]>
Commit | Line | Data |
---|---|---|
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 | 10 | |
84be629d | 11 | #include "qapi/qmp/qnull.h" |
7d7a337e | 12 | #include "qemu-common.h" |
b3db211f DB |
13 | #include "qapi/qobject-input-visitor.h" |
14 | #include "qapi/qobject-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 | ||
23 | static void qnull_ref_test(void) | |
24 | { | |
25 | QObject *obj; | |
26 | ||
006ca09f MA |
27 | g_assert(qnull_.base.refcnt == 1); |
28 | obj = QOBJECT(qnull()); | |
7d7a337e | 29 | g_assert(obj); |
006ca09f MA |
30 | g_assert(obj == QOBJECT(&qnull_)); |
31 | g_assert(qnull_.base.refcnt == 2); | |
7d7a337e | 32 | g_assert(qobject_type(obj) == QTYPE_QNULL); |
cb3e7f08 | 33 | qobject_unref(obj); |
006ca09f | 34 | g_assert(qnull_.base.refcnt == 1); |
7d7a337e EB |
35 | } |
36 | ||
37 | static void qnull_visit_test(void) | |
38 | { | |
39 | QObject *obj; | |
b70ce101 | 40 | Visitor *v; |
d2f95f4d | 41 | QNull *null; |
7d7a337e EB |
42 | |
43 | /* | |
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. | |
47 | */ | |
48 | ||
006ca09f MA |
49 | g_assert(qnull_.base.refcnt == 1); |
50 | obj = QOBJECT(qnull()); | |
048abb7b | 51 | v = qobject_input_visitor_new(obj); |
cb3e7f08 | 52 | qobject_unref(obj); |
d2f95f4d MA |
53 | visit_type_null(v, NULL, &null, &error_abort); |
54 | g_assert(obj == QOBJECT(&qnull_)); | |
cb3e7f08 | 55 | qobject_unref(null); |
b70ce101 | 56 | visit_free(v); |
3df016f1 | 57 | |
d2f95f4d | 58 | null = NULL; |
7d5e199a | 59 | v = qobject_output_visitor_new(&obj); |
d2f95f4d | 60 | visit_type_null(v, NULL, &null, &error_abort); |
3b098d56 | 61 | visit_complete(v, &obj); |
006ca09f | 62 | g_assert(obj == QOBJECT(&qnull_)); |
cb3e7f08 MAL |
63 | qobject_unref(null); |
64 | qobject_unref(obj); | |
3b098d56 | 65 | visit_free(v); |
3df016f1 | 66 | |
006ca09f | 67 | g_assert(qnull_.base.refcnt == 1); |
7d7a337e EB |
68 | } |
69 | ||
70 | int main(int argc, char **argv) | |
71 | { | |
72 | g_test_init(&argc, &argv, NULL); | |
73 | ||
74 | g_test_add_func("/public/qnull_ref", qnull_ref_test); | |
75 | g_test_add_func("/public/qnull_visit", qnull_visit_test); | |
76 | ||
77 | return g_test_run(); | |
78 | } |