|
9 | 9 |
|
10 | 10 | #include "qemu/osdep.h"
|
11 | 11 |
|
| 12 | +#include "qapi/qmp/qbool.h" |
12 | 13 | #include "qapi/qmp/qdict.h"
|
13 | 14 | #include "qapi/qmp/qlist.h"
|
14 | 15 | #include "qapi/qmp/qlit.h"
|
| 16 | +#include "qapi/qmp/qnum.h" |
15 | 17 | #include "qapi/qmp/qstring.h"
|
16 | 18 |
|
17 | 19 | static QLitObject qlit = QLIT_QDICT(((QLitDictEntry[]) {
|
@@ -63,11 +65,37 @@ static void qlit_equal_qobject_test(void)
|
63 | 65 | qobject_decref(qobj);
|
64 | 66 | }
|
65 | 67 |
|
| 68 | +static void qobject_from_qlit_test(void) |
| 69 | +{ |
| 70 | + QObject *obj, *qobj = qobject_from_qlit(&qlit); |
| 71 | + QDict *qdict; |
| 72 | + QList *bee; |
| 73 | + |
| 74 | + qdict = qobject_to_qdict(qobj); |
| 75 | + g_assert_cmpint(qdict_get_int(qdict, "foo"), ==, 42); |
| 76 | + g_assert_cmpstr(qdict_get_str(qdict, "bar"), ==, "hello world"); |
| 77 | + g_assert(qobject_type(qdict_get(qdict, "baz")) == QTYPE_QNULL); |
| 78 | + |
| 79 | + bee = qdict_get_qlist(qdict, "bee"); |
| 80 | + obj = qlist_pop(bee); |
| 81 | + g_assert_cmpint(qnum_get_int(qobject_to_qnum(obj)), ==, 43); |
| 82 | + qobject_decref(obj); |
| 83 | + obj = qlist_pop(bee); |
| 84 | + g_assert_cmpint(qnum_get_int(qobject_to_qnum(obj)), ==, 44); |
| 85 | + qobject_decref(obj); |
| 86 | + obj = qlist_pop(bee); |
| 87 | + g_assert(qbool_get_bool(qobject_to_qbool(obj))); |
| 88 | + qobject_decref(obj); |
| 89 | + |
| 90 | + qobject_decref(qobj); |
| 91 | +} |
| 92 | + |
66 | 93 | int main(int argc, char **argv)
|
67 | 94 | {
|
68 | 95 | g_test_init(&argc, &argv, NULL);
|
69 | 96 |
|
70 | 97 | g_test_add_func("/qlit/equal_qobject", qlit_equal_qobject_test);
|
| 98 | + g_test_add_func("/qlit/qobject_from_qlit", qobject_from_qlit_test); |
71 | 99 |
|
72 | 100 | return g_test_run();
|
73 | 101 | }
|
0 commit comments