Extract the test prefix path into a variable and reuse virTestLoadFileJSON to load the sample json files rather than doing it manually. --- tests/qemumonitorjsontest.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index 56a0a25e1..268c15f4b 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -2736,8 +2736,7 @@ static int testBlockNodeNameDetect(const void *opaque) { const struct testBlockNodeNameDetectData *data = opaque; - char *namedNodesFile = NULL; - char *namedNodesStr = NULL; + const char *pathprefix = "qemumonitorjsondata/qemumonitorjson-nodename-"; char *resultFile = NULL; char *actual = NULL; char **nodenames = NULL; @@ -2747,21 +2746,15 @@ testBlockNodeNameDetect(const void *opaque) virBuffer buf = VIR_BUFFER_INITIALIZER; int ret = -1; - if (virAsprintf(&namedNodesFile, - "%s/qemumonitorjsondata/qemumonitorjson-nodename-%s-named-nodes.json", - abs_srcdir, data->name) < 0 || - virAsprintf(&resultFile, - "%s/qemumonitorjsondata/qemumonitorjson-nodename-%s.result", - abs_srcdir, data->name) < 0) + if (virAsprintf(&resultFile, "%s/%s%s.result", + abs_srcdir, pathprefix, data->name) < 0) goto cleanup; if (!(nodenames = virStringSplit(data->nodenames, ",", 0))) goto cleanup; - if (virTestLoadFile(namedNodesFile, &namedNodesStr) < 0) - goto cleanup; - - if (!(namedNodesJson = virJSONValueFromString(namedNodesStr))) + if (!(namedNodesJson = virTestLoadFileJSON(pathprefix, data->name, + "-named-nodes.json", NULL))) goto cleanup; if (!(nodedata = qemuBlockNodeNameGetBackingChain(namedNodesJson))) @@ -2783,9 +2776,7 @@ testBlockNodeNameDetect(const void *opaque) ret = 0; cleanup: - VIR_FREE(namedNodesFile); VIR_FREE(resultFile); - VIR_FREE(namedNodesStr); VIR_FREE(actual); virHashFree(nodedata); virStringListFree(nodenames); -- 2.13.2 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list