render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
c401cc
From 51006099fec3d69fd90a71d71b5d464767652ee4 Mon Sep 17 00:00:00 2001
c401cc
Message-Id: <51006099fec3d69fd90a71d71b5d464767652ee4@dist-git>
c401cc
From: Peter Krempa <pkrempa@redhat.com>
c401cc
Date: Wed, 26 Feb 2014 14:55:04 +0100
c401cc
Subject: [PATCH] domainsnapshotxml2xmltest: Clean up labels and use bool
c401cc
 instead of int
c401cc
c401cc
https://bugzilla.redhat.com/show_bug.cgi?id=1032370
c401cc
c401cc
The 'internal' variable holds only two states; convert it to a boolean
c401cc
and the 'fail' label should be called 'cleanup'. This patch also fixes a
c401cc
minor memory leak of driver capabilities in case the XML config object
c401cc
can't be allocated.
c401cc
c401cc
(cherry picked from commit af75de308f0f491f8be55917f58f3faa700108cc)
c401cc
c401cc
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c401cc
---
c401cc
 tests/domainsnapshotxml2xmltest.c | 36 ++++++++++++++++++++----------------
c401cc
 1 file changed, 20 insertions(+), 16 deletions(-)
c401cc
c401cc
diff --git a/tests/domainsnapshotxml2xmltest.c b/tests/domainsnapshotxml2xmltest.c
c401cc
index defa955..ea33688 100644
c401cc
--- a/tests/domainsnapshotxml2xmltest.c
c401cc
+++ b/tests/domainsnapshotxml2xmltest.c
c401cc
@@ -23,7 +23,7 @@
c401cc
 static virQEMUDriver driver;
c401cc
 
c401cc
 static int
c401cc
-testCompareXMLToXMLFiles(const char *inxml, const char *uuid, int internal)
c401cc
+testCompareXMLToXMLFiles(const char *inxml, const char *uuid, bool internal)
c401cc
 {
c401cc
     char *inXmlData = NULL;
c401cc
     char *actual = NULL;
c401cc
@@ -33,7 +33,7 @@ testCompareXMLToXMLFiles(const char *inxml, const char *uuid, int internal)
c401cc
                           VIR_DOMAIN_SNAPSHOT_PARSE_DISKS);
c401cc
 
c401cc
     if (virtTestLoadFile(inxml, &inXmlData) < 0)
c401cc
-        goto fail;
c401cc
+        goto cleanup;
c401cc
 
c401cc
     if (internal)
c401cc
         flags |= VIR_DOMAIN_SNAPSHOT_PARSE_INTERNAL;
c401cc
@@ -41,21 +41,22 @@ testCompareXMLToXMLFiles(const char *inxml, const char *uuid, int internal)
c401cc
                                                 driver.xmlopt,
c401cc
                                                 QEMU_EXPECTED_VIRT_TYPES,
c401cc
                                                 flags)))
c401cc
-        goto fail;
c401cc
+        goto cleanup;
c401cc
 
c401cc
     if (!(actual = virDomainSnapshotDefFormat(uuid, def,
c401cc
                                               VIR_DOMAIN_XML_SECURE,
c401cc
                                               internal)))
c401cc
-        goto fail;
c401cc
+        goto cleanup;
c401cc
 
c401cc
 
c401cc
     if (STRNEQ(inXmlData, actual)) {
c401cc
         virtTestDifference(stderr, inXmlData, actual);
c401cc
-        goto fail;
c401cc
+        goto cleanup;
c401cc
     }
c401cc
 
c401cc
     ret = 0;
c401cc
- fail:
c401cc
+
c401cc
+cleanup:
c401cc
     VIR_FREE(inXmlData);
c401cc
     VIR_FREE(actual);
c401cc
     virDomainSnapshotDefFree(def);
c401cc
@@ -65,9 +66,10 @@ testCompareXMLToXMLFiles(const char *inxml, const char *uuid, int internal)
c401cc
 struct testInfo {
c401cc
     const char *name;
c401cc
     const char *uuid;
c401cc
-    int internal;
c401cc
+    bool internal;
c401cc
 };
c401cc
 
c401cc
+
c401cc
 static int
c401cc
 testCompareXMLToXMLHelper(const void *data)
c401cc
 {
c401cc
@@ -95,8 +97,10 @@ mymain(void)
c401cc
     if ((driver.caps = testQemuCapsInit()) == NULL)
c401cc
         return EXIT_FAILURE;
c401cc
 
c401cc
-    if (!(driver.xmlopt = virQEMUDriverCreateXMLConf(&driver)))
c401cc
+    if (!(driver.xmlopt = virQEMUDriverCreateXMLConf(&driver))) {
c401cc
+        virObjectUnref(driver.caps);
c401cc
         return EXIT_FAILURE;
c401cc
+    }
c401cc
 
c401cc
 # define DO_TEST(name, uuid, internal)                                  \
c401cc
     do {                                                                \
c401cc
@@ -111,14 +115,14 @@ mymain(void)
c401cc
      * values for these envvars */
c401cc
     setenv("PATH", "/bin", 1);
c401cc
 
c401cc
-    DO_TEST("all_parameters", "9d37b878-a7cc-9f9a-b78f-49b3abad25a8", 1);
c401cc
-    DO_TEST("disk_snapshot", "c7a5fdbd-edaf-9455-926a-d65c16db1809", 1);
c401cc
-    DO_TEST("full_domain", "c7a5fdbd-edaf-9455-926a-d65c16db1809", 1);
c401cc
-    DO_TEST("noparent_nodescription_noactive", NULL, 0);
c401cc
-    DO_TEST("noparent_nodescription", NULL, 1);
c401cc
-    DO_TEST("noparent", "9d37b878-a7cc-9f9a-b78f-49b3abad25a8", 0);
c401cc
-    DO_TEST("metadata", "c7a5fdbd-edaf-9455-926a-d65c16db1809", 0);
c401cc
-    DO_TEST("external_vm", "c7a5fdbd-edaf-9455-926a-d65c16db1809", 0);
c401cc
+    DO_TEST("all_parameters", "9d37b878-a7cc-9f9a-b78f-49b3abad25a8", true);
c401cc
+    DO_TEST("disk_snapshot", "c7a5fdbd-edaf-9455-926a-d65c16db1809", true);
c401cc
+    DO_TEST("full_domain", "c7a5fdbd-edaf-9455-926a-d65c16db1809", true);
c401cc
+    DO_TEST("noparent_nodescription_noactive", NULL, false);
c401cc
+    DO_TEST("noparent_nodescription", NULL, true);
c401cc
+    DO_TEST("noparent", "9d37b878-a7cc-9f9a-b78f-49b3abad25a8", false);
c401cc
+    DO_TEST("metadata", "c7a5fdbd-edaf-9455-926a-d65c16db1809", false);
c401cc
+    DO_TEST("external_vm", "c7a5fdbd-edaf-9455-926a-d65c16db1809", false);
c401cc
 
c401cc
     virObjectUnref(driver.caps);
c401cc
     virObjectUnref(driver.xmlopt);
c401cc
-- 
c401cc
1.9.0
c401cc