LCOV - code coverage report
Current view: top level - glib/gio/tests - test-io-stream.c (source / functions) Hit Total Coverage
Test: unnamed Lines: 29 29 100.0 %
Date: 2024-04-23 05:16:05 Functions: 9 9 100.0 %
Branches: 5 6 83.3 %

           Branch data     Line data    Source code
       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 <davidz@redhat.com>
      22                 :            :  * Author: Simon McVittie <simon.mcvittie@collabora.co.uk>
      23                 :            :  */
      24                 :            : 
      25                 :            : #include <gio/gio.h>
      26                 :            : 
      27                 :            : #include "test-io-stream.h"
      28                 :            : 
      29   [ +  +  +  -  :         95 : G_DEFINE_TYPE (TestIOStream, test_io_stream, G_TYPE_IO_STREAM)
                   +  + ]
      30                 :            : 
      31                 :            : static void
      32                 :          5 : test_io_stream_finalize (GObject *object)
      33                 :            : {
      34                 :          5 :   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                 :          5 :   g_clear_object (&stream->input_stream);
      40                 :          5 :   g_clear_object (&stream->output_stream);
      41                 :            : 
      42                 :          5 :   G_OBJECT_CLASS (test_io_stream_parent_class)->finalize (object);
      43                 :          5 : }
      44                 :            : 
      45                 :            : static void
      46                 :          6 : test_io_stream_init (TestIOStream *stream)
      47                 :            : {
      48                 :          6 : }
      49                 :            : 
      50                 :            : static GInputStream *
      51                 :         52 : test_io_stream_get_input_stream (GIOStream *_stream)
      52                 :            : {
      53                 :         52 :   TestIOStream *stream = TEST_IO_STREAM (_stream);
      54                 :            : 
      55                 :         52 :   return stream->input_stream;
      56                 :            : }
      57                 :            : 
      58                 :            : static GOutputStream *
      59                 :         22 : test_io_stream_get_output_stream (GIOStream *_stream)
      60                 :            : {
      61                 :         22 :   TestIOStream *stream = TEST_IO_STREAM (_stream);
      62                 :            : 
      63                 :         22 :   return stream->output_stream;
      64                 :            : }
      65                 :            : 
      66                 :            : static void
      67                 :          2 : test_io_stream_class_init (TestIOStreamClass *klass)
      68                 :            : {
      69                 :            :   GObjectClass *gobject_class;
      70                 :            :   GIOStreamClass *giostream_class;
      71                 :            : 
      72                 :          2 :   gobject_class = G_OBJECT_CLASS (klass);
      73                 :          2 :   gobject_class->finalize = test_io_stream_finalize;
      74                 :            : 
      75                 :          2 :   giostream_class = G_IO_STREAM_CLASS (klass);
      76                 :          2 :   giostream_class->get_input_stream  = test_io_stream_get_input_stream;
      77                 :          2 :   giostream_class->get_output_stream = test_io_stream_get_output_stream;
      78                 :          2 : }
      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                 :          6 : test_io_stream_new (GInputStream  *input_stream,
      94                 :            :                     GOutputStream *output_stream)
      95                 :            : {
      96                 :            :   TestIOStream *stream;
      97                 :            : 
      98                 :          6 :   g_return_val_if_fail (G_IS_INPUT_STREAM (input_stream), NULL);
      99                 :          6 :   g_return_val_if_fail (G_IS_OUTPUT_STREAM (output_stream), NULL);
     100                 :          6 :   stream = TEST_IO_STREAM (g_object_new (TEST_TYPE_IO_STREAM, NULL));
     101                 :          6 :   stream->input_stream = g_object_ref (input_stream);
     102                 :          6 :   stream->output_stream = g_object_ref (output_stream);
     103                 :          6 :   return G_IO_STREAM (stream);
     104                 :            : }

Generated by: LCOV version 1.14