Blob Blame History Raw
From 51006099fec3d69fd90a71d71b5d464767652ee4 Mon Sep 17 00:00:00 2001
Message-Id: <51006099fec3d69fd90a71d71b5d464767652ee4@dist-git>
From: Peter Krempa <pkrempa@redhat.com>
Date: Wed, 26 Feb 2014 14:55:04 +0100
Subject: [PATCH] domainsnapshotxml2xmltest: Clean up labels and use bool
 instead of int

https://bugzilla.redhat.com/show_bug.cgi?id=1032370

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.

(cherry picked from commit af75de308f0f491f8be55917f58f3faa700108cc)

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 tests/domainsnapshotxml2xmltest.c | 36 ++++++++++++++++++++----------------
 1 file changed, 20 insertions(+), 16 deletions(-)

diff --git a/tests/domainsnapshotxml2xmltest.c b/tests/domainsnapshotxml2xmltest.c
index defa955..ea33688 100644
--- a/tests/domainsnapshotxml2xmltest.c
+++ b/tests/domainsnapshotxml2xmltest.c
@@ -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);
-- 
1.9.0