1 /* GLib testing framework examples and tests
2 * Copyright (C) 2008 Red Hat, Inc.
3 * Authors: Matthias Clasen <mclasen@redhat.com>
4 *
5 * This work is provided "as is"; redistribution and modification
6 * in whole or in part, in any medium, physical or electronic is
7 * permitted without restriction.
8 *
9 * This work is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 *
13 * In no event shall the authors or contributors be liable for any
14 * direct, indirect, incidental, special, exemplary, or consequential
15 * damages (including, but not limited to, procurement of substitute
16 * goods or services; loss of use, data, or profits; or business
17 * interruption) however caused and on any theory of liability, whether
18 * in contract, strict liability, or tort (including negligence or
19 * otherwise) arising in any way out of the use of this software, even
20 * if advised of the possibility of such damage.
21 */
22
23 #include <glib/glib.h>
24 #include <gio/gio.h>
25 #include <stdlib.h>
26 #include <string.h>
27
28 static void
test_read_byte(void)29 test_read_byte (void)
30 {
31 GInputStream *base;
32 GInputStream *in;
33
34 g_test_bug ("562393");
35
36 base = g_memory_input_stream_new_from_data ("abcdefghijk", -1, NULL);
37 in = g_buffered_input_stream_new (base);
38
39 g_assert_cmpint (g_buffered_input_stream_read_byte (G_BUFFERED_INPUT_STREAM (in), NULL, NULL), ==, 'a');
40 g_assert_cmpint (g_buffered_input_stream_read_byte (G_BUFFERED_INPUT_STREAM (in), NULL, NULL), ==, 'b');
41 g_assert_cmpint (g_buffered_input_stream_read_byte (G_BUFFERED_INPUT_STREAM (in), NULL, NULL), ==, 'c');
42
43 g_assert_cmpint (g_input_stream_skip (in, 3, NULL, NULL), ==, 3);
44
45 g_assert_cmpint (g_buffered_input_stream_read_byte (G_BUFFERED_INPUT_STREAM (in), NULL, NULL), ==, 'g');
46 }
47
48
49 int
main(int argc,char * argv[])50 main (int argc,
51 char *argv[])
52 {
53 g_type_init ();
54 g_test_init (&argc, &argv, NULL);
55 g_test_bug_base ("http://bugzilla.gnome.org/");
56
57 g_test_add_func ("/buffered-input-stream/read-byte", test_read_byte);
58
59 return g_test_run();
60 }
61