1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-07 17:28:15 +00:00

domainsnapshotxml2xmltest: Clean up labels and use bool instead of int

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.
This commit is contained in:
Peter Krempa 2013-12-04 13:49:40 +01:00
parent 62774afb6b
commit af75de308f

View File

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