tests: Add virtTestCompareToFile

Replaces a common pattern used in many test files
This commit is contained in:
Cole Robinson
2015-04-23 17:08:48 -04:00
parent bdbe26b504
commit ca32929908
32 changed files with 78 additions and 324 deletions
+2 -16
View File
@@ -48,7 +48,6 @@ static virDomainXMLOptionPtr xmlopt;
static int
testCompareParseXML(const char *xmcfg, const char *xml, int xendConfigVersion)
{
char *xmcfgData = NULL;
char *gotxmcfgData = NULL;
virConfPtr conf = NULL;
virConnectPtr conn = NULL;
@@ -62,9 +61,6 @@ testCompareParseXML(const char *xmcfg, const char *xml, int xendConfigVersion)
conn = virGetConnect();
if (!conn) goto fail;
if (virtTestLoadFile(xmcfg, &xmcfgData) < 0)
goto fail;
if (!(def = virDomainDefParseFile(xml, caps, xmlopt,
VIR_DOMAIN_XML_INACTIVE)))
goto fail;
@@ -81,15 +77,12 @@ testCompareParseXML(const char *xmcfg, const char *xml, int xendConfigVersion)
goto fail;
gotxmcfgData[wrote] = '\0';
if (STRNEQ(xmcfgData, gotxmcfgData)) {
virtTestDifference(stderr, xmcfgData, gotxmcfgData);
if (virtTestCompareToFile(gotxmcfgData, xmcfg) < 0)
goto fail;
}
ret = 0;
fail:
VIR_FREE(xmcfgData);
VIR_FREE(gotxmcfgData);
if (conf)
virConfFree(conf);
@@ -104,7 +97,6 @@ testCompareParseXML(const char *xmcfg, const char *xml, int xendConfigVersion)
static int
testCompareFormatXML(const char *xmcfg, const char *xml, int xendConfigVersion)
{
char *xmlData = NULL;
char *xmcfgData = NULL;
char *gotxml = NULL;
virConfPtr conf = NULL;
@@ -115,9 +107,6 @@ testCompareFormatXML(const char *xmcfg, const char *xml, int xendConfigVersion)
conn = virGetConnect();
if (!conn) goto fail;
if (virtTestLoadFile(xml, &xmlData) < 0)
goto fail;
if (virtTestLoadFile(xmcfg, &xmcfgData) < 0)
goto fail;
@@ -131,17 +120,14 @@ testCompareFormatXML(const char *xmcfg, const char *xml, int xendConfigVersion)
VIR_DOMAIN_XML_SECURE)))
goto fail;
if (STRNEQ(xmlData, gotxml)) {
virtTestDifference(stderr, xmlData, gotxml);
if (virtTestCompareToFile(gotxml, xml) < 0)
goto fail;
}
ret = 0;
fail:
if (conf)
virConfFree(conf);
VIR_FREE(xmlData);
VIR_FREE(xmcfgData);
VIR_FREE(gotxml);
virDomainDefFree(def);