2 * QEMU I/O channel null test
4 * Copyright (c) 2022 Red Hat, Inc.
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.1 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 Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
21 #include "qemu/osdep.h"
22 #include "io/channel-null.h"
23 #include "qapi/error.h"
25 static gboolean test_io_channel_watch(QIOChannel *ioc,
26 GIOCondition condition,
29 GIOCondition *gotcond = opaque;
31 return G_SOURCE_REMOVE;
34 static void test_io_channel_null_io(void)
36 g_autoptr(QIOChannelNull) null = qio_channel_null_new();
38 GIOCondition gotcond = 0;
39 Error *local_err = NULL;
41 g_assert(qio_channel_write(QIO_CHANNEL(null),
45 g_assert(qio_channel_read(QIO_CHANNEL(null),
49 qio_channel_add_watch(QIO_CHANNEL(null),
51 test_io_channel_watch,
55 g_main_context_iteration(NULL, false);
57 g_assert(gotcond == G_IO_IN);
59 qio_channel_add_watch(QIO_CHANNEL(null),
61 test_io_channel_watch,
65 g_main_context_iteration(NULL, false);
67 g_assert(gotcond == (G_IO_IN | G_IO_OUT));
69 qio_channel_close(QIO_CHANNEL(null), &error_abort);
71 g_assert(qio_channel_write(QIO_CHANNEL(null),
74 g_assert_nonnull(local_err);
76 g_clear_pointer(&local_err, error_free);
78 g_assert(qio_channel_read(QIO_CHANNEL(null),
81 g_assert_nonnull(local_err);
83 g_clear_pointer(&local_err, error_free);
86 int main(int argc, char **argv)
88 module_call_init(MODULE_INIT_QOM);
90 g_test_init(&argc, &argv, NULL);
92 g_test_add_func("/io/channel/null/io", test_io_channel_null_io);