mirror of
https://github.com/libvirt/libvirt.git
synced 2025-01-08 07:03:19 -06:00
tests: introduce testVirNetDevBandwidthParse
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@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
3e74bb8321
commit
0846343861
@ -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";
|
||||
|
@ -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";
|
||||
|
Loading…
Reference in New Issue
Block a user