vl: smp_parse: cleanups
[qemu/ar7.git] / tests / check-qnull.c
blob05d562d494decb30b1326cb1f28c91c394f0acbe
1 /*
2 * QNull unit-tests.
4 * Copyright (C) 2016 Red Hat Inc.
6 * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
7 * See the COPYING.LIB file in the top-level directory.
8 */
9 #include "qemu/osdep.h"
11 #include "qapi/qmp/qobject.h"
12 #include "qemu-common.h"
13 #include "qapi/qmp-input-visitor.h"
14 #include "qapi/qmp-output-visitor.h"
15 #include "qapi/error.h"
18 * Public Interface test-cases
20 * (with some violations to access 'private' data)
23 static void qnull_ref_test(void)
25 QObject *obj;
27 g_assert(qnull_.refcnt == 1);
28 obj = qnull();
29 g_assert(obj);
30 g_assert(obj == &qnull_);
31 g_assert(qnull_.refcnt == 2);
32 g_assert(qobject_type(obj) == QTYPE_QNULL);
33 qobject_decref(obj);
34 g_assert(qnull_.refcnt == 1);
37 static void qnull_visit_test(void)
39 QObject *obj;
40 QmpOutputVisitor *qov;
41 QmpInputVisitor *qiv;
44 * Most tests of interactions between QObject and visitors are in
45 * test-qmp-*-visitor; but these tests live here because they
46 * depend on layering violations to check qnull_ refcnt.
49 g_assert(qnull_.refcnt == 1);
50 obj = qnull();
51 qiv = qmp_input_visitor_new(obj, true);
52 qobject_decref(obj);
53 visit_type_null(qmp_input_get_visitor(qiv), NULL, &error_abort);
54 qmp_input_visitor_cleanup(qiv);
56 qov = qmp_output_visitor_new();
57 visit_type_null(qmp_output_get_visitor(qov), NULL, &error_abort);
58 obj = qmp_output_get_qobject(qov);
59 g_assert(obj == &qnull_);
60 qobject_decref(obj);
61 qmp_output_visitor_cleanup(qov);
63 g_assert(qnull_.refcnt == 1);
66 int main(int argc, char **argv)
68 g_test_init(&argc, &argv, NULL);
70 g_test_add_func("/public/qnull_ref", qnull_ref_test);
71 g_test_add_func("/public/qnull_visit", qnull_visit_test);
73 return g_test_run();