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.
9 #include "qemu/osdep.h"
11 #include "qapi/qmp/qobject.h"
12 #include "qemu-common.h"
13 #include "qapi/qobject-input-visitor.h"
14 #include "qapi/qobject-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)
27 g_assert(qnull_
.refcnt
== 1);
30 g_assert(obj
== &qnull_
);
31 g_assert(qnull_
.refcnt
== 2);
32 g_assert(qobject_type(obj
) == QTYPE_QNULL
);
34 g_assert(qnull_
.refcnt
== 1);
37 static void qnull_visit_test(void)
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.
48 g_assert(qnull_
.refcnt
== 1);
50 v
= qobject_input_visitor_new(obj
, true);
52 visit_type_null(v
, NULL
, &error_abort
);
55 v
= qobject_output_visitor_new(&obj
);
56 visit_type_null(v
, NULL
, &error_abort
);
57 visit_complete(v
, &obj
);
58 g_assert(obj
== &qnull_
);
62 g_assert(qnull_
.refcnt
== 1);
65 int main(int argc
, char **argv
)
67 g_test_init(&argc
, &argv
, NULL
);
69 g_test_add_func("/public/qnull_ref", qnull_ref_test
);
70 g_test_add_func("/public/qnull_visit", qnull_visit_test
);