diff mbox

[20/36] qtest: Avoid dynamic JSON in device-introspect-test

Message ID 1480535094-23831-21-git-send-email-eblake@redhat.com
State New
Headers show

Commit Message

Eric Blake Nov. 30, 2016, 7:44 p.m. UTC
As argued elsewhere, it's less code to maintain if we convert
from a dynamic string passed to qobject_from_jsonv() to instead
use a hand-built QDict.

Signed-off-by: Eric Blake <eblake@redhat.com>
---
 tests/device-introspect-test.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
diff mbox

Patch

diff --git a/tests/device-introspect-test.c b/tests/device-introspect-test.c
index 37debc1..9655a49 100644
--- a/tests/device-introspect-test.c
+++ b/tests/device-introspect-test.c
@@ -19,6 +19,8 @@ 

 #include "qemu/osdep.h"
 #include "qemu-common.h"
+#include "qapi/qmp/qbool.h"
+#include "qapi/qmp/qdict.h"
 #include "qapi/qmp/qstring.h"
 #include "libqtest.h"

@@ -28,10 +30,11 @@  static QList *device_type_list(bool abstract)
 {
     QDict *resp;
     QList *ret;
+    QDict *args = qdict_new();

-    resp = qmp("{'execute': 'qom-list-types',"
-               " 'arguments': {'implements': 'device', 'abstract': %i}}",
-               abstract);
+    qdict_put_str(args, "implements", "device");
+    qdict_put_bool(args, "abstract", abstract);
+    resp = qmp_cmd("qom-list-types", args);
     g_assert(qdict_haskey(resp, "return"));
     ret = qdict_get_qlist(resp, "return");
     QINCREF(ret);
@@ -43,10 +46,10 @@  static void test_one_device(const char *type)
 {
     QDict *resp;
     char *help, *qom_tree;
+    QDict *args = qdict_new();

-    resp = qmp("{'execute': 'device-list-properties',"
-               " 'arguments': {'typename': %s}}",
-               type);
+    qdict_put_str(args, "typename", type);
+    resp = qmp_cmd("device-list-properties", args);
     QDECREF(resp);

     help = hmp("device_add \"%s,help\"", type);