Blame gio/tests/test-io-stream.c

Packit ae235b
/* Simple I/O stream. This is a utility class for tests, not a test.
Packit ae235b
 *
Packit ae235b
 * Copyright © 2008-2010 Red Hat, Inc.
Packit ae235b
 * Copyright © 2011 Nokia Corporation
Packit ae235b
 *
Packit ae235b
 * This library is free software; you can redistribute it and/or
Packit ae235b
 * modify it under the terms of the GNU Lesser General Public
Packit ae235b
 * License as published by the Free Software Foundation; either
Packit ae235b
 * version 2.1 of the License, or (at your option) any later version.
Packit ae235b
 *
Packit ae235b
 * This library is distributed in the hope that it will be useful,
Packit ae235b
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit ae235b
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit ae235b
 * Lesser General Public License for more details.
Packit ae235b
 *
Packit ae235b
 * You should have received a copy of the GNU Lesser General
Packit ae235b
 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
Packit ae235b
 *
Packit ae235b
 * Author: David Zeuthen <davidz@redhat.com>
Packit ae235b
 * Author: Simon McVittie <simon.mcvittie@collabora.co.uk>
Packit ae235b
 */
Packit ae235b
Packit ae235b
#include <gio/gio.h>
Packit ae235b
Packit ae235b
#include "test-io-stream.h"
Packit ae235b
Packit ae235b
G_DEFINE_TYPE (TestIOStream, test_io_stream, G_TYPE_IO_STREAM)
Packit ae235b
Packit ae235b
static void
Packit ae235b
test_io_stream_finalize (GObject *object)
Packit ae235b
{
Packit ae235b
  TestIOStream *stream = TEST_IO_STREAM (object);
Packit ae235b
Packit ae235b
  /* strictly speaking we should unref these in dispose, but
Packit ae235b
   * g_io_stream_dispose() wants them to still exist
Packit ae235b
   */
Packit ae235b
  g_clear_object (&stream->input_stream);
Packit ae235b
  g_clear_object (&stream->output_stream);
Packit ae235b
Packit ae235b
  G_OBJECT_CLASS (test_io_stream_parent_class)->finalize (object);
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
test_io_stream_init (TestIOStream *stream)
Packit ae235b
{
Packit ae235b
}
Packit ae235b
Packit ae235b
static GInputStream *
Packit ae235b
test_io_stream_get_input_stream (GIOStream *_stream)
Packit ae235b
{
Packit ae235b
  TestIOStream *stream = TEST_IO_STREAM (_stream);
Packit ae235b
Packit ae235b
  return stream->input_stream;
Packit ae235b
}
Packit ae235b
Packit ae235b
static GOutputStream *
Packit ae235b
test_io_stream_get_output_stream (GIOStream *_stream)
Packit ae235b
{
Packit ae235b
  TestIOStream *stream = TEST_IO_STREAM (_stream);
Packit ae235b
Packit ae235b
  return stream->output_stream;
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
test_io_stream_class_init (TestIOStreamClass *klass)
Packit ae235b
{
Packit ae235b
  GObjectClass *gobject_class;
Packit ae235b
  GIOStreamClass *giostream_class;
Packit ae235b
Packit ae235b
  gobject_class = G_OBJECT_CLASS (klass);
Packit ae235b
  gobject_class->finalize = test_io_stream_finalize;
Packit ae235b
Packit ae235b
  giostream_class = G_IO_STREAM_CLASS (klass);
Packit ae235b
  giostream_class->get_input_stream  = test_io_stream_get_input_stream;
Packit ae235b
  giostream_class->get_output_stream = test_io_stream_get_output_stream;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * test_io_stream_new:
Packit ae235b
 * @input_stream: an input stream
Packit ae235b
 * @output_stream: an output stream
Packit ae235b
 *
Packit ae235b
 * Return a simple #GIOStream binding together @input_stream and
Packit ae235b
 * @output_stream. They have no additional semantics as a result of being
Packit ae235b
 * part of this I/O stream: in particular, closing one does not close
Packit ae235b
 * the other (although closing the #GIOStream will close both sub-streams).
Packit ae235b
 *
Packit ae235b
 * Returns: (transfer full): a new #GIOStream
Packit ae235b
 */
Packit ae235b
GIOStream *
Packit ae235b
test_io_stream_new (GInputStream  *input_stream,
Packit ae235b
                    GOutputStream *output_stream)
Packit ae235b
{
Packit ae235b
  TestIOStream *stream;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_INPUT_STREAM (input_stream), NULL);
Packit ae235b
  g_return_val_if_fail (G_IS_OUTPUT_STREAM (output_stream), NULL);
Packit ae235b
  stream = TEST_IO_STREAM (g_object_new (TEST_TYPE_IO_STREAM, NULL));
Packit ae235b
  stream->input_stream = g_object_ref (input_stream);
Packit ae235b
  stream->output_stream = g_object_ref (output_stream);
Packit ae235b
  return G_IO_STREAM (stream);
Packit ae235b
}