]>
Commit | Line | Data |
---|---|---|
382176b4 MAL |
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/qbool.h" | |
13 | #include "qapi/qmp/qdict.h" | |
14 | #include "qapi/qmp/qlit.h" | |
15 | #include "qapi/qmp/qnum.h" | |
16 | #include "qapi/qmp/qstring.h" | |
17 | ||
18 | static QLitObject qlit = QLIT_QDICT(((QLitDictEntry[]) { | |
19 | { "foo", QLIT_QNUM(42) }, | |
20 | { "bar", QLIT_QSTR("hello world") }, | |
21 | { "baz", QLIT_QNULL }, | |
22 | { "bee", QLIT_QLIST(((QLitObject[]) { | |
23 | QLIT_QNUM(43), | |
24 | QLIT_QNUM(44), | |
25 | QLIT_QBOOL(true), | |
26 | { }, | |
27 | }))}, | |
28 | { }, | |
29 | })); | |
30 | ||
6da8a7a3 MAL |
31 | static QLitObject qlit_foo = QLIT_QDICT(((QLitDictEntry[]) { |
32 | { "foo", QLIT_QNUM(42) }, | |
33 | { }, | |
34 | })); | |
35 | ||
382176b4 MAL |
36 | static QObject *make_qobject(void) |
37 | { | |
38 | QDict *qdict = qdict_new(); | |
39 | QList *list = qlist_new(); | |
40 | ||
41 | qdict_put_int(qdict, "foo", 42); | |
42 | qdict_put_str(qdict, "bar", "hello world"); | |
43 | qdict_put_null(qdict, "baz"); | |
44 | ||
45 | qlist_append_int(list, 43); | |
46 | qlist_append_int(list, 44); | |
47 | qlist_append_bool(list, true); | |
48 | qdict_put(qdict, "bee", list); | |
49 | ||
50 | return QOBJECT(qdict); | |
51 | } | |
52 | ||
53 | static void qlit_equal_qobject_test(void) | |
54 | { | |
55 | QObject *qobj = make_qobject(); | |
56 | ||
57 | g_assert(qlit_equal_qobject(&qlit, qobj)); | |
58 | ||
6da8a7a3 MAL |
59 | g_assert(!qlit_equal_qobject(&qlit_foo, qobj)); |
60 | ||
cbb65405 MAL |
61 | qdict_put(qobject_to_qdict(qobj), "bee", qlist_new()); |
62 | g_assert(!qlit_equal_qobject(&qlit, qobj)); | |
63 | ||
382176b4 MAL |
64 | qobject_decref(qobj); |
65 | } | |
66 | ||
67 | int main(int argc, char **argv) | |
68 | { | |
69 | g_test_init(&argc, &argv, NULL); | |
70 | ||
71 | g_test_add_func("/qlit/equal_qobject", qlit_equal_qobject_test); | |
72 | ||
73 | return g_test_run(); | |
74 | } |