]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
tests: qemumonitorjson: Add tests for QAPI schema query
authorPeter Krempa <pkrempa@redhat.com>
Tue, 9 Apr 2019 11:22:32 +0000 (13:22 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 6 May 2019 07:46:06 +0000 (09:46 +0200)
While we technically test the query strings in the qemucapabilitiestest
this was done to help refactor and extend the QAPI schema query
infrastructure.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
tests/qemumonitorjsontest.c

index 120941c780584b10b147307c5ccec6cd72babbb3..41092e199ce1dea09dfe286fda69d2fa677a8f73 100644 (file)
@@ -2834,9 +2834,30 @@ struct testQAPISchemaData {
     const char *query;
     const char *json;
     bool success;
+    int rc;
+    bool replyobj;
 };
 
 
+static int
+testQAPISchemaQuery(const void *opaque)
+{
+    const struct testQAPISchemaData *data = opaque;
+    virJSONValuePtr replyobj = NULL;
+    int rc;
+
+    rc = virQEMUQAPISchemaPathGet(data->query, data->schema, &replyobj);
+
+    if (data->rc != rc || data->replyobj != !!replyobj) {
+        VIR_TEST_VERBOSE("\n success: expected '%d' got '%d', replyobj: expected '%d' got '%d'",
+                         data->rc, rc, data->replyobj, !!replyobj);
+        return -1;
+    }
+
+    return 0;
+}
+
+
 static int
 testQAPISchemaValidate(const void *opaque)
 {
@@ -3054,6 +3075,30 @@ mymain(void)
 
 #undef DO_TEST_BLOCK_NODE_DETECT
 
+#define DO_TEST_QAPI_QUERY(nme, qry, scc, rplobj) \
+    do { \
+        qapiData.name = nme; \
+        qapiData.query = qry; \
+        qapiData.rc = scc; \
+        qapiData.replyobj = rplobj; \
+        if (virTestRun("qapi schema query" nme, testQAPISchemaQuery, &qapiData) < 0)\
+            ret = -1; \
+    } while (0)
+
+    DO_TEST_QAPI_QUERY("command", "blockdev-add", 0, true);
+    DO_TEST_QAPI_QUERY("event", "RTC_CHANGE", 0, true);
+    DO_TEST_QAPI_QUERY("object property", "screendump/arg-type/device", 0, true);
+    DO_TEST_QAPI_QUERY("optional property", "block-commit/arg-type/*top", 0, true);
+    DO_TEST_QAPI_QUERY("variant", "blockdev-add/arg-type/+file", 0, true);
+    DO_TEST_QAPI_QUERY("variant property", "blockdev-add/arg-type/+file/filename", 0, true);
+
+    DO_TEST_QAPI_QUERY("nonexistent command", "nonexistent", 0, false);
+    DO_TEST_QAPI_QUERY("nonexistent attr", "screendump/arg-type/nonexistent", 0, false);
+    DO_TEST_QAPI_QUERY("nonexistent variant", "blockdev-add/arg-type/+nonexistent", 0, false);
+
+#undef DO_TEST_QAPI_QUERY
+
+
 #define DO_TEST_QAPI_VALIDATE(nme, rootquery, scc, jsonstr) \
     do { \
         qapiData.name = nme; \