]> git.proxmox.com Git - mirror_qemu.git/blobdiff - tests/check-qlit.c
qobject: Replace qobject_incref/QINCREF qobject_decref/QDECREF
[mirror_qemu.git] / tests / check-qlit.c
index f012885534a77ea52daa91d72c3ef88852dc4ac8..bd6798d91224ba5e9b9d4f5c71c7432a1c87f91c 100644 (file)
@@ -9,6 +9,7 @@
 
 #include "qemu/osdep.h"
 
+#include "qapi/qmp/qbool.h"
 #include "qapi/qmp/qdict.h"
 #include "qapi/qmp/qlist.h"
 #include "qapi/qmp/qlit.h"
@@ -58,10 +59,35 @@ static void qlit_equal_qobject_test(void)
 
     g_assert(!qlit_equal_qobject(&qlit_foo, qobj));
 
-    qdict_put(qobject_to_qdict(qobj), "bee", qlist_new());
+    qdict_put(qobject_to(QDict, qobj), "bee", qlist_new());
     g_assert(!qlit_equal_qobject(&qlit, qobj));
 
-    qobject_decref(qobj);
+    qobject_unref(qobj);
+}
+
+static void qobject_from_qlit_test(void)
+{
+    QObject *obj, *qobj = qobject_from_qlit(&qlit);
+    QDict *qdict;
+    QList *bee;
+
+    qdict = qobject_to(QDict, qobj);
+    g_assert_cmpint(qdict_get_int(qdict, "foo"), ==, 42);
+    g_assert_cmpstr(qdict_get_str(qdict, "bar"), ==, "hello world");
+    g_assert(qobject_type(qdict_get(qdict, "baz")) == QTYPE_QNULL);
+
+    bee = qdict_get_qlist(qdict, "bee");
+    obj = qlist_pop(bee);
+    g_assert_cmpint(qnum_get_int(qobject_to(QNum, obj)), ==, 43);
+    qobject_unref(obj);
+    obj = qlist_pop(bee);
+    g_assert_cmpint(qnum_get_int(qobject_to(QNum, obj)), ==, 44);
+    qobject_unref(obj);
+    obj = qlist_pop(bee);
+    g_assert(qbool_get_bool(qobject_to(QBool, obj)));
+    qobject_unref(obj);
+
+    qobject_unref(qobj);
 }
 
 int main(int argc, char **argv)
@@ -69,6 +95,7 @@ int main(int argc, char **argv)
     g_test_init(&argc, &argv, NULL);
 
     g_test_add_func("/qlit/equal_qobject", qlit_equal_qobject_test);
+    g_test_add_func("/qlit/qobject_from_qlit", qobject_from_qlit_test);
 
     return g_test_run();
 }