| 1 |
/* Simple I/O stream. This is a utility class for tests, not a test. |
| 2 |
* |
| 3 |
* Copyright © 2008-2010 Red Hat, Inc. |
| 4 |
* Copyright © 2011 Nokia Corporation |
| 5 |
* |
| 6 |
* SPDX-License-Identifier: LGPL-2.1-or-later |
| 7 |
* |
| 8 |
* This library is free software; you can redistribute it and/or |
| 9 |
* modify it under the terms of the GNU Lesser General Public |
| 10 |
* License as published by the Free Software Foundation; either |
| 11 |
* version 2.1 of the License, or (at your option) any later version. |
| 12 |
* |
| 13 |
* This library is distributed in the hope that it will be useful, |
| 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 |
* Lesser General Public License for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU Lesser General |
| 19 |
* Public License along with this library; if not, see <http://www.gnu.org/licenses/>. |
| 20 |
* |
| 21 |
* Author: David Zeuthen <[email protected]> |
| 22 |
* Author: Simon McVittie <[email protected]> |
| 23 |
*/ |
| 24 |
|
| 25 |
#include <gio/gio.h> |
| 26 |
|
| 27 |
#include "test-io-stream.h" |
| 28 |
|
| 29 |
G_DEFINE_TYPE (TestIOStream, test_io_stream, G_TYPE_IO_STREAM) |
| 30 |
|
| 31 |
static void |
| 32 |
test_io_stream_finalize (GObject *object) |
| 33 |
{ |
| 34 |
TestIOStream *stream = TEST_IO_STREAM (object); |
| 35 |
|
| 36 |
/* strictly speaking we should unref these in dispose, but |
| 37 |
* g_io_stream_dispose() wants them to still exist |
| 38 |
*/ |
| 39 |
g_clear_object (&stream->input_stream); |
| 40 |
g_clear_object (&stream->output_stream); |
| 41 |
|
| 42 |
G_OBJECT_CLASS (test_io_stream_parent_class)->finalize (object); |
| 43 |
} |
| 44 |
|
| 45 |
static void |
| 46 |
test_io_stream_init (TestIOStream *stream) |
| 47 |
{ |
| 48 |
} |
| 49 |
|
| 50 |
static GInputStream * |
| 51 |
test_io_stream_get_input_stream (GIOStream *_stream) |
| 52 |
{ |
| 53 |
TestIOStream *stream = TEST_IO_STREAM (_stream); |
| 54 |
|
| 55 |
return stream->input_stream; |
| 56 |
} |
| 57 |
|
| 58 |
static GOutputStream * |
| 59 |
test_io_stream_get_output_stream (GIOStream *_stream) |
| 60 |
{ |
| 61 |
TestIOStream *stream = TEST_IO_STREAM (_stream); |
| 62 |
|
| 63 |
return stream->output_stream; |
| 64 |
} |
| 65 |
|
| 66 |
static void |
| 67 |
test_io_stream_class_init (TestIOStreamClass *klass) |
| 68 |
{ |
| 69 |
GObjectClass *gobject_class; |
| 70 |
GIOStreamClass *giostream_class; |
| 71 |
|
| 72 |
gobject_class = G_OBJECT_CLASS (klass); |
| 73 |
gobject_class->finalize = test_io_stream_finalize; |
| 74 |
|
| 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; |
| 78 |
} |
| 79 |
|
| 80 |
/** |
| 81 |
* test_io_stream_new: |
| 82 |
* @input_stream: an input stream |
| 83 |
* @output_stream: an output stream |
| 84 |
* |
| 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). |
| 89 |
* |
| 90 |
* Returns: (transfer full): a new #GIOStream |
| 91 |
*/ |
| 92 |
GIOStream * |
| 93 |
test_io_stream_new (GInputStream *input_stream, |
| 94 |
GOutputStream *output_stream) |
| 95 |
{ |
| 96 |
TestIOStream *stream; |
| 97 |
|
| 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); |
| 104 |
} |