lasips2: standardise on lp name for LASIPS2Port variables
[qemu/ar7.git] / tests / unit / test-io-channel-null.c
blobb3aab17ccce99a256247502f953105927933bde0
1 /*
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,
27 gpointer opaque)
29 GIOCondition *gotcond = opaque;
30 *gotcond = condition;
31 return G_SOURCE_REMOVE;
34 static void test_io_channel_null_io(void)
36 g_autoptr(QIOChannelNull) null = qio_channel_null_new();
37 char buf[1024];
38 GIOCondition gotcond = 0;
39 Error *local_err = NULL;
41 g_assert(qio_channel_write(QIO_CHANNEL(null),
42 "Hello World", 11,
43 &error_abort) == 11);
45 g_assert(qio_channel_read(QIO_CHANNEL(null),
46 buf, sizeof(buf),
47 &error_abort) == 0);
49 qio_channel_add_watch(QIO_CHANNEL(null),
50 G_IO_IN,
51 test_io_channel_watch,
52 &gotcond,
53 NULL);
55 g_main_context_iteration(NULL, false);
57 g_assert(gotcond == G_IO_IN);
59 qio_channel_add_watch(QIO_CHANNEL(null),
60 G_IO_IN | G_IO_OUT,
61 test_io_channel_watch,
62 &gotcond,
63 NULL);
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),
72 "Hello World", 11,
73 &local_err) == -1);
74 g_assert_nonnull(local_err);
76 g_clear_pointer(&local_err, error_free);
78 g_assert(qio_channel_read(QIO_CHANNEL(null),
79 buf, sizeof(buf),
80 &local_err) == -1);
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);
94 return g_test_run();