[glib] Improve coverage of stream tests



commit 758c3216cddf35721b3c1fc244f93f6169d9a84b
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Jul 29 00:54:23 2010 -0400

    Improve coverage of stream tests

 gio/tests/buffered-input-stream.c |    2 ++
 gio/tests/converter-stream.c      |    4 ++++
 gio/tests/data-input-stream.c     |   31 +++++++++++++++++++++++++++++++
 gio/tests/data-output-stream.c    |   32 ++++++++++++++++++++++++++++----
 4 files changed, 65 insertions(+), 4 deletions(-)
---
diff --git a/gio/tests/buffered-input-stream.c b/gio/tests/buffered-input-stream.c
index 4809cc7..563e592 100644
--- a/gio/tests/buffered-input-stream.c
+++ b/gio/tests/buffered-input-stream.c
@@ -105,6 +105,8 @@ test_set_buffer_size (void)
   g_buffered_input_stream_set_buffer_size (G_BUFFERED_INPUT_STREAM (in), 2);
   size = g_buffered_input_stream_get_buffer_size (G_BUFFERED_INPUT_STREAM (in));
   g_assert_cmpint (size, ==, bufsize);
+  g_object_get (in, "buffer-size", &size, NULL);
+  g_assert_cmpint (size, ==, bufsize);
 
   g_object_unref (in);
 
diff --git a/gio/tests/converter-stream.c b/gio/tests/converter-stream.c
index ad7b4ce..f8f2d5b 100644
--- a/gio/tests/converter-stream.c
+++ b/gio/tests/converter-stream.c
@@ -301,6 +301,7 @@ test_expander (void)
   GInputStream *mem, *cstream;
   GOutputStream *mem_out, *cstream_out;
   GConverter *expander;
+  GConverter *converter;
   GError *error;
   int i;
 
@@ -326,6 +327,9 @@ test_expander (void)
 					     NULL);
   cstream = g_converter_input_stream_new (mem, expander);
   g_assert (g_converter_input_stream_get_converter (G_CONVERTER_INPUT_STREAM (cstream)) == expander);
+  g_object_get (cstream, "converter", &converter, NULL);
+  g_assert (converter == expander);
+  g_object_unref (converter);
   g_object_unref (mem);
 
   total_read = 0;
diff --git a/gio/tests/data-input-stream.c b/gio/tests/data-input-stream.c
index 368866e..b05241a 100644
--- a/gio/tests/data-input-stream.c
+++ b/gio/tests/data-input-stream.c
@@ -29,6 +29,30 @@
 #define MAX_BYTES	0x10000	
 
 static void
+test_basic (void)
+{
+  GInputStream *stream;
+  GInputStream *base_stream;
+  gint val;
+
+  base_stream = g_memory_input_stream_new ();
+  stream = G_INPUT_STREAM (g_data_input_stream_new (base_stream));
+
+  g_object_get (stream, "byte-order", &val, NULL);
+  g_assert_cmpint (val, ==, G_DATA_STREAM_BYTE_ORDER_BIG_ENDIAN);
+  g_object_set (stream, "byte-order", G_DATA_STREAM_BYTE_ORDER_LITTLE_ENDIAN, NULL);
+  g_assert_cmpint (g_data_input_stream_get_byte_order (G_DATA_INPUT_STREAM (stream)), ==, G_DATA_STREAM_BYTE_ORDER_LITTLE_ENDIAN);
+
+  g_object_get (stream, "newline-type", &val, NULL);
+  g_assert_cmpint (val, ==, G_DATA_STREAM_NEWLINE_TYPE_LF);
+  g_object_set (stream, "newline-type", G_DATA_STREAM_NEWLINE_TYPE_CR_LF, NULL);
+  g_assert_cmpint (g_data_input_stream_get_newline_type (G_DATA_INPUT_STREAM (stream)), ==, G_DATA_STREAM_NEWLINE_TYPE_CR_LF);
+
+  g_object_unref (stream);
+  g_object_unref (base_stream);
+}
+
+static void
 test_seek_to_start (GInputStream *stream)
 {
   GError *error = NULL;
@@ -117,6 +141,11 @@ test_read_lines_CR_LF (void)
   test_read_lines (G_DATA_STREAM_NEWLINE_TYPE_CR_LF);
 }
 
+static void
+test_read_lines_any (void)
+{
+  test_read_lines (G_DATA_STREAM_NEWLINE_TYPE_ANY);
+}
 
 static void
 test_read_until (void)
@@ -326,9 +355,11 @@ main (int   argc,
   g_type_init ();
   g_test_init (&argc, &argv, NULL);
 
+  g_test_add_func ("/data-input-stream/basic", test_basic);
   g_test_add_func ("/data-input-stream/read-lines-LF", test_read_lines_LF);
   g_test_add_func ("/data-input-stream/read-lines-CR", test_read_lines_CR);
   g_test_add_func ("/data-input-stream/read-lines-CR-LF", test_read_lines_CR_LF);
+  g_test_add_func ("/data-input-stream/read-lines-any", test_read_lines_any);
   g_test_add_func ("/data-input-stream/read-until", test_read_until);
   g_test_add_func ("/data-input-stream/read-int", test_read_int);
 
diff --git a/gio/tests/data-output-stream.c b/gio/tests/data-output-stream.c
index 0172389..7acaa02 100644
--- a/gio/tests/data-output-stream.c
+++ b/gio/tests/data-output-stream.c
@@ -30,6 +30,29 @@
 #define MAX_BYTES_BINARY	0x100	
 
 static void
+test_basic (void)
+{
+  GOutputStream *stream;
+  GOutputStream *base_stream;
+  gpointer data;
+  gint val;
+
+  data = g_malloc0 (MAX_LINES_BUFF);
+  
+  /* initialize objects */
+  base_stream = g_memory_output_stream_new (data, MAX_LINES_BUFF, NULL, NULL);
+  stream = G_OUTPUT_STREAM (g_data_output_stream_new (base_stream));
+
+  g_object_get (stream, "byte-order", &val, NULL);
+  g_assert_cmpint (val, ==, G_DATA_STREAM_BYTE_ORDER_BIG_ENDIAN);
+  g_object_set (stream, "byte-order", G_DATA_STREAM_BYTE_ORDER_LITTLE_ENDIAN, NULL);
+  g_assert_cmpint (g_data_output_stream_get_byte_order (G_DATA_OUTPUT_STREAM (stream)), ==, G_DATA_STREAM_BYTE_ORDER_LITTLE_ENDIAN);
+
+  g_object_unref (stream);
+  g_object_unref (base_stream);
+}
+
+static void
 test_read_lines (GDataStreamNewlineType newline_type)
 {
   GOutputStream *stream;
@@ -280,10 +303,11 @@ main (int   argc,
   g_type_init ();
   g_test_init (&argc, &argv, NULL);
 
-  g_test_add_func ("/data-input-stream/read-lines-LF", test_read_lines_LF);
-  g_test_add_func ("/data-input-stream/read-lines-CR", test_read_lines_CR);
-  g_test_add_func ("/data-input-stream/read-lines-CR-LF", test_read_lines_CR_LF);
-  g_test_add_func ("/data-input-stream/read-int", test_read_int);
+  g_test_add_func ("/data-output-stream/basic", test_basic);
+  g_test_add_func ("/data-output-stream/write-lines-LF", test_read_lines_LF);
+  g_test_add_func ("/data-output-stream/write-lines-CR", test_read_lines_CR);
+  g_test_add_func ("/data-output-stream/write-lines-CR-LF", test_read_lines_CR_LF);
+  g_test_add_func ("/data-output-stream/write-int", test_read_int);
 
   return g_test_run();
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]