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";
47 base = g_memory_output_stream_new (g_malloc0 (30), 30, g_realloc, g_free);
48 out = g_buffered_output_stream_new (base);
50 g_buffered_output_stream_set_buffer_size (G_BUFFERED_OUTPUT_STREAM (out), 16);
51 g_buffered_output_stream_set_auto_grow (G_BUFFERED_OUTPUT_STREAM (out), TRUE);
54 g_assert_cmpint (g_output_stream_write (out, buffer, 10, NULL, &error), ==, 10);
55 g_assert_no_error (error);
57 g_assert_cmpint (g_buffered_output_stream_get_buffer_size (G_BUFFERED_OUTPUT_STREAM (out)), ==, 16);
58 g_assert_cmpint (g_memory_output_stream_get_data_size (G_MEMORY_OUTPUT_STREAM (base)), ==, 0);
60 g_assert_cmpint (g_output_stream_write (out, buffer + 10, 10, NULL, &error), ==, 10);
61 g_assert_no_error (error);
63 g_assert_cmpint (g_buffered_output_stream_get_buffer_size (G_BUFFERED_OUTPUT_STREAM (out)), >=, 20);
64 g_assert_cmpint (g_memory_output_stream_get_data_size (G_MEMORY_OUTPUT_STREAM (base)), ==, 0);
66 g_assert (g_output_stream_flush (out, NULL, &error));
67 g_assert_no_error (error);
69 g_assert_cmpstr (g_memory_output_stream_get_data (G_MEMORY_OUTPUT_STREAM (base)), ==, "abcdefghijklmnopqrst");
72 g_object_unref (base);
76 main (int argc, char *argv[])
80 g_test_init (&argc, &argv, NULL);
82 g_test_add_func ("/buffered-output-stream/write", test_write);
83 g_test_add_func ("/buffered-output-stream/grow", test_grow);