blob: 7ef6374756a960203594ba25ffa71346b7d43cb5 [file] [log] [blame]
Paul Jakma010ebbb2014-09-16 11:53:49 +01001/* 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
paul067fca82006-01-10 14:49:04 +000023#include <zebra.h>
24#include <stream.h>
25#include <thread.h>
26
Donald Sharp61695592015-10-12 14:33:31 -040027static unsigned long long ham = 0xdeadbeefdeadbeef;
paul067fca82006-01-10 14:49:04 +000028struct thread_master *master;
29
30static void
31print_stream (struct stream *s)
32{
33 size_t getp = stream_get_getp (s);
34
Donald Sharp61695592015-10-12 14:33:31 -040035 printf ("endp: %zu, readable: %zu, writeable: %zu\n",
paul067fca82006-01-10 14:49:04 +000036 stream_get_endp (s),
37 STREAM_READABLE (s),
38 STREAM_WRITEABLE (s));
39
40 while (STREAM_READABLE (s))
41 {
42 printf ("0x%x ", *stream_pnt (s));
43 stream_forward_getp (s, 1);
44 }
45
46 printf ("\n");
47
48 /* put getp back to where it was */
49 stream_set_getp (s, getp);
50}
51
52int
53main (void)
54{
55 struct stream *s;
56
57 s = stream_new (1024);
58
59 stream_putc (s, ham);
60 stream_putw (s, ham);
61 stream_putl (s, ham);
62 stream_putq (s, ham);
63
64 print_stream (s);
65
66 stream_resize (s, stream_get_endp (s));
67
68 print_stream (s);
69
70 printf ("c: 0x%hhx\n", stream_getc (s));
71 printf ("w: 0x%hx\n", stream_getw (s));
72 printf ("l: 0x%x\n", stream_getl (s));
Donald Sharp61695592015-10-12 14:33:31 -040073 printf ("q: 0x%" PRIu64 "\n", stream_getq (s));
paul067fca82006-01-10 14:49:04 +000074
75 return 0;
76}