From: Peter Krempa Date: Tue, 25 Jul 2017 13:49:00 +0000 (+0200) Subject: tests: qemumonitorjson: simplify path handling in testBlockNodeNameDetect X-Git-Tag: v3.6.0-rc1~21 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e3b0eb5b1cfdb243931abe4a7b345b601268b04d;p=thirdparty%2Flibvirt.git tests: qemumonitorjson: simplify path handling in testBlockNodeNameDetect Extract the test prefix path into a variable and reuse virTestLoadFileJSON to load the sample json files rather than doing it manually. Reviewed-by: Eric Blake --- diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index 56a0a25e1d..268c15f4b6 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);