1 /* Simple I/O stream. This is a utility class for tests, not a test.
3 * Copyright © 2008-2010 Red Hat, Inc.
4 * Copyright © 2011 Nokia Corporation
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General
17 * Public License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
19 * Boston, MA 02111-1307, USA.
21 * Author: David Zeuthen <davidz@redhat.com>
22 * Author: Simon McVittie <simon.mcvittie@collabora.co.uk>
27 #include "test-io-stream.h"
29 G_DEFINE_TYPE (TestIOStream, test_io_stream, G_TYPE_IO_STREAM)
32 test_io_stream_finalize (GObject *object)
34 TestIOStream *stream = TEST_IO_STREAM (object);
36 /* strictly speaking we should unref these in dispose, but
37 * g_io_stream_dispose() wants them to still exist
39 g_clear_object (&stream->input_stream);
40 g_clear_object (&stream->output_stream);
42 G_OBJECT_CLASS (test_io_stream_parent_class)->finalize (object);
46 test_io_stream_init (TestIOStream *stream)
51 test_io_stream_get_input_stream (GIOStream *_stream)
53 TestIOStream *stream = TEST_IO_STREAM (_stream);
55 return stream->input_stream;
58 static GOutputStream *
59 test_io_stream_get_output_stream (GIOStream *_stream)
61 TestIOStream *stream = TEST_IO_STREAM (_stream);
63 return stream->output_stream;
67 test_io_stream_class_init (TestIOStreamClass *klass)
69 GObjectClass *gobject_class;
70 GIOStreamClass *giostream_class;
72 gobject_class = G_OBJECT_CLASS (klass);
73 gobject_class->finalize = test_io_stream_finalize;
75 giostream_class = G_IO_STREAM_CLASS (klass);
76 giostream_class->get_input_stream = test_io_stream_get_input_stream;
77 giostream_class->get_output_stream = test_io_stream_get_output_stream;
82 * @input_stream: an input stream
83 * @output_stream: an output stream
85 * Return a simple #GIOStream binding together @input_stream and
86 * @output_stream. They have no additional semantics as a result of being
87 * part of this I/O stream: in particular, closing one does not close
88 * the other (although closing the #GIOStream will close both sub-streams).
90 * Returns: (transfer full): a new #GIOStream
93 test_io_stream_new (GInputStream *input_stream,
94 GOutputStream *output_stream)
98 g_return_val_if_fail (G_IS_INPUT_STREAM (input_stream), NULL);
99 g_return_val_if_fail (G_IS_OUTPUT_STREAM (output_stream), NULL);
100 stream = TEST_IO_STREAM (g_object_new (TEST_TYPE_IO_STREAM, NULL));
101 stream->input_stream = g_object_ref (input_stream);
102 stream->output_stream = g_object_ref (output_stream);
103 return G_IO_STREAM (stream);