]> git.proxmox.com Git - mirror_qemu.git/blob - tests/check-qlit.c
Merge remote-tracking branch 'remotes/mst/tags/for_upstream' into staging
[mirror_qemu.git] / tests / check-qlit.c
1 /*
2 * QLit unit-tests.
3 *
4 * Copyright (C) 2017 Red Hat Inc.
5 *
6 * This work is licensed under the terms of the GNU GPL, version 2 or later.
7 * See the COPYING file in the top-level directory.
8 */
9
10 #include "qemu/osdep.h"
11
12 #include "qapi/qmp/qdict.h"
13 #include "qapi/qmp/qlist.h"
14 #include "qapi/qmp/qlit.h"
15 #include "qapi/qmp/qstring.h"
16
17 static QLitObject qlit = QLIT_QDICT(((QLitDictEntry[]) {
18 { "foo", QLIT_QNUM(42) },
19 { "bar", QLIT_QSTR("hello world") },
20 { "baz", QLIT_QNULL },
21 { "bee", QLIT_QLIST(((QLitObject[]) {
22 QLIT_QNUM(43),
23 QLIT_QNUM(44),
24 QLIT_QBOOL(true),
25 { },
26 }))},
27 { },
28 }));
29
30 static QLitObject qlit_foo = QLIT_QDICT(((QLitDictEntry[]) {
31 { "foo", QLIT_QNUM(42) },
32 { },
33 }));
34
35 static QObject *make_qobject(void)
36 {
37 QDict *qdict = qdict_new();
38 QList *list = qlist_new();
39
40 qdict_put_int(qdict, "foo", 42);
41 qdict_put_str(qdict, "bar", "hello world");
42 qdict_put_null(qdict, "baz");
43
44 qlist_append_int(list, 43);
45 qlist_append_int(list, 44);
46 qlist_append_bool(list, true);
47 qdict_put(qdict, "bee", list);
48
49 return QOBJECT(qdict);
50 }
51
52 static void qlit_equal_qobject_test(void)
53 {
54 QObject *qobj = make_qobject();
55
56 g_assert(qlit_equal_qobject(&qlit, qobj));
57
58 g_assert(!qlit_equal_qobject(&qlit_foo, qobj));
59
60 qdict_put(qobject_to_qdict(qobj), "bee", qlist_new());
61 g_assert(!qlit_equal_qobject(&qlit, qobj));
62
63 qobject_decref(qobj);
64 }
65
66 int main(int argc, char **argv)
67 {
68 g_test_init(&argc, &argv, NULL);
69
70 g_test_add_func("/qlit/equal_qobject", qlit_equal_qobject_test);
71
72 return g_test_run();
73 }