Update German translation
[glib.git] / gio / tests / test-io-stream.c
blobb79f62e4e95c072560d204395d9629d459cb4450
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, see <http://www.gnu.org/licenses/>.
19 * Author: David Zeuthen <davidz@redhat.com>
20 * Author: Simon McVittie <simon.mcvittie@collabora.co.uk>
23 #include <gio/gio.h>
25 #include "test-io-stream.h"
27 G_DEFINE_TYPE (TestIOStream, test_io_stream, G_TYPE_IO_STREAM)
29 static void
30 test_io_stream_finalize (GObject *object)
32 TestIOStream *stream = TEST_IO_STREAM (object);
34 /* strictly speaking we should unref these in dispose, but
35 * g_io_stream_dispose() wants them to still exist
37 g_clear_object (&stream->input_stream);
38 g_clear_object (&stream->output_stream);
40 G_OBJECT_CLASS (test_io_stream_parent_class)->finalize (object);
43 static void
44 test_io_stream_init (TestIOStream *stream)
48 static GInputStream *
49 test_io_stream_get_input_stream (GIOStream *_stream)
51 TestIOStream *stream = TEST_IO_STREAM (_stream);
53 return stream->input_stream;
56 static GOutputStream *
57 test_io_stream_get_output_stream (GIOStream *_stream)
59 TestIOStream *stream = TEST_IO_STREAM (_stream);
61 return stream->output_stream;
64 static void
65 test_io_stream_class_init (TestIOStreamClass *klass)
67 GObjectClass *gobject_class;
68 GIOStreamClass *giostream_class;
70 gobject_class = G_OBJECT_CLASS (klass);
71 gobject_class->finalize = test_io_stream_finalize;
73 giostream_class = G_IO_STREAM_CLASS (klass);
74 giostream_class->get_input_stream = test_io_stream_get_input_stream;
75 giostream_class->get_output_stream = test_io_stream_get_output_stream;
78 /**
79 * test_io_stream_new:
80 * @input_stream: an input stream
81 * @output_stream: an output stream
83 * Return a simple #GIOStream binding together @input_stream and
84 * @output_stream. They have no additional semantics as a result of being
85 * part of this I/O stream: in particular, closing one does not close
86 * the other (although closing the #GIOStream will close both sub-streams).
88 * Returns: (transfer full): a new #GIOStream
90 GIOStream *
91 test_io_stream_new (GInputStream *input_stream,
92 GOutputStream *output_stream)
94 TestIOStream *stream;
96 g_return_val_if_fail (G_IS_INPUT_STREAM (input_stream), NULL);
97 g_return_val_if_fail (G_IS_OUTPUT_STREAM (output_stream), NULL);
98 stream = TEST_IO_STREAM (g_object_new (TEST_TYPE_IO_STREAM, NULL));
99 stream->input_stream = g_object_ref (input_stream);
100 stream->output_stream = g_object_ref (output_stream);
101 return G_IO_STREAM (stream);