[libvirt PATCH 4/5] tests: introduce testVirNetDevBandwidthParse

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The 'PARSE' macro does not use '#' or '##' directives,
or anything from outside of the macro other than the
cleanup label.

Turn it into a function.

Signed-off-by: Ján Tomko <jtomko@xxxxxxxxxx>
---
 tests/virnetdevbandwidthtest.c   | 44 ++++++++++++++++----------------
 tests/virnetdevopenvswitchtest.c | 44 ++++++++++++++++----------------
 2 files changed, 44 insertions(+), 44 deletions(-)

diff --git a/tests/virnetdevbandwidthtest.c b/tests/virnetdevbandwidthtest.c
index 197d936479..a17737ec40 100644
--- a/tests/virnetdevbandwidthtest.c
+++ b/tests/virnetdevbandwidthtest.c
@@ -39,27 +39,26 @@ struct testSetStruct {
     const bool hierarchical_class;
 };
 
-#define PARSE(xml, var) \
-    do { \
-        int rc; \
-        g_autoptr(xmlDoc) doc = NULL; \
-        g_autoptr(xmlXPathContext) ctxt = NULL; \
- \
-        if (!xml) \
-            break; \
- \
-        if (!(doc = virXMLParseStringCtxt((xml), \
-                                          "bandwidth definition", \
-                                          &ctxt))) \
-            goto cleanup; \
- \
-        rc = virNetDevBandwidthParse(&(var), \
-                                     NULL, \
-                                     ctxt->node, \
-                                     true); \
-        if (rc < 0) \
-            goto cleanup; \
-    } while (0)
+static int
+testVirNetDevBandwidthParse(virNetDevBandwidth **var,
+                            const char *xml)
+{
+    g_autoptr(xmlDoc) doc = NULL;
+    g_autoptr(xmlXPathContext) ctxt = NULL;
+
+    if (!xml)
+        return 0;
+
+    if (!(doc = virXMLParseStringCtxt((xml),
+                                      "bandwidth definition",
+                                      &ctxt)))
+        return -1;
+
+    return virNetDevBandwidthParse(var,
+                                   NULL,
+                                   ctxt->node,
+                                   true);
+}
 
 static int
 testVirNetDevBandwidthSet(const void *data)
@@ -72,7 +71,8 @@ testVirNetDevBandwidthSet(const void *data)
     g_autofree char *actual_cmd = NULL;
     g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew();
 
-    PARSE(info->band, band);
+    if (testVirNetDevBandwidthParse(&band, info->band) < 0)
+        return -1;
 
     if (!iface)
         iface = "eth0";
diff --git a/tests/virnetdevopenvswitchtest.c b/tests/virnetdevopenvswitchtest.c
index 89ffc1e4b5..1026c890cd 100644
--- a/tests/virnetdevopenvswitchtest.c
+++ b/tests/virnetdevopenvswitchtest.c
@@ -45,27 +45,26 @@ struct testClearQosStruct {
     const unsigned char *vmid;
 };
 
-#define PARSE(xml, var) \
-    do { \
-        int rc; \
-        g_autoptr(xmlDoc) doc = NULL; \
-        g_autoptr(xmlXPathContext) ctxt = NULL; \
- \
-        if (!xml) \
-            break; \
- \
-        if (!(doc = virXMLParseStringCtxt((xml), \
-                                          "bandwidth definition", \
-                                          &ctxt))) \
-            goto cleanup; \
- \
-        rc = virNetDevBandwidthParse(&(var), \
-                                     NULL, \
-                                     ctxt->node, \
-                                     true); \
-        if (rc < 0) \
-            goto cleanup; \
-    } while (0)
+static int
+testVirNetDevBandwidthParse(virNetDevBandwidth **var,
+                            const char *xml)
+{
+    g_autoptr(xmlDoc) doc = NULL;
+    g_autoptr(xmlXPathContext) ctxt = NULL;
+
+    if (!xml)
+        return 0;
+
+    if (!(doc = virXMLParseStringCtxt((xml),
+                                      "bandwidth definition",
+                                      &ctxt)))
+        return -1;
+
+    return virNetDevBandwidthParse(var,
+                                   NULL,
+                                   ctxt->node,
+                                   true);
+}
 
 static const unsigned char vm_id[VIR_UUID_BUFLEN] = "fakeuuid";
 
@@ -161,7 +160,8 @@ testVirNetDevOpenvswitchInterfaceSetQos(const void *data)
     g_autofree char *actual_cmd = NULL;
     g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew();
 
-    PARSE(info->band, band);
+    if (testVirNetDevBandwidthParse(&band, info->band) < 0)
+        return -1;
 
     if (!iface)
         iface = "tap-fake";
-- 
2.31.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux