static int testCompareParseXML(const char *xmcfg, const char *xml, int xendConfigVersion) { char *xmlData = NULL; char *xmcfgData = NULL; char *gotxmcfgData = NULL; virConfPtr conf = NULL; int ret = -1; virConnectPtr conn = NULL; int wrote = 4096; struct _xenUnifiedPrivate priv; virDomainDefPtr def = NULL; if (VIR_ALLOC_N(gotxmcfgData, wrote) < 0) goto fail; conn = virGetConnect(); if (!conn) goto fail; if (virtTestLoadFile(xml, &xmlData) < 0) goto fail; if (virtTestLoadFile(xmcfg, &xmcfgData) < 0) goto fail; /* Many puppies died to bring you this code. */ priv.xendConfigVersion = xendConfigVersion; priv.caps = caps; conn->privateData = &priv; if (!(def = virDomainDefParseString(caps, xmlData, 1 << VIR_DOMAIN_VIRT_XEN, VIR_DOMAIN_XML_INACTIVE))) goto fail; if (!(conf = xenFormatXM(conn, def, xendConfigVersion))) goto fail; if (virConfWriteMem(gotxmcfgData, &wrote, conf) < 0) goto fail; gotxmcfgData[wrote] = '\0'; if (STRNEQ(xmcfgData, gotxmcfgData)) { virtTestDifference(stderr, xmcfgData, gotxmcfgData); goto fail; } ret = 0; fail: free(xmlData); free(xmcfgData); free(gotxmcfgData); if (conf) virConfFree(conf); virDomainDefFree(def); virUnrefConnect(conn); return ret; }
static int testCompareParseXML(const char *xmcfg, const char *xml) { char *gotxmcfgData = NULL; virConfPtr conf = NULL; int ret = -1; virConnectPtr conn = NULL; int wrote = 4096; struct _xenUnifiedPrivate priv; virDomainDefPtr def = NULL; if (VIR_ALLOC_N(gotxmcfgData, wrote) < 0) goto fail; conn = virGetConnect(); if (!conn) goto fail; /* Many puppies died to bring you this code. */ priv.caps = caps; conn->privateData = &priv; if (!(def = virDomainDefParseFile(xml, caps, xmlopt, NULL, VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto fail; if (!virDomainDefCheckABIStability(def, def, xmlopt)) { fprintf(stderr, "ABI stability check failed on %s", xml); goto fail; } if (!(conf = xenFormatXM(conn, def))) goto fail; if (virConfWriteMem(gotxmcfgData, &wrote, conf) < 0) goto fail; gotxmcfgData[wrote] = '\0'; if (virTestCompareToFile(gotxmcfgData, xmcfg) < 0) goto fail; ret = 0; fail: VIR_FREE(gotxmcfgData); if (conf) virConfFree(conf); virDomainDefFree(def); virObjectUnref(conn); return ret; }