9 const gchar buffer[] = "abcdefghijklmnopqrstuvwxyz";
11 base = g_memory_output_stream_new (g_malloc0 (20), 20, g_realloc, g_free);
12 out = g_buffered_output_stream_new (base);
14 g_assert_cmpint (g_buffered_output_stream_get_buffer_size (G_BUFFERED_OUTPUT_STREAM (out)), ==, 4096);
15 g_assert (!g_buffered_output_stream_get_auto_grow (G_BUFFERED_OUTPUT_STREAM (out)));
16 g_buffered_output_stream_set_buffer_size (G_BUFFERED_OUTPUT_STREAM (out), 16);
17 g_assert_cmpint (g_buffered_output_stream_get_buffer_size (G_BUFFERED_OUTPUT_STREAM (out)), ==, 16);
20 g_assert_cmpint (g_output_stream_write (out, buffer, 10, NULL, &error), ==, 10);
21 g_assert_no_error (error);
23 g_assert_cmpint (g_memory_output_stream_get_data_size (G_MEMORY_OUTPUT_STREAM (base)), ==, 0);
25 g_assert_cmpint (g_output_stream_write (out, buffer + 10, 10, NULL, &error), ==, 6);
26 g_assert_no_error (error);
28 g_assert_cmpint (g_memory_output_stream_get_data_size (G_MEMORY_OUTPUT_STREAM (base)), ==, 0);
29 g_assert (g_output_stream_flush (out, NULL, &error));
30 g_assert_no_error (error);
31 g_assert_cmpint (g_memory_output_stream_get_data_size (G_MEMORY_OUTPUT_STREAM (base)), ==, 16);
33 g_assert_cmpstr (g_memory_output_stream_get_data (G_MEMORY_OUTPUT_STREAM (base)), ==, "abcdefghijklmnop");
36 g_object_unref (base);
45 const gchar buffer[] = "abcdefghijklmnopqrstuvwxyz";
49 base = g_memory_output_stream_new (g_malloc0 (30), 30, g_realloc, g_free);
50 out = g_buffered_output_stream_new_sized (base, 16);
52 g_buffered_output_stream_set_auto_grow (G_BUFFERED_OUTPUT_STREAM (out), TRUE);
54 g_object_get (out, "buffer-size", &size, "auto-grow", &grow, NULL);
55 g_assert_cmpint (size, ==, 16);
59 g_assert_cmpint (g_output_stream_write (out, buffer, 10, NULL, &error), ==, 10);
60 g_assert_no_error (error);
62 g_assert_cmpint (g_buffered_output_stream_get_buffer_size (G_BUFFERED_OUTPUT_STREAM (out)), ==, 16);
63 g_assert_cmpint (g_memory_output_stream_get_data_size (G_MEMORY_OUTPUT_STREAM (base)), ==, 0);
65 g_assert_cmpint (g_output_stream_write (out, buffer + 10, 10, NULL, &error), ==, 10);
66 g_assert_no_error (error);
68 g_assert_cmpint (g_buffered_output_stream_get_buffer_size (G_BUFFERED_OUTPUT_STREAM (out)), >=, 20);
69 g_assert_cmpint (g_memory_output_stream_get_data_size (G_MEMORY_OUTPUT_STREAM (base)), ==, 0);
71 g_assert (g_output_stream_flush (out, NULL, &error));
72 g_assert_no_error (error);
74 g_assert_cmpstr (g_memory_output_stream_get_data (G_MEMORY_OUTPUT_STREAM (base)), ==, "abcdefghijklmnopqrst");
77 g_object_unref (base);
87 base = g_memory_output_stream_new (g_malloc0 (30), 30, g_realloc, g_free);
88 out = g_buffered_output_stream_new (base);
90 g_assert (g_filter_output_stream_get_close_base_stream (G_FILTER_OUTPUT_STREAM (out)));
93 g_assert (g_output_stream_close (out, NULL, &error));
94 g_assert_no_error (error);
95 g_assert (g_output_stream_is_closed (base));
98 g_object_unref (base);
100 base = g_memory_output_stream_new (g_malloc0 (30), 30, g_realloc, g_free);
101 out = g_buffered_output_stream_new (base);
103 g_filter_output_stream_set_close_base_stream (G_FILTER_OUTPUT_STREAM (out), FALSE);
106 g_assert (g_output_stream_close (out, NULL, &error));
107 g_assert_no_error (error);
108 g_assert (!g_output_stream_is_closed (base));
110 g_object_unref (out);
111 g_object_unref (base);
115 main (int argc, char *argv[])
119 g_test_init (&argc, &argv, NULL);
121 g_test_add_func ("/buffered-output-stream/write", test_write);
122 g_test_add_func ("/buffered-output-stream/grow", test_grow);
123 g_test_add_func ("/filter-output-stream/close", test_close);
125 return g_test_run ();