From: Michal Privoznik Date: Wed, 17 Dec 2025 10:31:52 +0000 (+0100) Subject: networkxml2xmltest: Store parsed def for future tests X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=369020180a8601521689f5c5491b1105eb79347e;p=thirdparty%2Flibvirt.git networkxml2xmltest: Store parsed def for future tests Soon, the testRun() will run more than one test case. The input network XML, however, stays the same. Instead of parsing it and throwing away immediately, store it temporarily. Signed-off-by: Michal Privoznik Reviewed-by: Ján Tomko --- diff --git a/tests/networkxml2xmltest.c b/tests/networkxml2xmltest.c index e90b38088a..4a4cf329e4 100644 --- a/tests/networkxml2xmltest.c +++ b/tests/networkxml2xmltest.c @@ -27,6 +27,7 @@ struct _testInfo { unsigned int flags; testCompareNetXML2XMLResult expectResult; virNetworkXMLOption *xmlopt; /* borrowed, immutable */ + virNetworkDef *def; char *inxml; char *outxml; }; @@ -40,6 +41,7 @@ void testInfoFree(testInfo *info) if (!info) return; + virNetworkDefFree(info->def); VIR_FREE(info->inxml); VIR_FREE(info->outxml); VIR_FREE(info); @@ -52,23 +54,23 @@ testCompareXMLToXMLFiles(const void *data) g_autofree char *actual = NULL; int ret; testCompareNetXML2XMLResult result = TEST_COMPARE_NET_XML2XML_RESULT_SUCCESS; - g_autoptr(virNetworkDef) dev = NULL; + g_autoptr(virNetworkDef) def = NULL; - if (!(dev = virNetworkDefParse(NULL, info->inxml, info->xmlopt, false))) { + if (!(def = virNetworkDefParse(NULL, info->inxml, info->xmlopt, false))) { result = TEST_COMPARE_NET_XML2XML_RESULT_FAIL_PARSE; goto cleanup; } if (info->expectResult == TEST_COMPARE_NET_XML2XML_RESULT_FAIL_PARSE) goto cleanup; - if (networkValidateTests(dev) < 0) { + if (networkValidateTests(def) < 0) { result = TEST_COMPARE_NET_XML2XML_RESULT_FAIL_VALIDATE; goto cleanup; } if (info->expectResult == TEST_COMPARE_NET_XML2XML_RESULT_FAIL_VALIDATE) goto cleanup; - if (!(actual = virNetworkDefFormat(dev, info->xmlopt, info->flags))) { + if (!(actual = virNetworkDefFormat(def, info->xmlopt, info->flags))) { result = TEST_COMPARE_NET_XML2XML_RESULT_FAIL_FORMAT; goto cleanup; } @@ -88,6 +90,8 @@ testCompareXMLToXMLFiles(const void *data) if (info->expectResult != TEST_COMPARE_NET_XML2XML_RESULT_SUCCESS) { VIR_TEST_DEBUG("Got expected failure code=%d msg=%s", result, virGetLastErrorMessage()); + } else { + info->def = g_steal_pointer(&def); } } else { ret = -1;