mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-25 15:06:14 +01:00
Improve coverage of stream tests
This commit is contained in:
parent
c6b0507167
commit
758c3216cd
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
|
@ -28,6 +28,30 @@
|
||||
#define MAX_LINES 0xFFF
|
||||
#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)
|
||||
{
|
||||
@ -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);
|
||||
|
||||
|
@ -29,6 +29,29 @@
|
||||
#define MAX_LINES_BUFF 0xFFFFFF
|
||||
#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)
|
||||
{
|
||||
@ -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();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user