test-stream.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* Simple stream test.
  2. *
  3. * Copyright (C) 2006 Sun Microsystems, Inc.
  4. *
  5. * This file is part of Quagga.
  6. *
  7. * Quagga is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation; either version 2, or (at your option) any
  10. * later version.
  11. *
  12. * Quagga is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with Quagga; see the file COPYING. If not, write to the Free
  19. * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  20. * 02111-1307, USA.
  21. */
  22. #include <zebra.h>
  23. #include <stream.h>
  24. #include <thread.h>
  25. static unsigned long long ham = 0xdeadbeefdeadbeef;
  26. struct thread_master *master;
  27. static void
  28. print_stream (struct stream *s)
  29. {
  30. size_t getp = stream_get_getp (s);
  31. printf ("endp: %zu, readable: %zu, writeable: %zu\n",
  32. stream_get_endp (s),
  33. STREAM_READABLE (s),
  34. STREAM_WRITEABLE (s));
  35. while (STREAM_READABLE (s))
  36. {
  37. printf ("0x%x ", *stream_pnt (s));
  38. stream_forward_getp (s, 1);
  39. }
  40. printf ("\n");
  41. /* put getp back to where it was */
  42. stream_set_getp (s, getp);
  43. }
  44. int
  45. main (void)
  46. {
  47. struct stream *s;
  48. s = stream_new (1024);
  49. stream_putc (s, ham);
  50. stream_putw (s, ham);
  51. stream_putl (s, ham);
  52. stream_putq (s, ham);
  53. print_stream (s);
  54. stream_resize (s, stream_get_endp (s));
  55. print_stream (s);
  56. printf ("c: 0x%hhx\n", stream_getc (s));
  57. printf ("w: 0x%hx\n", stream_getw (s));
  58. printf ("l: 0x%x\n", stream_getl (s));
  59. printf ("q: 0x%" PRIu64 "\n", stream_getq (s));
  60. return 0;
  61. }