]> git.proxmox.com Git - mirror_qemu.git/blame - tests/check-qnull.c
qapi: Add new visit_complete() function
[mirror_qemu.git] / tests / check-qnull.c
CommitLineData
7d7a337e
EB
1/*
2 * QNull unit-tests.
3 *
4 * Copyright (C) 2016 Red Hat Inc.
5 *
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"
7d7a337e
EB
10
11#include "qapi/qmp/qobject.h"
12#include "qemu-common.h"
3df016f1 13#include "qapi/qmp-input-visitor.h"
7d7a337e 14#include "qapi/qmp-output-visitor.h"
3df016f1 15#include "qapi/error.h"
7d7a337e
EB
16
17/*
18 * Public Interface test-cases
19 *
20 * (with some violations to access 'private' data)
21 */
22
23static void qnull_ref_test(void)
24{
25 QObject *obj;
26
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);
35}
36
37static void qnull_visit_test(void)
38{
39 QObject *obj;
b70ce101 40 Visitor *v;
7d7a337e
EB
41
42 /*
43 * Most tests of interactions between QObject and visitors are in
44 * test-qmp-*-visitor; but these tests live here because they
45 * depend on layering violations to check qnull_ refcnt.
46 */
47
48 g_assert(qnull_.refcnt == 1);
3df016f1 49 obj = qnull();
b70ce101 50 v = qmp_input_visitor_new(obj, true);
3df016f1 51 qobject_decref(obj);
b70ce101
EB
52 visit_type_null(v, NULL, &error_abort);
53 visit_free(v);
3df016f1 54
3b098d56
EB
55 v = qmp_output_visitor_new(&obj);
56 visit_type_null(v, NULL, &error_abort);
57 visit_complete(v, &obj);
7d7a337e
EB
58 g_assert(obj == &qnull_);
59 qobject_decref(obj);
3b098d56 60 visit_free(v);
3df016f1 61
7d7a337e
EB
62 g_assert(qnull_.refcnt == 1);
63}
64
65int main(int argc, char **argv)
66{
67 g_test_init(&argc, &argv, NULL);
68
69 g_test_add_func("/public/qnull_ref", qnull_ref_test);
70 g_test_add_func("/public/qnull_visit", qnull_visit_test);
71
72 return g_test_run();
73}