]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
domainsnapshotxml2xmltest: Clean up labels and use bool instead of int
authorPeter Krempa <pkrempa@redhat.com>
Wed, 4 Dec 2013 12:49:40 +0000 (13:49 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 5 Dec 2013 08:40:13 +0000 (09:40 +0100)
The 'internal' variable holds only two states; convert it to a boolean
and the 'fail' label should be called 'cleanup'. This patch also fixes a
minor memory leak of driver capabilities in case the XML config object
can't be allocated.

tests/domainsnapshotxml2xmltest.c

index 92251193bb158cbe9426e294c826a698e51c63d7..c787f73568b8926c06dcc5b61eb4a12c8cd338ff 100644 (file)
@@ -23,7 +23,7 @@
 static virQEMUDriver driver;
 
 static int
-testCompareXMLToXMLFiles(const char *inxml, const char *uuid, int internal)
+testCompareXMLToXMLFiles(const char *inxml, const char *uuid, bool internal)
 {
     char *inXmlData = NULL;
     char *actual = NULL;
@@ -33,7 +33,7 @@ testCompareXMLToXMLFiles(const char *inxml, const char *uuid, int internal)
                           VIR_DOMAIN_SNAPSHOT_PARSE_DISKS);
 
     if (virtTestLoadFile(inxml, &inXmlData) < 0)
-        goto fail;
+        goto cleanup;
 
     if (internal)
         flags |= VIR_DOMAIN_SNAPSHOT_PARSE_INTERNAL;
@@ -41,21 +41,22 @@ testCompareXMLToXMLFiles(const char *inxml, const char *uuid, int internal)
                                                 driver.xmlopt,
                                                 QEMU_EXPECTED_VIRT_TYPES,
                                                 flags)))
-        goto fail;
+        goto cleanup;
 
     if (!(actual = virDomainSnapshotDefFormat(uuid, def,
                                               VIR_DOMAIN_XML_SECURE,
                                               internal)))
-        goto fail;
+        goto cleanup;
 
 
     if (STRNEQ(inXmlData, actual)) {
         virtTestDifference(stderr, inXmlData, actual);
-        goto fail;
+        goto cleanup;
     }
 
     ret = 0;
- fail:
+
+cleanup:
     VIR_FREE(inXmlData);
     VIR_FREE(actual);
     virDomainSnapshotDefFree(def);
@@ -65,9 +66,10 @@ testCompareXMLToXMLFiles(const char *inxml, const char *uuid, int internal)
 struct testInfo {
     const char *name;
     const char *uuid;
-    int internal;
+    bool internal;
 };
 
+
 static int
 testCompareXMLToXMLHelper(const void *data)
 {
@@ -95,8 +97,10 @@ mymain(void)
     if ((driver.caps = testQemuCapsInit()) == NULL)
         return EXIT_FAILURE;
 
-    if (!(driver.xmlopt = virQEMUDriverCreateXMLConf(&driver)))
+    if (!(driver.xmlopt = virQEMUDriverCreateXMLConf(&driver))) {
+        virObjectUnref(driver.caps);
         return EXIT_FAILURE;
+    }
 
 # define DO_TEST(name, uuid, internal)                                  \
     do {                                                                \
@@ -111,14 +115,14 @@ mymain(void)
      * values for these envvars */
     setenv("PATH", "/bin", 1);
 
-    DO_TEST("all_parameters", "9d37b878-a7cc-9f9a-b78f-49b3abad25a8", 1);
-    DO_TEST("disk_snapshot", "c7a5fdbd-edaf-9455-926a-d65c16db1809", 1);
-    DO_TEST("full_domain", "c7a5fdbd-edaf-9455-926a-d65c16db1809", 1);
-    DO_TEST("noparent_nodescription_noactive", NULL, 0);
-    DO_TEST("noparent_nodescription", NULL, 1);
-    DO_TEST("noparent", "9d37b878-a7cc-9f9a-b78f-49b3abad25a8", 0);
-    DO_TEST("metadata", "c7a5fdbd-edaf-9455-926a-d65c16db1809", 0);
-    DO_TEST("external_vm", "c7a5fdbd-edaf-9455-926a-d65c16db1809", 0);
+    DO_TEST("all_parameters", "9d37b878-a7cc-9f9a-b78f-49b3abad25a8", true);
+    DO_TEST("disk_snapshot", "c7a5fdbd-edaf-9455-926a-d65c16db1809", true);
+    DO_TEST("full_domain", "c7a5fdbd-edaf-9455-926a-d65c16db1809", true);
+    DO_TEST("noparent_nodescription_noactive", NULL, false);
+    DO_TEST("noparent_nodescription", NULL, true);
+    DO_TEST("noparent", "9d37b878-a7cc-9f9a-b78f-49b3abad25a8", false);
+    DO_TEST("metadata", "c7a5fdbd-edaf-9455-926a-d65c16db1809", false);
+    DO_TEST("external_vm", "c7a5fdbd-edaf-9455-926a-d65c16db1809", false);
 
     virObjectUnref(driver.caps);
     virObjectUnref(driver.xmlopt);