Add GSimpleIOStream class

GSimpleIOStream represents an object that wraps an input and an output
stream making easy to use them by calling the #GIOStream methods.

https://bugzilla.gnome.org/show_bug.cgi?id=741630
This commit is contained in:
Ignacio Casal Quinteiro
2014-12-17 09:11:29 +01:00
committed by Ryan Lortie
parent c2c0a6ae5c
commit d4e3b82a93
9 changed files with 291 additions and 79 deletions

View File

@@ -82,6 +82,7 @@ test_type (gconstpointer data)
g_type_is_a (type, G_TYPE_PROPERTY_ACTION) ||
g_type_is_a (type, G_TYPE_SETTINGS) ||
g_type_is_a (type, G_TYPE_SOCKET_CONNECTION) ||
g_type_is_a (type, G_TYPE_SIMPLE_IO_STREAM) ||
g_type_is_a (type, G_TYPE_THEMED_ICON) ||
FALSE)
{

View File

@@ -25,81 +25,6 @@
#include <stdlib.h>
#include <string.h>
typedef struct
{
GIOStream parent;
GInputStream *input_stream;
GOutputStream *output_stream;
} GTestIOStream;
typedef struct
{
GIOStreamClass parent_class;
} GTestIOStreamClass;
static GType g_test_io_stream_get_type (void);
G_DEFINE_TYPE (GTestIOStream, g_test_io_stream, G_TYPE_IO_STREAM);
static GInputStream *
get_input_stream (GIOStream *io_stream)
{
GTestIOStream *self = (GTestIOStream *) io_stream;
return self->input_stream;
}
static GOutputStream *
get_output_stream (GIOStream *io_stream)
{
GTestIOStream *self = (GTestIOStream *) io_stream;
return self->output_stream;
}
static void
finalize (GObject *object)
{
GTestIOStream *self = (GTestIOStream *) object;
if (self->input_stream != NULL)
g_object_unref (self->input_stream);
if (self->output_stream != NULL)
g_object_unref (self->output_stream);
G_OBJECT_CLASS (g_test_io_stream_parent_class)->finalize (object);
}
static void
g_test_io_stream_class_init (GTestIOStreamClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GIOStreamClass *io_class = G_IO_STREAM_CLASS (klass);
object_class->finalize = finalize;
io_class->get_input_stream = get_input_stream;
io_class->get_output_stream = get_output_stream;
}
static void
g_test_io_stream_init (GTestIOStream *self)
{
}
static GIOStream *
g_test_io_stream_new (GInputStream *input, GOutputStream *output)
{
GTestIOStream *self;
self = g_object_new (g_test_io_stream_get_type (), NULL);
self->input_stream = g_object_ref (input);
self->output_stream = g_object_ref (output);
return G_IO_STREAM (self);
}
typedef struct
{
GMainLoop *main_loop;
@@ -122,11 +47,11 @@ test_copy_chunks_splice_cb (GObject *source_object,
g_io_stream_splice_finish (res, &error);
g_assert_no_error (error);
ostream = G_MEMORY_OUTPUT_STREAM (((GTestIOStream *) data->iostream1)->output_stream);
ostream = G_MEMORY_OUTPUT_STREAM (g_io_stream_get_output_stream (data->iostream1));
received_data = g_memory_output_stream_get_data (ostream);
g_assert_cmpstr (received_data, ==, data->data2);
ostream = G_MEMORY_OUTPUT_STREAM (((GTestIOStream *) data->iostream2)->output_stream);
ostream = G_MEMORY_OUTPUT_STREAM (g_io_stream_get_output_stream (data->iostream2));
received_data = g_memory_output_stream_get_data (ostream);
g_assert_cmpstr (received_data, ==, data->data1);
@@ -149,13 +74,13 @@ test_copy_chunks (void)
istream = g_memory_input_stream_new_from_data (data.data1, -1, NULL);
ostream = g_memory_output_stream_new (NULL, 0, g_realloc, g_free);
data.iostream1 = g_test_io_stream_new (istream, ostream);
data.iostream1 = g_simple_io_stream_new (istream, ostream);
g_object_unref (istream);
g_object_unref (ostream);
istream = g_memory_input_stream_new_from_data (data.data2, -1, NULL);
ostream = g_memory_output_stream_new (NULL, 0, g_realloc, g_free);
data.iostream2 = g_test_io_stream_new (istream, ostream);
data.iostream2 = g_simple_io_stream_new (istream, ostream);
g_object_unref (istream);
g_object_unref (ostream);