]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
networkxml2xmltest: Move path generation into testRun()
authorMichal Privoznik <mprivozn@redhat.com>
Wed, 17 Dec 2025 08:51:17 +0000 (09:51 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 29 Jan 2026 12:39:04 +0000 (13:39 +0100)
This effectively dissolves testCompareXMLToXMLHelper() into
testRun(). Motivation is that parts of data generated inside of
testCompareXMLToXMLHelper() is going to be reused from the caller
(testRun()).

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
tests/networkxml2xmltest.c

index 552364818d52ef4c20fc82f161840996a4df3854..2a537d77c06a0ce9403ffd30f501e5e7c1105114 100644 (file)
@@ -22,86 +22,69 @@ typedef enum {
     TEST_COMPARE_NET_XML2XML_RESULT_FAIL_COMPARE,
 } testCompareNetXML2XMLResult;
 
+struct testInfo {
+    const char *name;
+    unsigned int flags;
+    testCompareNetXML2XMLResult expectResult;
+    virNetworkXMLOption *xmlopt;
+    const char *inxml;
+    const char *outxml;
+};
+
 static int
-testCompareXMLToXMLFiles(const char *inxml,
-                         const char *outxml,
-                         unsigned int flags,
-                         testCompareNetXML2XMLResult expectResult,
-                         virNetworkXMLOption *xmlopt)
+testCompareXMLToXMLFiles(const void *data)
 {
+    struct testInfo *info = (void *) data;
     g_autofree char *actual = NULL;
     int ret;
     testCompareNetXML2XMLResult result = TEST_COMPARE_NET_XML2XML_RESULT_SUCCESS;
     g_autoptr(virNetworkDef) dev = NULL;
 
-    if (!(dev = virNetworkDefParse(NULL, inxml, xmlopt, false))) {
+    if (!(dev = virNetworkDefParse(NULL, info->inxml, info->xmlopt, false))) {
         result = TEST_COMPARE_NET_XML2XML_RESULT_FAIL_PARSE;
         goto cleanup;
     }
-    if (expectResult == TEST_COMPARE_NET_XML2XML_RESULT_FAIL_PARSE)
+    if (info->expectResult == TEST_COMPARE_NET_XML2XML_RESULT_FAIL_PARSE)
         goto cleanup;
 
     if (networkValidateTests(dev) < 0) {
         result = TEST_COMPARE_NET_XML2XML_RESULT_FAIL_VALIDATE;
         goto cleanup;
     }
-    if (expectResult == TEST_COMPARE_NET_XML2XML_RESULT_FAIL_VALIDATE)
+    if (info->expectResult == TEST_COMPARE_NET_XML2XML_RESULT_FAIL_VALIDATE)
         goto cleanup;
 
-    if (!(actual = virNetworkDefFormat(dev, xmlopt, flags))) {
+    if (!(actual = virNetworkDefFormat(dev, info->xmlopt, info->flags))) {
         result = TEST_COMPARE_NET_XML2XML_RESULT_FAIL_FORMAT;
         goto cleanup;
     }
-    if (expectResult == TEST_COMPARE_NET_XML2XML_RESULT_FAIL_FORMAT)
+    if (info->expectResult == TEST_COMPARE_NET_XML2XML_RESULT_FAIL_FORMAT)
         goto cleanup;
 
-    if (virTestCompareToFile(actual, outxml) < 0) {
+    if (virTestCompareToFile(actual, info->outxml) < 0) {
         result = TEST_COMPARE_NET_XML2XML_RESULT_FAIL_COMPARE;
         goto cleanup;
     }
-    if (expectResult == TEST_COMPARE_NET_XML2XML_RESULT_FAIL_COMPARE)
+    if (info->expectResult == TEST_COMPARE_NET_XML2XML_RESULT_FAIL_COMPARE)
         goto cleanup;
 
  cleanup:
-    if (result == expectResult) {
+    if (result == info->expectResult) {
         ret = 0;
-        if (expectResult != TEST_COMPARE_NET_XML2XML_RESULT_SUCCESS) {
+        if (info->expectResult != TEST_COMPARE_NET_XML2XML_RESULT_SUCCESS) {
             VIR_TEST_DEBUG("Got expected failure code=%d msg=%s",
                            result, virGetLastErrorMessage());
         }
     } else {
         ret = -1;
         VIR_TEST_DEBUG("Expected result code=%d but received code=%d",
-                       expectResult, result);
+                       info->expectResult, result);
     }
     virResetLastError();
 
     return ret;
 }
 
-struct testInfo {
-    const char *name;
-    unsigned int flags;
-    testCompareNetXML2XMLResult expectResult;
-    virNetworkXMLOption *xmlopt;
-};
-
-static int
-testCompareXMLToXMLHelper(const void *data)
-{
-    const struct testInfo *info = data;
-    int result = -1;
-    g_autofree char *inxml = NULL;
-    g_autofree char *outxml = NULL;
-
-    inxml = g_strdup_printf("%s/networkxml2xmlin/%s.xml", abs_srcdir, info->name);
-    outxml = g_strdup_printf("%s/networkxml2xmlout/%s.xml", abs_srcdir, info->name);
-
-    result = testCompareXMLToXMLFiles(inxml, outxml, info->flags,
-                                      info->expectResult, info->xmlopt);
-
-    return result;
-}
 
 static void
 testRun(const char *name,
@@ -112,8 +95,16 @@ testRun(const char *name,
 {
     g_autofree char *name_xml2xml = g_strdup_printf("Network XML-2-XML %s", name);
     struct testInfo info = { .name = name, .flags = flags, .expectResult = expectResult, .xmlopt = xmlopt };
+    g_autofree char *inxml = NULL;
+    g_autofree char *outxml = NULL;
+
+    inxml = g_strdup_printf("%s/networkxml2xmlin/%s.xml", abs_srcdir, name);
+    outxml = g_strdup_printf("%s/networkxml2xmlout/%s.xml", abs_srcdir, name);
+
+    info.inxml = inxml;
+    info.outxml = outxml;
 
-    virTestRunLog(ret, name_xml2xml, testCompareXMLToXMLHelper, &info);
+    virTestRunLog(ret, name_xml2xml, testCompareXMLToXMLFiles, &info);
 }
 
 static int