mirror of
https://github.com/libvirt/libvirt.git
synced 2026-09-03 20:53:04 -05:00
tests: Add virtTestCompareToFile
Replaces a common pattern used in many test files
This commit is contained in:
+2
-16
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user