]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
testQEMUSchemaValidateEnum: Refactor logic to simplify switching to new QMP schema...
authorPeter Krempa <pkrempa@redhat.com>
Fri, 17 Sep 2021 14:21:43 +0000 (16:21 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 1 Nov 2021 16:37:15 +0000 (17:37 +0100)
QEMU-6.2 is reporting enum values in the new 'members' array which we'll
be switching to. Rewrite the logic so that adding the new checker is
more straightforward.

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

index 4f9db98e07b22fa21ffaf608413703c7e1ba63f6..82c5994604fd66e76747c2cc1f39568d9f293d56 100644 (file)
@@ -324,7 +324,6 @@ testQEMUSchemaValidateEnum(virJSONValue *obj,
 {
     const char *objstr;
     virJSONValue *values = NULL;
-    virJSONValue *value;
     size_t i;
 
     if (virJSONValueGetType(obj) != VIR_JSON_TYPE_STRING) {
@@ -334,24 +333,24 @@ testQEMUSchemaValidateEnum(virJSONValue *obj,
 
     objstr = virJSONValueGetString(obj);
 
-    if (!(values = virJSONValueObjectGetArray(root, "values"))) {
-        virBufferAsprintf(ctxt->debug, "ERROR: missing enum values in schema '%s'",
-                          NULLSTR(virJSONValueObjectGetString(root, "name")));
-        return -2;
-    }
-
-    for (i = 0; i < virJSONValueArraySize(values); i++) {
-        value = virJSONValueArrayGet(values, i);
+    if ((values = virJSONValueObjectGetArray(root, "values"))) {
+        for (i = 0; i < virJSONValueArraySize(values); i++) {
+            virJSONValue *value = virJSONValueArrayGet(values, i);
 
-        if (STREQ_NULLABLE(objstr, virJSONValueGetString(value))) {
-            virBufferAsprintf(ctxt->debug, "'%s' OK", NULLSTR(objstr));
-            return 0;
+            if (STREQ_NULLABLE(objstr, virJSONValueGetString(value))) {
+                virBufferAsprintf(ctxt->debug, "'%s' OK", NULLSTR(objstr));
+                return 0;
+            }
         }
+
+        virBufferAsprintf(ctxt->debug, "ERROR: enum value '%s' is not in schema",
+                          NULLSTR(objstr));
+        return -1;
     }
 
-    virBufferAsprintf(ctxt->debug, "ERROR: enum value '%s' is not in schema",
-                      NULLSTR(objstr));
-    return -1;
+    virBufferAsprintf(ctxt->debug, "ERROR: missing enum values in schema '%s'",
+                      NULLSTR(virJSONValueObjectGetString(root, "name")));
+    return -2;
 }