[libvirt] [PATCHv2 00/14] virjsontest: separate some tests into files

v1: cover.1549987014.git.jtomko@redhat.com v2: prettify output, use VIR_AUTO and better-looking commit messages Ján Tomko (14): virjsontest: switch AddAndRemove tests to work with files testJSONFromString: regroup if blocks virjsontest: reword error messages in testJSONFromString virjsontest: use VIR_AUTOPTR for virJSONValues virjsontest: use VIR_AUTOFREE for strings virjsontest: remove unnecessary cleanup labels virjsontest: introduce DO_TEST_PARSE_FILE virjsontest: switch DO_TEST_PARSE_FILE to use output files virjsontest: reformat add-remove test input data vvv--- squash into: json_reformat add-remove output data virjsontest: prettify AddRemove test virjsondata: json_reformat input data vvv SQUASH HERE: reformat parseFile output data virjsontest: prettify JSONFromFile test tests/virjsondata/add-remove-failure-in.json | 3 + tests/virjsondata/add-remove-success-in.json | 4 + tests/virjsondata/add-remove-success-out.json | 4 + tests/virjsondata/parse-Harder-in.json | 13 + tests/virjsondata/parse-Harder-out.json | 13 + tests/virjsondata/parse-NotSoSimple-in.json | 15 + tests/virjsondata/parse-NotSoSimple-out.json | 15 + tests/virjsondata/parse-Simple-in.json | 6 + tests/virjsondata/parse-Simple-out.json | 6 + tests/virjsondata/parse-VeryHard-in.json | 143 +++++++ tests/virjsondata/parse-VeryHard-out.json | 143 +++++++ tests/virjsontest.c | 370 ++++++++---------- 12 files changed, 531 insertions(+), 204 deletions(-) create mode 100644 tests/virjsondata/add-remove-failure-in.json create mode 100644 tests/virjsondata/add-remove-success-in.json create mode 100644 tests/virjsondata/add-remove-success-out.json create mode 100644 tests/virjsondata/parse-Harder-in.json create mode 100644 tests/virjsondata/parse-Harder-out.json create mode 100644 tests/virjsondata/parse-NotSoSimple-in.json create mode 100644 tests/virjsondata/parse-NotSoSimple-out.json create mode 100644 tests/virjsondata/parse-Simple-in.json create mode 100644 tests/virjsondata/parse-Simple-out.json create mode 100644 tests/virjsondata/parse-VeryHard-in.json create mode 100644 tests/virjsondata/parse-VeryHard-out.json -- 2.19.2

Instead of using JSON in C strings, put it in separate files for easier manipulation. Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Andrea Bolognani <abologna@redhat.com> --- tests/virjsondata/add-remove-failure-in.json | 1 + tests/virjsondata/add-remove-success-in.json | 1 + tests/virjsondata/add-remove-success-out.json | 1 + tests/virjsontest.c | 38 ++++++++++++------- 4 files changed, 27 insertions(+), 14 deletions(-) create mode 100644 tests/virjsondata/add-remove-failure-in.json create mode 100644 tests/virjsondata/add-remove-success-in.json create mode 100644 tests/virjsondata/add-remove-success-out.json diff --git a/tests/virjsondata/add-remove-failure-in.json b/tests/virjsondata/add-remove-failure-in.json new file mode 100644 index 0000000000..dd264421e9 --- /dev/null +++ b/tests/virjsondata/add-remove-failure-in.json @@ -0,0 +1 @@ +[ 1 ] diff --git a/tests/virjsondata/add-remove-success-in.json b/tests/virjsondata/add-remove-success-in.json new file mode 100644 index 0000000000..b8edd30963 --- /dev/null +++ b/tests/virjsondata/add-remove-success-in.json @@ -0,0 +1 @@ +{"name": "sample", "value": true} diff --git a/tests/virjsondata/add-remove-success-out.json b/tests/virjsondata/add-remove-success-out.json new file mode 100644 index 0000000000..9f1e44637c --- /dev/null +++ b/tests/virjsondata/add-remove-success-out.json @@ -0,0 +1 @@ +{"value":true,"newname":"foo"} diff --git a/tests/virjsontest.c b/tests/virjsontest.c index a4bd4fb07b..429eb58704 100644 --- a/tests/virjsontest.c +++ b/tests/virjsontest.c @@ -68,12 +68,24 @@ static int testJSONAddRemove(const void *data) { const struct testInfo *info = data; - virJSONValuePtr json; + virJSONValuePtr json = NULL; virJSONValuePtr name = NULL; - char *result = NULL; + char *infile = NULL; + char *indata = NULL; + char *outfile = NULL; + char *actual = NULL; int ret = -1; - json = virJSONValueFromString(info->doc); + if (virAsprintf(&infile, "%s/virjsondata/add-remove-%s-in.json", + abs_srcdir, info->name) < 0 || + virAsprintf(&outfile, "%s/virjsondata/add-remove-%s-out.json", + abs_srcdir, info->name) < 0) + goto cleanup; + + if (virTestLoadFile(infile, &indata) < 0) + goto cleanup; + + json = virJSONValueFromString(indata); if (!json) { VIR_TEST_VERBOSE("Fail to parse %s\n", info->name); ret = -1; @@ -113,20 +125,22 @@ testJSONAddRemove(const void *data) VIR_TEST_VERBOSE("%s", "unexpected failure adding new key\n"); goto cleanup; } - if (!(result = virJSONValueToString(json, false))) { + if (!(actual = virJSONValueToString(json, false))) { VIR_TEST_VERBOSE("%s", "failed to stringize result\n"); goto cleanup; } - if (STRNEQ(info->expect, result)) { - virTestDifference(stderr, info->expect, result); + if (virTestCompareToFile(actual, outfile) < 0) goto cleanup; - } + ret = 0; cleanup: virJSONValueFree(json); virJSONValueFree(name); - VIR_FREE(result); + VIR_FREE(infile); + VIR_FREE(indata); + VIR_FREE(outfile); + VIR_FREE(actual); return ret; } @@ -543,12 +557,8 @@ mymain(void) "\"query-uuid\"},{\"name\":\"query-migrate\"},{\"name\":" "\"query-balloon\"}],\"id\":\"libvirt-2\"}", NULL); - DO_TEST_FULL("add and remove", AddRemove, - "{\"name\": \"sample\", \"value\": true}", - "{\"value\":true,\"newname\":\"foo\"}", - true); - DO_TEST_FULL("add and remove", AddRemove, - "[ 1 ]", NULL, false); + DO_TEST_FULL("success", AddRemove, NULL, NULL, true); + DO_TEST_FULL("failure", AddRemove, NULL, NULL, false); DO_TEST_FULL("copy and free", Copy, "{\"return\": [{\"name\": \"quit\"}, {\"name\": \"eject\"}," -- 2.19.2

Handle failure to parse the JSON in an else branch for readability. Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/virjsontest.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/virjsontest.c b/tests/virjsontest.c index 429eb58704..3c4bb4141a 100644 --- a/tests/virjsontest.c +++ b/tests/virjsontest.c @@ -36,11 +36,11 @@ testJSONFromString(const void *data) ret = 0; goto cleanup; } - } - - if (!info->pass) { - VIR_TEST_VERBOSE("Should not have parsed %s\n", info->doc); - goto cleanup; + } else { + if (!info->pass) { + VIR_TEST_VERBOSE("Should not have parsed %s\n", info->name); + goto cleanup; + } } VIR_TEST_DEBUG("Parsed %s\n", info->doc); -- 2.19.2

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/virjsontest.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/virjsontest.c b/tests/virjsontest.c index 3c4bb4141a..51777ba770 100644 --- a/tests/virjsontest.c +++ b/tests/virjsontest.c @@ -29,16 +29,16 @@ testJSONFromString(const void *data) if (!json) { if (info->pass) { - VIR_TEST_VERBOSE("Fail to parse %s\n", info->doc); + VIR_TEST_VERBOSE("Failed to parse %s\n", info->doc); goto cleanup; } else { - VIR_TEST_DEBUG("Fail to parse %s\n", info->doc); + VIR_TEST_DEBUG("As expected, failed to parse %s\n", info->doc); ret = 0; goto cleanup; } } else { if (!info->pass) { - VIR_TEST_VERBOSE("Should not have parsed %s\n", info->name); + VIR_TEST_VERBOSE("Unexpected success while parsing %s\n", info->doc); goto cleanup; } } -- 2.19.2

On Tue, Apr 02, 2019 at 17:41:42 +0200, Ján Tomko wrote:
Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/virjsontest.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
ACK

Remove all explicit usage of virJSONValueFree. Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/virjsontest.c | 45 +++++++++++++++------------------------------ 1 file changed, 15 insertions(+), 30 deletions(-) diff --git a/tests/virjsontest.c b/tests/virjsontest.c index 51777ba770..bf2bb85c6c 100644 --- a/tests/virjsontest.c +++ b/tests/virjsontest.c @@ -20,7 +20,7 @@ static int testJSONFromString(const void *data) { const struct testInfo *info = data; - virJSONValuePtr json; + VIR_AUTOPTR(virJSONValue) json = NULL; const char *expectstr = info->expect ? info->expect : info->doc; char *formatted = NULL; int ret = -1; @@ -59,7 +59,6 @@ testJSONFromString(const void *data) cleanup: VIR_FREE(formatted); - virJSONValueFree(json); return ret; } @@ -68,8 +67,8 @@ static int testJSONAddRemove(const void *data) { const struct testInfo *info = data; - virJSONValuePtr json = NULL; - virJSONValuePtr name = NULL; + VIR_AUTOPTR(virJSONValue) json = NULL; + VIR_AUTOPTR(virJSONValue) name = NULL; char *infile = NULL; char *indata = NULL; char *outfile = NULL; @@ -135,8 +134,6 @@ testJSONAddRemove(const void *data) ret = 0; cleanup: - virJSONValueFree(json); - virJSONValueFree(name); VIR_FREE(infile); VIR_FREE(indata); VIR_FREE(outfile); @@ -149,7 +146,7 @@ static int testJSONLookup(const void *data) { const struct testInfo *info = data; - virJSONValuePtr json; + VIR_AUTOPTR(virJSONValue) json = NULL; virJSONValuePtr value = NULL; char *result = NULL; int rc; @@ -247,7 +244,6 @@ testJSONLookup(const void *data) ret = 0; cleanup: - virJSONValueFree(json); VIR_FREE(result); return ret; } @@ -257,8 +253,8 @@ static int testJSONCopy(const void *data) { const struct testInfo *info = data; - virJSONValuePtr json = NULL; - virJSONValuePtr jsonCopy = NULL; + VIR_AUTOPTR(virJSONValue) json = NULL; + VIR_AUTOPTR(virJSONValue) jsonCopy = NULL; char *result = NULL; char *resultCopy = NULL; int ret = -1; @@ -318,8 +314,6 @@ testJSONCopy(const void *data) cleanup: VIR_FREE(result); VIR_FREE(resultCopy); - virJSONValueFree(json); - virJSONValueFree(jsonCopy); return ret; } @@ -328,8 +322,8 @@ static int testJSONDeflatten(const void *data) { const struct testInfo *info = data; - virJSONValuePtr injson = NULL; - virJSONValuePtr deflattened = NULL; + VIR_AUTOPTR(virJSONValue) injson = NULL; + VIR_AUTOPTR(virJSONValue) deflattened = NULL; char *infile = NULL; char *indata = NULL; char *outfile = NULL; @@ -369,8 +363,6 @@ testJSONDeflatten(const void *data) ret = 0; cleanup: - virJSONValueFree(injson); - virJSONValueFree(deflattened); VIR_FREE(infile); VIR_FREE(indata); VIR_FREE(outfile); @@ -383,9 +375,9 @@ testJSONDeflatten(const void *data) static int testJSONEscapeObj(const void *data ATTRIBUTE_UNUSED) { - virJSONValuePtr json = NULL; - virJSONValuePtr nestjson = NULL; - virJSONValuePtr parsejson = NULL; + VIR_AUTOPTR(virJSONValue) json = NULL; + VIR_AUTOPTR(virJSONValue) nestjson = NULL; + VIR_AUTOPTR(virJSONValue) parsejson = NULL; char *neststr = NULL; char *result = NULL; const char *parsednestedstr; @@ -434,9 +426,6 @@ testJSONEscapeObj(const void *data ATTRIBUTE_UNUSED) cleanup: VIR_FREE(neststr); VIR_FREE(result); - virJSONValueFree(json); - virJSONValueFree(nestjson); - virJSONValueFree(parsejson); return ret; } @@ -444,10 +433,10 @@ testJSONEscapeObj(const void *data ATTRIBUTE_UNUSED) static int testJSONObjectFormatSteal(const void *opaque ATTRIBUTE_UNUSED) { - virJSONValuePtr a1 = NULL; - virJSONValuePtr a2 = NULL; - virJSONValuePtr t1 = NULL; - virJSONValuePtr t2 = NULL; + VIR_AUTOPTR(virJSONValue) a1 = NULL; + VIR_AUTOPTR(virJSONValue) a2 = NULL; + VIR_AUTOPTR(virJSONValue) t1 = NULL; + VIR_AUTOPTR(virJSONValue) t2 = NULL; int ret = -1; if (!(a1 = virJSONValueNewString("test")) || @@ -478,10 +467,6 @@ testJSONObjectFormatSteal(const void *opaque ATTRIBUTE_UNUSED) ret = 0; cleanup: - virJSONValueFree(a1); - virJSONValueFree(a2); - virJSONValueFree(t1); - virJSONValueFree(t2); return ret; } -- 2.19.2

The only remaining use of VIR_FREE is for reusing variables. Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/virjsontest.c | 42 ++++++++++++++---------------------------- 1 file changed, 14 insertions(+), 28 deletions(-) diff --git a/tests/virjsontest.c b/tests/virjsontest.c index bf2bb85c6c..12458878e0 100644 --- a/tests/virjsontest.c +++ b/tests/virjsontest.c @@ -22,7 +22,7 @@ testJSONFromString(const void *data) const struct testInfo *info = data; VIR_AUTOPTR(virJSONValue) json = NULL; const char *expectstr = info->expect ? info->expect : info->doc; - char *formatted = NULL; + VIR_AUTOFREE(char *) formatted = NULL; int ret = -1; json = virJSONValueFromString(info->doc); @@ -58,7 +58,6 @@ testJSONFromString(const void *data) ret = 0; cleanup: - VIR_FREE(formatted); return ret; } @@ -69,10 +68,10 @@ testJSONAddRemove(const void *data) const struct testInfo *info = data; VIR_AUTOPTR(virJSONValue) json = NULL; VIR_AUTOPTR(virJSONValue) name = NULL; - char *infile = NULL; - char *indata = NULL; - char *outfile = NULL; - char *actual = NULL; + VIR_AUTOFREE(char *) infile = NULL; + VIR_AUTOFREE(char *) indata = NULL; + VIR_AUTOFREE(char *) outfile = NULL; + VIR_AUTOFREE(char *) actual = NULL; int ret = -1; if (virAsprintf(&infile, "%s/virjsondata/add-remove-%s-in.json", @@ -134,10 +133,6 @@ testJSONAddRemove(const void *data) ret = 0; cleanup: - VIR_FREE(infile); - VIR_FREE(indata); - VIR_FREE(outfile); - VIR_FREE(actual); return ret; } @@ -148,7 +143,7 @@ testJSONLookup(const void *data) const struct testInfo *info = data; VIR_AUTOPTR(virJSONValue) json = NULL; virJSONValuePtr value = NULL; - char *result = NULL; + VIR_AUTOFREE(char *) result = NULL; int rc; int number; const char *str; @@ -244,7 +239,6 @@ testJSONLookup(const void *data) ret = 0; cleanup: - VIR_FREE(result); return ret; } @@ -255,8 +249,8 @@ testJSONCopy(const void *data) const struct testInfo *info = data; VIR_AUTOPTR(virJSONValue) json = NULL; VIR_AUTOPTR(virJSONValue) jsonCopy = NULL; - char *result = NULL; - char *resultCopy = NULL; + VIR_AUTOFREE(char *) result = NULL; + VIR_AUTOFREE(char *) resultCopy = NULL; int ret = -1; json = virJSONValueFromString(info->doc); @@ -312,8 +306,6 @@ testJSONCopy(const void *data) ret = 0; cleanup: - VIR_FREE(result); - VIR_FREE(resultCopy); return ret; } @@ -324,10 +316,10 @@ testJSONDeflatten(const void *data) const struct testInfo *info = data; VIR_AUTOPTR(virJSONValue) injson = NULL; VIR_AUTOPTR(virJSONValue) deflattened = NULL; - char *infile = NULL; - char *indata = NULL; - char *outfile = NULL; - char *actual = NULL; + VIR_AUTOFREE(char *) infile = NULL; + VIR_AUTOFREE(char *) indata = NULL; + VIR_AUTOFREE(char *) outfile = NULL; + VIR_AUTOFREE(char *) actual = NULL; int ret = -1; if (virAsprintf(&infile, "%s/virjsondata/deflatten-%s-in.json", @@ -363,10 +355,6 @@ testJSONDeflatten(const void *data) ret = 0; cleanup: - VIR_FREE(infile); - VIR_FREE(indata); - VIR_FREE(outfile); - VIR_FREE(actual); return ret; } @@ -378,8 +366,8 @@ testJSONEscapeObj(const void *data ATTRIBUTE_UNUSED) VIR_AUTOPTR(virJSONValue) json = NULL; VIR_AUTOPTR(virJSONValue) nestjson = NULL; VIR_AUTOPTR(virJSONValue) parsejson = NULL; - char *neststr = NULL; - char *result = NULL; + VIR_AUTOFREE(char *) neststr = NULL; + VIR_AUTOFREE(char *) result = NULL; const char *parsednestedstr; int ret = -1; @@ -424,8 +412,6 @@ testJSONEscapeObj(const void *data ATTRIBUTE_UNUSED) ret = 0; cleanup: - VIR_FREE(neststr); - VIR_FREE(result); return ret; } -- 2.19.2

On Tue, Apr 02, 2019 at 17:41:44 +0200, Ján Tomko wrote:
The only remaining use of VIR_FREE is for reusing variables.
Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/virjsontest.c | 42 ++++++++++++++---------------------------- 1 file changed, 14 insertions(+), 28 deletions(-)
diff --git a/tests/virjsontest.c b/tests/virjsontest.c index bf2bb85c6c..12458878e0 100644 --- a/tests/virjsontest.c +++ b/tests/virjsontest.c @@ -22,7 +22,7 @@ testJSONFromString(const void *data) const struct testInfo *info = data; VIR_AUTOPTR(virJSONValue) json = NULL; const char *expectstr = info->expect ? info->expect : info->doc; - char *formatted = NULL; + VIR_AUTOFREE(char *) formatted = NULL; int ret = -1;
json = virJSONValueFromString(info->doc); @@ -58,7 +58,6 @@ testJSONFromString(const void *data) ret = 0;
cleanup: - VIR_FREE(formatted); return ret; }
@@ -69,10 +68,10 @@ testJSONAddRemove(const void *data) const struct testInfo *info = data; VIR_AUTOPTR(virJSONValue) json = NULL; VIR_AUTOPTR(virJSONValue) name = NULL; - char *infile = NULL; - char *indata = NULL; - char *outfile = NULL; - char *actual = NULL; + VIR_AUTOFREE(char *) infile = NULL; + VIR_AUTOFREE(char *) indata = NULL; + VIR_AUTOFREE(char *) outfile = NULL; + VIR_AUTOFREE(char *) actual = NULL;
These were added in 1/n of this series. I've seen you had a R-b there but consider not changing recently added code.
int ret = -1;
if (virAsprintf(&infile, "%s/virjsondata/add-remove-%s-in.json",
ACK

Now that cleanup is handled automatically, we can use 'return' more often. Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/virjsontest.c | 160 ++++++++++++++++++-------------------------- 1 file changed, 65 insertions(+), 95 deletions(-) diff --git a/tests/virjsontest.c b/tests/virjsontest.c index 12458878e0..0825a87188 100644 --- a/tests/virjsontest.c +++ b/tests/virjsontest.c @@ -23,23 +23,21 @@ testJSONFromString(const void *data) VIR_AUTOPTR(virJSONValue) json = NULL; const char *expectstr = info->expect ? info->expect : info->doc; VIR_AUTOFREE(char *) formatted = NULL; - int ret = -1; json = virJSONValueFromString(info->doc); if (!json) { if (info->pass) { VIR_TEST_VERBOSE("Failed to parse %s\n", info->doc); - goto cleanup; + return -1; } else { VIR_TEST_DEBUG("As expected, failed to parse %s\n", info->doc); - ret = 0; - goto cleanup; + return 0; } } else { if (!info->pass) { VIR_TEST_VERBOSE("Unexpected success while parsing %s\n", info->doc); - goto cleanup; + return -1; } } @@ -47,18 +45,15 @@ testJSONFromString(const void *data) if (!(formatted = virJSONValueToString(json, false))) { VIR_TEST_VERBOSE("Failed to format json data\n"); - goto cleanup; + return -1; } if (STRNEQ(expectstr, formatted)) { virTestDifference(stderr, expectstr, formatted); - goto cleanup; + return -1; } - ret = 0; - - cleanup: - return ret; + return 0; } @@ -72,22 +67,20 @@ testJSONAddRemove(const void *data) VIR_AUTOFREE(char *) indata = NULL; VIR_AUTOFREE(char *) outfile = NULL; VIR_AUTOFREE(char *) actual = NULL; - int ret = -1; if (virAsprintf(&infile, "%s/virjsondata/add-remove-%s-in.json", abs_srcdir, info->name) < 0 || virAsprintf(&outfile, "%s/virjsondata/add-remove-%s-out.json", abs_srcdir, info->name) < 0) - goto cleanup; + return -1; if (virTestLoadFile(infile, &indata) < 0) - goto cleanup; + return -1; json = virJSONValueFromString(indata); if (!json) { VIR_TEST_VERBOSE("Fail to parse %s\n", info->name); - ret = -1; - goto cleanup; + return -1; } switch (virJSONValueObjectRemoveKey(json, "name", &name)) { @@ -95,45 +88,43 @@ testJSONAddRemove(const void *data) if (!info->pass) { VIR_TEST_VERBOSE("should not remove from non-object %s\n", info->name); - goto cleanup; + return -1; } break; case -1: if (!info->pass) - ret = 0; + return 0; else VIR_TEST_VERBOSE("Fail to recognize non-object %s\n", info->name); - goto cleanup; + return -1; default: VIR_TEST_VERBOSE("unexpected result when removing from %s\n", info->name); - goto cleanup; + return -1; } if (STRNEQ_NULLABLE(virJSONValueGetString(name), "sample")) { VIR_TEST_VERBOSE("unexpected value after removing name: %s\n", NULLSTR(virJSONValueGetString(name))); - goto cleanup; + return -1; } if (virJSONValueObjectRemoveKey(json, "name", NULL)) { VIR_TEST_VERBOSE("%s", "unexpected success when removing missing key\n"); - goto cleanup; + return -1; } if (virJSONValueObjectAppendString(json, "newname", "foo") < 0) { VIR_TEST_VERBOSE("%s", "unexpected failure adding new key\n"); - goto cleanup; + return -1; } if (!(actual = virJSONValueToString(json, false))) { VIR_TEST_VERBOSE("%s", "failed to stringize result\n"); - goto cleanup; + return -1; } - if (virTestCompareToFile(actual, outfile) < 0) - goto cleanup; - ret = 0; + if (virTestCompareToFile(actual, outfile) < 0) + return -1; - cleanup: - return ret; + return 0; } @@ -147,13 +138,11 @@ testJSONLookup(const void *data) int rc; int number; const char *str; - int ret = -1; json = virJSONValueFromString(info->doc); if (!json) { VIR_TEST_VERBOSE("Fail to parse %s\n", info->doc); - ret = -1; - goto cleanup; + return -1; } value = virJSONValueObjectGetObject(json, "a"); @@ -161,21 +150,21 @@ testJSONLookup(const void *data) if (!info->pass) { VIR_TEST_VERBOSE("lookup for 'a' in '%s' should have failed\n", info->doc); - goto cleanup; + return -1; } else { result = virJSONValueToString(value, false); if (STRNEQ_NULLABLE(result, "{}")) { VIR_TEST_VERBOSE("lookup for 'a' in '%s' found '%s' but " "should have found '{}'\n", info->doc, NULLSTR(result)); - goto cleanup; + return -1; } VIR_FREE(result); } } else if (info->pass) { VIR_TEST_VERBOSE("lookup for 'a' in '%s' should have succeeded\n", info->doc); - goto cleanup; + return -1; } number = 2; @@ -184,17 +173,17 @@ testJSONLookup(const void *data) if (!info->pass) { VIR_TEST_VERBOSE("lookup for 'b' in '%s' should have failed\n", info->doc); - goto cleanup; + return -1; } else if (number != 1) { VIR_TEST_VERBOSE("lookup for 'b' in '%s' found %d but " "should have found 1\n", info->doc, number); - goto cleanup; + return -1; } } else if (info->pass) { VIR_TEST_VERBOSE("lookup for 'b' in '%s' should have succeeded\n", info->doc); - goto cleanup; + return -1; } str = virJSONValueObjectGetString(json, "c"); @@ -202,16 +191,16 @@ testJSONLookup(const void *data) if (!info->pass) { VIR_TEST_VERBOSE("lookup for 'c' in '%s' should have failed\n", info->doc); - goto cleanup; + return -1; } else if (STRNEQ(str, "str")) { VIR_TEST_VERBOSE("lookup for 'c' in '%s' found '%s' but " "should have found 'str'\n", info->doc, str); - goto cleanup; + return -1; } } else if (info->pass) { VIR_TEST_VERBOSE("lookup for 'c' in '%s' should have succeeded\n", info->doc); - goto cleanup; + return -1; } value = virJSONValueObjectGetArray(json, "d"); @@ -219,27 +208,24 @@ testJSONLookup(const void *data) if (!info->pass) { VIR_TEST_VERBOSE("lookup for 'd' in '%s' should have failed\n", info->doc); - goto cleanup; + return -1; } else { result = virJSONValueToString(value, false); if (STRNEQ_NULLABLE(result, "[]")) { VIR_TEST_VERBOSE("lookup for 'd' in '%s' found '%s' but " "should have found '[]'\n", info->doc, NULLSTR(result)); - goto cleanup; + return -1; } VIR_FREE(result); } } else if (info->pass) { VIR_TEST_VERBOSE("lookup for 'd' in '%s' should have succeeded\n", info->doc); - goto cleanup; + return -1; } - ret = 0; - - cleanup: - return ret; + return 0; } @@ -251,36 +237,35 @@ testJSONCopy(const void *data) VIR_AUTOPTR(virJSONValue) jsonCopy = NULL; VIR_AUTOFREE(char *) result = NULL; VIR_AUTOFREE(char *) resultCopy = NULL; - int ret = -1; json = virJSONValueFromString(info->doc); if (!json) { VIR_TEST_VERBOSE("Failed to parse %s\n", info->doc); - goto cleanup; + return -1; } jsonCopy = virJSONValueCopy(json); if (!jsonCopy) { VIR_TEST_VERBOSE("Failed to copy JSON data\n"); - goto cleanup; + return -1; } result = virJSONValueToString(json, false); if (!result) { VIR_TEST_VERBOSE("Failed to format original JSON data\n"); - goto cleanup; + return -1; } resultCopy = virJSONValueToString(json, false); if (!resultCopy) { VIR_TEST_VERBOSE("Failed to format copied JSON data\n"); - goto cleanup; + return -1; } if (STRNEQ(result, resultCopy)) { if (virTestGetVerbose()) virTestDifference(stderr, result, resultCopy); - goto cleanup; + return -1; } VIR_FREE(result); @@ -289,24 +274,22 @@ testJSONCopy(const void *data) result = virJSONValueToString(json, true); if (!result) { VIR_TEST_VERBOSE("Failed to format original JSON data\n"); - goto cleanup; + return -1; } resultCopy = virJSONValueToString(json, true); if (!resultCopy) { VIR_TEST_VERBOSE("Failed to format copied JSON data\n"); - goto cleanup; + return -1; } if (STRNEQ(result, resultCopy)) { if (virTestGetVerbose()) virTestDifference(stderr, result, resultCopy); - goto cleanup; + return -1; } - ret = 0; - cleanup: - return ret; + return 0; } @@ -320,43 +303,38 @@ testJSONDeflatten(const void *data) VIR_AUTOFREE(char *) indata = NULL; VIR_AUTOFREE(char *) outfile = NULL; VIR_AUTOFREE(char *) actual = NULL; - int ret = -1; if (virAsprintf(&infile, "%s/virjsondata/deflatten-%s-in.json", abs_srcdir, info->name) < 0 || virAsprintf(&outfile, "%s/virjsondata/deflatten-%s-out.json", abs_srcdir, info->name) < 0) - goto cleanup; + return -1; if (virTestLoadFile(infile, &indata) < 0) - goto cleanup; + return -1; if (!(injson = virJSONValueFromString(indata))) - goto cleanup; + return -1; if ((deflattened = virJSONValueObjectDeflatten(injson))) { if (!info->pass) { VIR_TEST_VERBOSE("%s: deflattening should have failed\n", info->name); - goto cleanup; + return -1; } } else { if (!info->pass) - ret = 0; + return 0; - goto cleanup; + return -1; } if (!(actual = virJSONValueToString(deflattened, true))) - goto cleanup; + return -1; if (virTestCompareToFile(actual, outfile) < 0) - goto cleanup; + return -1; - ret = 0; - - cleanup: - - return ret; + return 0; } @@ -369,50 +347,46 @@ testJSONEscapeObj(const void *data ATTRIBUTE_UNUSED) VIR_AUTOFREE(char *) neststr = NULL; VIR_AUTOFREE(char *) result = NULL; const char *parsednestedstr; - int ret = -1; if (virJSONValueObjectCreate(&nestjson, "s:stringkey", "stringvalue", "i:numberkey", 1234, "b:booleankey", false, NULL) < 0) { VIR_TEST_VERBOSE("failed to create nested json object"); - goto cleanup; + return -1; } if (!(neststr = virJSONValueToString(nestjson, false))) { VIR_TEST_VERBOSE("failed to format nested json object"); - goto cleanup; + return -1; } if (virJSONValueObjectCreate(&json, "s:test", neststr, NULL) < 0) { VIR_TEST_VERBOSE("Failed to create json object"); - goto cleanup; + return -1; } if (!(result = virJSONValueToString(json, false))) { VIR_TEST_VERBOSE("Failed to format json object"); - goto cleanup; + return -1; } if (!(parsejson = virJSONValueFromString(result))) { VIR_TEST_VERBOSE("Failed to parse JSON with nested JSON in string"); - goto cleanup; + return -1; } if (!(parsednestedstr = virJSONValueObjectGetString(parsejson, "test"))) { VIR_TEST_VERBOSE("Failed to retrieve string containing nested json"); - goto cleanup; + return -1; } if (STRNEQ(parsednestedstr, neststr)) { virTestDifference(stderr, neststr, parsednestedstr); - goto cleanup; + return -1; } - ret = 0; - - cleanup: - return ret; + return 0; } @@ -423,7 +397,6 @@ testJSONObjectFormatSteal(const void *opaque ATTRIBUTE_UNUSED) VIR_AUTOPTR(virJSONValue) a2 = NULL; VIR_AUTOPTR(virJSONValue) t1 = NULL; VIR_AUTOPTR(virJSONValue) t2 = NULL; - int ret = -1; if (!(a1 = virJSONValueNewString("test")) || !(a2 = virJSONValueNewString("test"))) { @@ -432,28 +405,25 @@ testJSONObjectFormatSteal(const void *opaque ATTRIBUTE_UNUSED) if (virJSONValueObjectCreate(&t1, "a:t", &a1, "s:f", NULL, NULL) != -1) { VIR_TEST_VERBOSE("virJSONValueObjectCreate(t1) should have failed\n"); - goto cleanup; + return -1; } if (a1) { VIR_TEST_VERBOSE("appended object a1 was not consumed\n"); - goto cleanup; + return -1; } if (virJSONValueObjectCreate(&t2, "s:f", NULL, "a:t", &a1, NULL) != -1) { VIR_TEST_VERBOSE("virJSONValueObjectCreate(t2) should have failed\n"); - goto cleanup; + return -1; } if (!a2) { VIR_TEST_VERBOSE("appended object a2 was consumed\n"); - goto cleanup; + return -1; } - ret = 0; - - cleanup: - return ret; + return 0; } -- 2.19.2

On Tue, Apr 02, 2019 at 17:41:45 +0200, Ján Tomko wrote:
Now that cleanup is handled automatically, we can use 'return' more often.
Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/virjsontest.c | 160 ++++++++++++++++++-------------------------- 1 file changed, 65 insertions(+), 95 deletions(-)
ACK

Introduce a new macro DO_TEST_PARSE_FILE which takes the input JSON from a file instead of a C string. This lets us get rid of quote escaping and makes the JSON easier to edit. The output JSON is still taken from a string and will be moved separately. Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/virjsondata/parse-Harder-in.json | 4 + tests/virjsondata/parse-NotSoSimple-in.json | 3 + tests/virjsondata/parse-Simple-in.json | 1 + tests/virjsondata/parse-VeryHard-in.json | 24 ++++ tests/virjsontest.c | 129 +++++++++++++------- 5 files changed, 118 insertions(+), 43 deletions(-) create mode 100644 tests/virjsondata/parse-Harder-in.json create mode 100644 tests/virjsondata/parse-NotSoSimple-in.json create mode 100644 tests/virjsondata/parse-Simple-in.json create mode 100644 tests/virjsondata/parse-VeryHard-in.json diff --git a/tests/virjsondata/parse-Harder-in.json b/tests/virjsondata/parse-Harder-in.json new file mode 100644 index 0000000000..739d780fb9 --- /dev/null +++ b/tests/virjsondata/parse-Harder-in.json @@ -0,0 +1,4 @@ +{"return": [{"filename": \ +"unix:/home/berrange/.libvirt/qemu/lib/tck.monitor,server",\ +"label": "charmonitor"}, {"filename": "pty:/dev/pts/158",\ +"label": "charserial0"}], "id": "libvirt-3"} diff --git a/tests/virjsondata/parse-NotSoSimple-in.json b/tests/virjsondata/parse-NotSoSimple-in.json new file mode 100644 index 0000000000..bda5fd1c3f --- /dev/null +++ b/tests/virjsondata/parse-NotSoSimple-in.json @@ -0,0 +1,3 @@ +{"QMP": {"version": {"qemu":\ +{"micro": 91, "minor": 13, "major": 0},\ +"package": " (qemu-kvm-devel)"}, "capabilities": []}} diff --git a/tests/virjsondata/parse-Simple-in.json b/tests/virjsondata/parse-Simple-in.json new file mode 100644 index 0000000000..a40724b322 --- /dev/null +++ b/tests/virjsondata/parse-Simple-in.json @@ -0,0 +1 @@ +{"return": {}, "id": "libvirt-1"} diff --git a/tests/virjsondata/parse-VeryHard-in.json b/tests/virjsondata/parse-VeryHard-in.json new file mode 100644 index 0000000000..e10d605950 --- /dev/null +++ b/tests/virjsondata/parse-VeryHard-in.json @@ -0,0 +1,24 @@ +{"return":[{"name":"quit"},{"name":\ +"eject"},{"name":"change"},{"name":"screendump"},\ +{"name":"stop"},{"name":"cont"},{"name":\ +"system_reset"},{"name":"system_powerdown"},\ +{"name":"device_add"},{"name":"device_del"},\ +{"name":"cpu"},{"name":"memsave"},{"name":\ +"pmemsave"},{"name":"migrate"},{"name":\ +"migrate_cancel"},{"name":"migrate_set_speed"},\ +{"name":"client_migrate_info"},{"name":\ +"migrate_set_downtime"},{"name":"netdev_add"},\ +{"name":"netdev_del"},{"name":"block_resize"},\ +{"name":"balloon"},{"name":"set_link"},{"name":\ +"getfd"},{"name":"closefd"},{"name":"block_passwd"},\ +{"name":"set_password"},{"name":"expire_password"},\ +{"name":"qmp_capabilities"},{"name":\ +"human-monitor-command"},{"name":"query-version"},\ +{"name":"query-commands"},{"name":"query-chardev"},\ +{"name":"query-block"},{"name":"query-blockstats"},\ +{"name":"query-cpus"},{"name":"query-pci"},{"name":\ +"query-kvm"},{"name":"query-status"},{"name":\ +"query-mice"},{"name":"query-vnc"},{"name":\ +"query-spice"},{"name":"query-name"},{"name":\ +"query-uuid"},{"name":"query-migrate"},{"name":\ +"query-balloon"}],"id":"libvirt-2"} diff --git a/tests/virjsontest.c b/tests/virjsontest.c index 0825a87188..262fcebca6 100644 --- a/tests/virjsontest.c +++ b/tests/virjsontest.c @@ -16,6 +16,51 @@ struct testInfo { }; +static int +testJSONFromFile(const void *data) +{ + const struct testInfo *info = data; + VIR_AUTOPTR(virJSONValue) injson = NULL; + VIR_AUTOFREE(char *) infile = NULL; + VIR_AUTOFREE(char *) indata = NULL; + VIR_AUTOFREE(char *) actual = NULL; + + if (virAsprintf(&infile, "%s/virjsondata/parse-%s-in.json", + abs_srcdir, info->name) < 0) + return -1; + + if (virTestLoadFile(infile, &indata) < 0) + return -1; + + injson = virJSONValueFromString(indata); + + if (!injson) { + if (info->pass) { + VIR_TEST_VERBOSE("Failed to parse %s\n", info->doc); + return -1; + } else { + VIR_TEST_DEBUG("As expected, failed to parse %s\n", info->doc); + return 0; + } + } else { + if (!info->pass) { + VIR_TEST_VERBOSE("Unexpected success while parsing %s\n", info->doc); + return -1; + } + } + + if (!(actual = virJSONValueToString(injson, false))) + return -1; + + if (STRNEQ(info->expect, actual)) { + virTestDifference(stderr, info->expect, actual); + return -1; + } + + return 0; +} + + static int testJSONFromString(const void *data) { @@ -454,49 +499,47 @@ mymain(void) #define DO_TEST_PARSE_FAIL(name, doc) \ DO_TEST_FULL(name, FromString, doc, NULL, false) - - DO_TEST_PARSE("Simple", "{\"return\": {}, \"id\": \"libvirt-1\"}", - "{\"return\":{},\"id\":\"libvirt-1\"}"); - DO_TEST_PARSE("NotSoSimple", "{\"QMP\": {\"version\": {\"qemu\":" - "{\"micro\": 91, \"minor\": 13, \"major\": 0}," - "\"package\": \" (qemu-kvm-devel)\"}, \"capabilities\": []}}", - "{\"QMP\":{\"version\":{\"qemu\":" - "{\"micro\":91,\"minor\":13,\"major\":0}," - "\"package\":\" (qemu-kvm-devel)\"},\"capabilities\":[]}}"); - - DO_TEST_PARSE("Harder", "{\"return\": [{\"filename\": " - "\"unix:/home/berrange/.libvirt/qemu/lib/tck.monitor,server\"," - "\"label\": \"charmonitor\"}, {\"filename\": \"pty:/dev/pts/158\"," - "\"label\": \"charserial0\"}], \"id\": \"libvirt-3\"}", - "{\"return\":[{\"filename\":" - "\"unix:/home/berrange/.libvirt/qemu/lib/tck.monitor,server\"," - "\"label\":\"charmonitor\"},{\"filename\":\"pty:/dev/pts/158\"," - "\"label\":\"charserial0\"}],\"id\":\"libvirt-3\"}"); - - DO_TEST_PARSE("VeryHard", "{\"return\":[{\"name\":\"quit\"},{\"name\":" - "\"eject\"},{\"name\":\"change\"},{\"name\":\"screendump\"}," - "{\"name\":\"stop\"},{\"name\":\"cont\"},{\"name\":" - "\"system_reset\"},{\"name\":\"system_powerdown\"}," - "{\"name\":\"device_add\"},{\"name\":\"device_del\"}," - "{\"name\":\"cpu\"},{\"name\":\"memsave\"},{\"name\":" - "\"pmemsave\"},{\"name\":\"migrate\"},{\"name\":" - "\"migrate_cancel\"},{\"name\":\"migrate_set_speed\"}," - "{\"name\":\"client_migrate_info\"},{\"name\":" - "\"migrate_set_downtime\"},{\"name\":\"netdev_add\"}," - "{\"name\":\"netdev_del\"},{\"name\":\"block_resize\"}," - "{\"name\":\"balloon\"},{\"name\":\"set_link\"},{\"name\":" - "\"getfd\"},{\"name\":\"closefd\"},{\"name\":\"block_passwd\"}," - "{\"name\":\"set_password\"},{\"name\":\"expire_password\"}," - "{\"name\":\"qmp_capabilities\"},{\"name\":" - "\"human-monitor-command\"},{\"name\":\"query-version\"}," - "{\"name\":\"query-commands\"},{\"name\":\"query-chardev\"}," - "{\"name\":\"query-block\"},{\"name\":\"query-blockstats\"}," - "{\"name\":\"query-cpus\"},{\"name\":\"query-pci\"},{\"name\":" - "\"query-kvm\"},{\"name\":\"query-status\"},{\"name\":" - "\"query-mice\"},{\"name\":\"query-vnc\"},{\"name\":" - "\"query-spice\"},{\"name\":\"query-name\"},{\"name\":" - "\"query-uuid\"},{\"name\":\"query-migrate\"},{\"name\":" - "\"query-balloon\"}],\"id\":\"libvirt-2\"}", NULL); +#define DO_TEST_PARSE_FILE(name, expect) \ + DO_TEST_FULL(name, FromFile, NULL, expect, true) + + + DO_TEST_PARSE_FILE("Simple", + "{\"return\":{},\"id\":\"libvirt-1\"}"); + DO_TEST_PARSE_FILE("NotSoSimple", + "{\"QMP\":{\"version\":{\"qemu\":" + "{\"micro\":91,\"minor\":13,\"major\":0}," + "\"package\":\" (qemu-kvm-devel)\"},\"capabilities\":[]}}"); + + DO_TEST_PARSE_FILE("Harder", + "{\"return\":[{\"filename\":" + "\"unix:/home/berrange/.libvirt/qemu/lib/tck.monitor,server\"," + "\"label\":\"charmonitor\"},{\"filename\":\"pty:/dev/pts/158\"," + "\"label\":\"charserial0\"}],\"id\":\"libvirt-3\"}"); + + DO_TEST_PARSE_FILE("VeryHard", "{\"return\":[{\"name\":\"quit\"},{\"name\":" + "\"eject\"},{\"name\":\"change\"},{\"name\":\"screendump\"}," + "{\"name\":\"stop\"},{\"name\":\"cont\"},{\"name\":" + "\"system_reset\"},{\"name\":\"system_powerdown\"}," + "{\"name\":\"device_add\"},{\"name\":\"device_del\"}," + "{\"name\":\"cpu\"},{\"name\":\"memsave\"},{\"name\":" + "\"pmemsave\"},{\"name\":\"migrate\"},{\"name\":" + "\"migrate_cancel\"},{\"name\":\"migrate_set_speed\"}," + "{\"name\":\"client_migrate_info\"},{\"name\":" + "\"migrate_set_downtime\"},{\"name\":\"netdev_add\"}," + "{\"name\":\"netdev_del\"},{\"name\":\"block_resize\"}," + "{\"name\":\"balloon\"},{\"name\":\"set_link\"},{\"name\":" + "\"getfd\"},{\"name\":\"closefd\"},{\"name\":\"block_passwd\"}," + "{\"name\":\"set_password\"},{\"name\":\"expire_password\"}," + "{\"name\":\"qmp_capabilities\"},{\"name\":" + "\"human-monitor-command\"},{\"name\":\"query-version\"}," + "{\"name\":\"query-commands\"},{\"name\":\"query-chardev\"}," + "{\"name\":\"query-block\"},{\"name\":\"query-blockstats\"}," + "{\"name\":\"query-cpus\"},{\"name\":\"query-pci\"},{\"name\":" + "\"query-kvm\"},{\"name\":\"query-status\"},{\"name\":" + "\"query-mice\"},{\"name\":\"query-vnc\"},{\"name\":" + "\"query-spice\"},{\"name\":\"query-name\"},{\"name\":" + "\"query-uuid\"},{\"name\":\"query-migrate\"},{\"name\":" + "\"query-balloon\"}],\"id\":\"libvirt-2\"}"); DO_TEST_FULL("success", AddRemove, NULL, NULL, true); DO_TEST_FULL("failure", AddRemove, NULL, NULL, false); -- 2.19.2

On Tue, Apr 02, 2019 at 17:41:46 +0200, Ján Tomko wrote:
Introduce a new macro DO_TEST_PARSE_FILE which takes the input JSON from a file instead of a C string.
This lets us get rid of quote escaping and makes the JSON easier to edit.
The output JSON is still taken from a string and will be moved separately.
Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/virjsondata/parse-Harder-in.json | 4 + tests/virjsondata/parse-NotSoSimple-in.json | 3 + tests/virjsondata/parse-Simple-in.json | 1 + tests/virjsondata/parse-VeryHard-in.json | 24 ++++ tests/virjsontest.c | 129 +++++++++++++------- 5 files changed, 118 insertions(+), 43 deletions(-) create mode 100644 tests/virjsondata/parse-Harder-in.json create mode 100644 tests/virjsondata/parse-NotSoSimple-in.json create mode 100644 tests/virjsondata/parse-Simple-in.json create mode 100644 tests/virjsondata/parse-VeryHard-in.json
ACK

Also switch the expected output of DO_TEST_PARSE_FILE to be in a file, now that we demonstrated the input files match the expected string representation. Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/virjsondata/parse-Harder-out.json | 4 ++ tests/virjsondata/parse-NotSoSimple-out.json | 3 ++ tests/virjsondata/parse-Simple-out.json | 1 + tests/virjsondata/parse-VeryHard-out.json | 24 +++++++++ tests/virjsontest.c | 56 +++++--------------- 5 files changed, 44 insertions(+), 44 deletions(-) create mode 100644 tests/virjsondata/parse-Harder-out.json create mode 100644 tests/virjsondata/parse-NotSoSimple-out.json create mode 100644 tests/virjsondata/parse-Simple-out.json create mode 100644 tests/virjsondata/parse-VeryHard-out.json diff --git a/tests/virjsondata/parse-Harder-out.json b/tests/virjsondata/parse-Harder-out.json new file mode 100644 index 0000000000..31b3edd731 --- /dev/null +++ b/tests/virjsondata/parse-Harder-out.json @@ -0,0 +1,4 @@ +{"return":[{"filename":\ +"unix:/home/berrange/.libvirt/qemu/lib/tck.monitor,server",\ +"label":"charmonitor"},{"filename":"pty:/dev/pts/158",\ +"label":"charserial0"}],"id":"libvirt-3"} diff --git a/tests/virjsondata/parse-NotSoSimple-out.json b/tests/virjsondata/parse-NotSoSimple-out.json new file mode 100644 index 0000000000..e679cd1813 --- /dev/null +++ b/tests/virjsondata/parse-NotSoSimple-out.json @@ -0,0 +1,3 @@ +{"QMP":{"version":{"qemu":\ +{"micro":91,"minor":13,"major":0},\ +"package":" (qemu-kvm-devel)"},"capabilities":[]}} diff --git a/tests/virjsondata/parse-Simple-out.json b/tests/virjsondata/parse-Simple-out.json new file mode 100644 index 0000000000..c6e85e1ceb --- /dev/null +++ b/tests/virjsondata/parse-Simple-out.json @@ -0,0 +1 @@ +{"return":{},"id":"libvirt-1"} diff --git a/tests/virjsondata/parse-VeryHard-out.json b/tests/virjsondata/parse-VeryHard-out.json new file mode 100644 index 0000000000..e10d605950 --- /dev/null +++ b/tests/virjsondata/parse-VeryHard-out.json @@ -0,0 +1,24 @@ +{"return":[{"name":"quit"},{"name":\ +"eject"},{"name":"change"},{"name":"screendump"},\ +{"name":"stop"},{"name":"cont"},{"name":\ +"system_reset"},{"name":"system_powerdown"},\ +{"name":"device_add"},{"name":"device_del"},\ +{"name":"cpu"},{"name":"memsave"},{"name":\ +"pmemsave"},{"name":"migrate"},{"name":\ +"migrate_cancel"},{"name":"migrate_set_speed"},\ +{"name":"client_migrate_info"},{"name":\ +"migrate_set_downtime"},{"name":"netdev_add"},\ +{"name":"netdev_del"},{"name":"block_resize"},\ +{"name":"balloon"},{"name":"set_link"},{"name":\ +"getfd"},{"name":"closefd"},{"name":"block_passwd"},\ +{"name":"set_password"},{"name":"expire_password"},\ +{"name":"qmp_capabilities"},{"name":\ +"human-monitor-command"},{"name":"query-version"},\ +{"name":"query-commands"},{"name":"query-chardev"},\ +{"name":"query-block"},{"name":"query-blockstats"},\ +{"name":"query-cpus"},{"name":"query-pci"},{"name":\ +"query-kvm"},{"name":"query-status"},{"name":\ +"query-mice"},{"name":"query-vnc"},{"name":\ +"query-spice"},{"name":"query-name"},{"name":\ +"query-uuid"},{"name":"query-migrate"},{"name":\ +"query-balloon"}],"id":"libvirt-2"} diff --git a/tests/virjsontest.c b/tests/virjsontest.c index 262fcebca6..4241acd911 100644 --- a/tests/virjsontest.c +++ b/tests/virjsontest.c @@ -23,9 +23,12 @@ testJSONFromFile(const void *data) VIR_AUTOPTR(virJSONValue) injson = NULL; VIR_AUTOFREE(char *) infile = NULL; VIR_AUTOFREE(char *) indata = NULL; + VIR_AUTOFREE(char *) outfile = NULL; VIR_AUTOFREE(char *) actual = NULL; if (virAsprintf(&infile, "%s/virjsondata/parse-%s-in.json", + abs_srcdir, info->name) < 0 || + virAsprintf(&outfile, "%s/virjsondata/parse-%s-out.json", abs_srcdir, info->name) < 0) return -1; @@ -52,10 +55,8 @@ testJSONFromFile(const void *data) if (!(actual = virJSONValueToString(injson, false))) return -1; - if (STRNEQ(info->expect, actual)) { - virTestDifference(stderr, info->expect, actual); + if (virTestCompareToFile(actual, outfile) < 0) return -1; - } return 0; } @@ -499,47 +500,14 @@ mymain(void) #define DO_TEST_PARSE_FAIL(name, doc) \ DO_TEST_FULL(name, FromString, doc, NULL, false) -#define DO_TEST_PARSE_FILE(name, expect) \ - DO_TEST_FULL(name, FromFile, NULL, expect, true) - - - DO_TEST_PARSE_FILE("Simple", - "{\"return\":{},\"id\":\"libvirt-1\"}"); - DO_TEST_PARSE_FILE("NotSoSimple", - "{\"QMP\":{\"version\":{\"qemu\":" - "{\"micro\":91,\"minor\":13,\"major\":0}," - "\"package\":\" (qemu-kvm-devel)\"},\"capabilities\":[]}}"); - - DO_TEST_PARSE_FILE("Harder", - "{\"return\":[{\"filename\":" - "\"unix:/home/berrange/.libvirt/qemu/lib/tck.monitor,server\"," - "\"label\":\"charmonitor\"},{\"filename\":\"pty:/dev/pts/158\"," - "\"label\":\"charserial0\"}],\"id\":\"libvirt-3\"}"); - - DO_TEST_PARSE_FILE("VeryHard", "{\"return\":[{\"name\":\"quit\"},{\"name\":" - "\"eject\"},{\"name\":\"change\"},{\"name\":\"screendump\"}," - "{\"name\":\"stop\"},{\"name\":\"cont\"},{\"name\":" - "\"system_reset\"},{\"name\":\"system_powerdown\"}," - "{\"name\":\"device_add\"},{\"name\":\"device_del\"}," - "{\"name\":\"cpu\"},{\"name\":\"memsave\"},{\"name\":" - "\"pmemsave\"},{\"name\":\"migrate\"},{\"name\":" - "\"migrate_cancel\"},{\"name\":\"migrate_set_speed\"}," - "{\"name\":\"client_migrate_info\"},{\"name\":" - "\"migrate_set_downtime\"},{\"name\":\"netdev_add\"}," - "{\"name\":\"netdev_del\"},{\"name\":\"block_resize\"}," - "{\"name\":\"balloon\"},{\"name\":\"set_link\"},{\"name\":" - "\"getfd\"},{\"name\":\"closefd\"},{\"name\":\"block_passwd\"}," - "{\"name\":\"set_password\"},{\"name\":\"expire_password\"}," - "{\"name\":\"qmp_capabilities\"},{\"name\":" - "\"human-monitor-command\"},{\"name\":\"query-version\"}," - "{\"name\":\"query-commands\"},{\"name\":\"query-chardev\"}," - "{\"name\":\"query-block\"},{\"name\":\"query-blockstats\"}," - "{\"name\":\"query-cpus\"},{\"name\":\"query-pci\"},{\"name\":" - "\"query-kvm\"},{\"name\":\"query-status\"},{\"name\":" - "\"query-mice\"},{\"name\":\"query-vnc\"},{\"name\":" - "\"query-spice\"},{\"name\":\"query-name\"},{\"name\":" - "\"query-uuid\"},{\"name\":\"query-migrate\"},{\"name\":" - "\"query-balloon\"}],\"id\":\"libvirt-2\"}"); +#define DO_TEST_PARSE_FILE(name) \ + DO_TEST_FULL(name, FromFile, NULL, NULL, true) + + + DO_TEST_PARSE_FILE("Simple"); + DO_TEST_PARSE_FILE("NotSoSimple"); + DO_TEST_PARSE_FILE("Harder"); + DO_TEST_PARSE_FILE("VeryHard"); DO_TEST_FULL("success", AddRemove, NULL, NULL, true); DO_TEST_FULL("failure", AddRemove, NULL, NULL, false); -- 2.19.2

On Tue, Apr 02, 2019 at 17:41:47 +0200, Ján Tomko wrote:
Also switch the expected output of DO_TEST_PARSE_FILE to be in a file, now that we demonstrated the input files match the expected string representation.
Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/virjsondata/parse-Harder-out.json | 4 ++ tests/virjsondata/parse-NotSoSimple-out.json | 3 ++ tests/virjsondata/parse-Simple-out.json | 1 + tests/virjsondata/parse-VeryHard-out.json | 24 +++++++++ tests/virjsontest.c | 56 +++++--------------- 5 files changed, 44 insertions(+), 44 deletions(-) create mode 100644 tests/virjsondata/parse-Harder-out.json create mode 100644 tests/virjsondata/parse-NotSoSimple-out.json create mode 100644 tests/virjsondata/parse-Simple-out.json create mode 100644 tests/virjsondata/parse-VeryHard-out.json
ACK

Use json_reformat to make the input more readable. Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/virjsondata/add-remove-failure-in.json | 4 +++- tests/virjsondata/add-remove-success-in.json | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/virjsondata/add-remove-failure-in.json b/tests/virjsondata/add-remove-failure-in.json index dd264421e9..7622214cf2 100644 --- a/tests/virjsondata/add-remove-failure-in.json +++ b/tests/virjsondata/add-remove-failure-in.json @@ -1 +1,3 @@ -[ 1 ] +[ + 1 +] diff --git a/tests/virjsondata/add-remove-success-in.json b/tests/virjsondata/add-remove-success-in.json index b8edd30963..bdc86185c6 100644 --- a/tests/virjsondata/add-remove-success-in.json +++ b/tests/virjsondata/add-remove-success-in.json @@ -1 +1,4 @@ -{"name": "sample", "value": true} +{ + "name": "sample", + "value": true +} -- 2.19.2

--- tests/virjsondata/add-remove-success-out.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/virjsondata/add-remove-success-out.json b/tests/virjsondata/add-remove-success-out.json index 9f1e44637c..50f1770910 100644 --- a/tests/virjsondata/add-remove-success-out.json +++ b/tests/virjsondata/add-remove-success-out.json @@ -1 +1,4 @@ -{"value":true,"newname":"foo"} +{ + "value": true, + "newname": "foo" +} -- 2.19.2

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/virjsondata/add-remove-success-out.json | 4 ++-- tests/virjsontest.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/virjsondata/add-remove-success-out.json b/tests/virjsondata/add-remove-success-out.json index 50f1770910..24ccb3e38c 100644 --- a/tests/virjsondata/add-remove-success-out.json +++ b/tests/virjsondata/add-remove-success-out.json @@ -1,4 +1,4 @@ { - "value": true, - "newname": "foo" + "value": true, + "newname": "foo" } diff --git a/tests/virjsontest.c b/tests/virjsontest.c index 4241acd911..4a33aff785 100644 --- a/tests/virjsontest.c +++ b/tests/virjsontest.c @@ -162,7 +162,7 @@ testJSONAddRemove(const void *data) VIR_TEST_VERBOSE("%s", "unexpected failure adding new key\n"); return -1; } - if (!(actual = virJSONValueToString(json, false))) { + if (!(actual = virJSONValueToString(json, true))) { VIR_TEST_VERBOSE("%s", "failed to stringize result\n"); return -1; } -- 2.19.2

Remove trailing slashes and run json_reformat. Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/virjsondata/parse-Harder-in.json | 17 +- tests/virjsondata/parse-NotSoSimple-in.json | 18 ++- tests/virjsondata/parse-Simple-in.json | 7 +- tests/virjsondata/parse-VeryHard-in.json | 167 +++++++++++++++++--- 4 files changed, 177 insertions(+), 32 deletions(-) diff --git a/tests/virjsondata/parse-Harder-in.json b/tests/virjsondata/parse-Harder-in.json index 739d780fb9..1cdac1f0c9 100644 --- a/tests/virjsondata/parse-Harder-in.json +++ b/tests/virjsondata/parse-Harder-in.json @@ -1,4 +1,13 @@ -{"return": [{"filename": \ -"unix:/home/berrange/.libvirt/qemu/lib/tck.monitor,server",\ -"label": "charmonitor"}, {"filename": "pty:/dev/pts/158",\ -"label": "charserial0"}], "id": "libvirt-3"} +{ + "return": [ + { + "filename": "unix:/home/berrange/.libvirt/qemu/lib/tck.monitor,server", + "label": "charmonitor" + }, + { + "filename": "pty:/dev/pts/158", + "label": "charserial0" + } + ], + "id": "libvirt-3" +} diff --git a/tests/virjsondata/parse-NotSoSimple-in.json b/tests/virjsondata/parse-NotSoSimple-in.json index bda5fd1c3f..c6553b74af 100644 --- a/tests/virjsondata/parse-NotSoSimple-in.json +++ b/tests/virjsondata/parse-NotSoSimple-in.json @@ -1,3 +1,15 @@ -{"QMP": {"version": {"qemu":\ -{"micro": 91, "minor": 13, "major": 0},\ -"package": " (qemu-kvm-devel)"}, "capabilities": []}} +{ + "QMP": { + "version": { + "qemu": { + "micro": 91, + "minor": 13, + "major": 0 + }, + "package": " (qemu-kvm-devel)" + }, + "capabilities": [ + + ] + } +} diff --git a/tests/virjsondata/parse-Simple-in.json b/tests/virjsondata/parse-Simple-in.json index a40724b322..167bdccdf8 100644 --- a/tests/virjsondata/parse-Simple-in.json +++ b/tests/virjsondata/parse-Simple-in.json @@ -1 +1,6 @@ -{"return": {}, "id": "libvirt-1"} +{ + "return": { + + }, + "id": "libvirt-1" +} diff --git a/tests/virjsondata/parse-VeryHard-in.json b/tests/virjsondata/parse-VeryHard-in.json index e10d605950..dc64fc1661 100644 --- a/tests/virjsondata/parse-VeryHard-in.json +++ b/tests/virjsondata/parse-VeryHard-in.json @@ -1,24 +1,143 @@ -{"return":[{"name":"quit"},{"name":\ -"eject"},{"name":"change"},{"name":"screendump"},\ -{"name":"stop"},{"name":"cont"},{"name":\ -"system_reset"},{"name":"system_powerdown"},\ -{"name":"device_add"},{"name":"device_del"},\ -{"name":"cpu"},{"name":"memsave"},{"name":\ -"pmemsave"},{"name":"migrate"},{"name":\ -"migrate_cancel"},{"name":"migrate_set_speed"},\ -{"name":"client_migrate_info"},{"name":\ -"migrate_set_downtime"},{"name":"netdev_add"},\ -{"name":"netdev_del"},{"name":"block_resize"},\ -{"name":"balloon"},{"name":"set_link"},{"name":\ -"getfd"},{"name":"closefd"},{"name":"block_passwd"},\ -{"name":"set_password"},{"name":"expire_password"},\ -{"name":"qmp_capabilities"},{"name":\ -"human-monitor-command"},{"name":"query-version"},\ -{"name":"query-commands"},{"name":"query-chardev"},\ -{"name":"query-block"},{"name":"query-blockstats"},\ -{"name":"query-cpus"},{"name":"query-pci"},{"name":\ -"query-kvm"},{"name":"query-status"},{"name":\ -"query-mice"},{"name":"query-vnc"},{"name":\ -"query-spice"},{"name":"query-name"},{"name":\ -"query-uuid"},{"name":"query-migrate"},{"name":\ -"query-balloon"}],"id":"libvirt-2"} +{ + "return": [ + { + "name": "quit" + }, + { + "name": "eject" + }, + { + "name": "change" + }, + { + "name": "screendump" + }, + { + "name": "stop" + }, + { + "name": "cont" + }, + { + "name": "system_reset" + }, + { + "name": "system_powerdown" + }, + { + "name": "device_add" + }, + { + "name": "device_del" + }, + { + "name": "cpu" + }, + { + "name": "memsave" + }, + { + "name": "pmemsave" + }, + { + "name": "migrate" + }, + { + "name": "migrate_cancel" + }, + { + "name": "migrate_set_speed" + }, + { + "name": "client_migrate_info" + }, + { + "name": "migrate_set_downtime" + }, + { + "name": "netdev_add" + }, + { + "name": "netdev_del" + }, + { + "name": "block_resize" + }, + { + "name": "balloon" + }, + { + "name": "set_link" + }, + { + "name": "getfd" + }, + { + "name": "closefd" + }, + { + "name": "block_passwd" + }, + { + "name": "set_password" + }, + { + "name": "expire_password" + }, + { + "name": "qmp_capabilities" + }, + { + "name": "human-monitor-command" + }, + { + "name": "query-version" + }, + { + "name": "query-commands" + }, + { + "name": "query-chardev" + }, + { + "name": "query-block" + }, + { + "name": "query-blockstats" + }, + { + "name": "query-cpus" + }, + { + "name": "query-pci" + }, + { + "name": "query-kvm" + }, + { + "name": "query-status" + }, + { + "name": "query-mice" + }, + { + "name": "query-vnc" + }, + { + "name": "query-spice" + }, + { + "name": "query-name" + }, + { + "name": "query-uuid" + }, + { + "name": "query-migrate" + }, + { + "name": "query-balloon" + } + ], + "id": "libvirt-2" +} -- 2.19.2

On Tue, Apr 02, 2019 at 17:41:51 +0200, Ján Tomko wrote:
Remove trailing slashes and run json_reformat.
Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/virjsondata/parse-Harder-in.json | 17 +- tests/virjsondata/parse-NotSoSimple-in.json | 18 ++- tests/virjsondata/parse-Simple-in.json | 7 +- tests/virjsondata/parse-VeryHard-in.json | 167 +++++++++++++++++--- 4 files changed, 177 insertions(+), 32 deletions(-)
I don't think we should do this for the input files and even for some output files. The non-prettified input/output is used in QMP monitor interactions and I think we should keep at least some in the "native" format. This is to complement most other test files like the caps replies where we use the prettified output so that the files can be updated reasonably. This static data does not have to change.

Remove trailing slashes and call json_reformat --- tests/virjsondata/parse-Harder-out.json | 17 +- tests/virjsondata/parse-NotSoSimple-out.json | 18 +- tests/virjsondata/parse-Simple-out.json | 7 +- tests/virjsondata/parse-VeryHard-out.json | 167 ++++++++++++++++--- 4 files changed, 177 insertions(+), 32 deletions(-) diff --git a/tests/virjsondata/parse-Harder-out.json b/tests/virjsondata/parse-Harder-out.json index 31b3edd731..1cdac1f0c9 100644 --- a/tests/virjsondata/parse-Harder-out.json +++ b/tests/virjsondata/parse-Harder-out.json @@ -1,4 +1,13 @@ -{"return":[{"filename":\ -"unix:/home/berrange/.libvirt/qemu/lib/tck.monitor,server",\ -"label":"charmonitor"},{"filename":"pty:/dev/pts/158",\ -"label":"charserial0"}],"id":"libvirt-3"} +{ + "return": [ + { + "filename": "unix:/home/berrange/.libvirt/qemu/lib/tck.monitor,server", + "label": "charmonitor" + }, + { + "filename": "pty:/dev/pts/158", + "label": "charserial0" + } + ], + "id": "libvirt-3" +} diff --git a/tests/virjsondata/parse-NotSoSimple-out.json b/tests/virjsondata/parse-NotSoSimple-out.json index e679cd1813..c6553b74af 100644 --- a/tests/virjsondata/parse-NotSoSimple-out.json +++ b/tests/virjsondata/parse-NotSoSimple-out.json @@ -1,3 +1,15 @@ -{"QMP":{"version":{"qemu":\ -{"micro":91,"minor":13,"major":0},\ -"package":" (qemu-kvm-devel)"},"capabilities":[]}} +{ + "QMP": { + "version": { + "qemu": { + "micro": 91, + "minor": 13, + "major": 0 + }, + "package": " (qemu-kvm-devel)" + }, + "capabilities": [ + + ] + } +} diff --git a/tests/virjsondata/parse-Simple-out.json b/tests/virjsondata/parse-Simple-out.json index c6e85e1ceb..167bdccdf8 100644 --- a/tests/virjsondata/parse-Simple-out.json +++ b/tests/virjsondata/parse-Simple-out.json @@ -1 +1,6 @@ -{"return":{},"id":"libvirt-1"} +{ + "return": { + + }, + "id": "libvirt-1" +} diff --git a/tests/virjsondata/parse-VeryHard-out.json b/tests/virjsondata/parse-VeryHard-out.json index e10d605950..dc64fc1661 100644 --- a/tests/virjsondata/parse-VeryHard-out.json +++ b/tests/virjsondata/parse-VeryHard-out.json @@ -1,24 +1,143 @@ -{"return":[{"name":"quit"},{"name":\ -"eject"},{"name":"change"},{"name":"screendump"},\ -{"name":"stop"},{"name":"cont"},{"name":\ -"system_reset"},{"name":"system_powerdown"},\ -{"name":"device_add"},{"name":"device_del"},\ -{"name":"cpu"},{"name":"memsave"},{"name":\ -"pmemsave"},{"name":"migrate"},{"name":\ -"migrate_cancel"},{"name":"migrate_set_speed"},\ -{"name":"client_migrate_info"},{"name":\ -"migrate_set_downtime"},{"name":"netdev_add"},\ -{"name":"netdev_del"},{"name":"block_resize"},\ -{"name":"balloon"},{"name":"set_link"},{"name":\ -"getfd"},{"name":"closefd"},{"name":"block_passwd"},\ -{"name":"set_password"},{"name":"expire_password"},\ -{"name":"qmp_capabilities"},{"name":\ -"human-monitor-command"},{"name":"query-version"},\ -{"name":"query-commands"},{"name":"query-chardev"},\ -{"name":"query-block"},{"name":"query-blockstats"},\ -{"name":"query-cpus"},{"name":"query-pci"},{"name":\ -"query-kvm"},{"name":"query-status"},{"name":\ -"query-mice"},{"name":"query-vnc"},{"name":\ -"query-spice"},{"name":"query-name"},{"name":\ -"query-uuid"},{"name":"query-migrate"},{"name":\ -"query-balloon"}],"id":"libvirt-2"} +{ + "return": [ + { + "name": "quit" + }, + { + "name": "eject" + }, + { + "name": "change" + }, + { + "name": "screendump" + }, + { + "name": "stop" + }, + { + "name": "cont" + }, + { + "name": "system_reset" + }, + { + "name": "system_powerdown" + }, + { + "name": "device_add" + }, + { + "name": "device_del" + }, + { + "name": "cpu" + }, + { + "name": "memsave" + }, + { + "name": "pmemsave" + }, + { + "name": "migrate" + }, + { + "name": "migrate_cancel" + }, + { + "name": "migrate_set_speed" + }, + { + "name": "client_migrate_info" + }, + { + "name": "migrate_set_downtime" + }, + { + "name": "netdev_add" + }, + { + "name": "netdev_del" + }, + { + "name": "block_resize" + }, + { + "name": "balloon" + }, + { + "name": "set_link" + }, + { + "name": "getfd" + }, + { + "name": "closefd" + }, + { + "name": "block_passwd" + }, + { + "name": "set_password" + }, + { + "name": "expire_password" + }, + { + "name": "qmp_capabilities" + }, + { + "name": "human-monitor-command" + }, + { + "name": "query-version" + }, + { + "name": "query-commands" + }, + { + "name": "query-chardev" + }, + { + "name": "query-block" + }, + { + "name": "query-blockstats" + }, + { + "name": "query-cpus" + }, + { + "name": "query-pci" + }, + { + "name": "query-kvm" + }, + { + "name": "query-status" + }, + { + "name": "query-mice" + }, + { + "name": "query-vnc" + }, + { + "name": "query-spice" + }, + { + "name": "query-name" + }, + { + "name": "query-uuid" + }, + { + "name": "query-migrate" + }, + { + "name": "query-balloon" + } + ], + "id": "libvirt-2" +} -- 2.19.2

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/virjsondata/parse-Harder-out.json | 22 +- tests/virjsondata/parse-NotSoSimple-out.json | 24 +- tests/virjsondata/parse-Simple-out.json | 6 +- tests/virjsondata/parse-VeryHard-out.json | 282 +++++++++---------- tests/virjsontest.c | 2 +- 5 files changed, 168 insertions(+), 168 deletions(-) diff --git a/tests/virjsondata/parse-Harder-out.json b/tests/virjsondata/parse-Harder-out.json index 1cdac1f0c9..6088af7167 100644 --- a/tests/virjsondata/parse-Harder-out.json +++ b/tests/virjsondata/parse-Harder-out.json @@ -1,13 +1,13 @@ { - "return": [ - { - "filename": "unix:/home/berrange/.libvirt/qemu/lib/tck.monitor,server", - "label": "charmonitor" - }, - { - "filename": "pty:/dev/pts/158", - "label": "charserial0" - } - ], - "id": "libvirt-3" + "return": [ + { + "filename": "unix:/home/berrange/.libvirt/qemu/lib/tck.monitor,server", + "label": "charmonitor" + }, + { + "filename": "pty:/dev/pts/158", + "label": "charserial0" + } + ], + "id": "libvirt-3" } diff --git a/tests/virjsondata/parse-NotSoSimple-out.json b/tests/virjsondata/parse-NotSoSimple-out.json index c6553b74af..0eb07b0670 100644 --- a/tests/virjsondata/parse-NotSoSimple-out.json +++ b/tests/virjsondata/parse-NotSoSimple-out.json @@ -1,15 +1,15 @@ { - "QMP": { - "version": { - "qemu": { - "micro": 91, - "minor": 13, - "major": 0 - }, - "package": " (qemu-kvm-devel)" - }, - "capabilities": [ + "QMP": { + "version": { + "qemu": { + "micro": 91, + "minor": 13, + "major": 0 + }, + "package": " (qemu-kvm-devel)" + }, + "capabilities": [ - ] - } + ] + } } diff --git a/tests/virjsondata/parse-Simple-out.json b/tests/virjsondata/parse-Simple-out.json index 167bdccdf8..29dcfe01ef 100644 --- a/tests/virjsondata/parse-Simple-out.json +++ b/tests/virjsondata/parse-Simple-out.json @@ -1,6 +1,6 @@ { - "return": { + "return": { - }, - "id": "libvirt-1" + }, + "id": "libvirt-1" } diff --git a/tests/virjsondata/parse-VeryHard-out.json b/tests/virjsondata/parse-VeryHard-out.json index dc64fc1661..38e7b4df5e 100644 --- a/tests/virjsondata/parse-VeryHard-out.json +++ b/tests/virjsondata/parse-VeryHard-out.json @@ -1,143 +1,143 @@ { - "return": [ - { - "name": "quit" - }, - { - "name": "eject" - }, - { - "name": "change" - }, - { - "name": "screendump" - }, - { - "name": "stop" - }, - { - "name": "cont" - }, - { - "name": "system_reset" - }, - { - "name": "system_powerdown" - }, - { - "name": "device_add" - }, - { - "name": "device_del" - }, - { - "name": "cpu" - }, - { - "name": "memsave" - }, - { - "name": "pmemsave" - }, - { - "name": "migrate" - }, - { - "name": "migrate_cancel" - }, - { - "name": "migrate_set_speed" - }, - { - "name": "client_migrate_info" - }, - { - "name": "migrate_set_downtime" - }, - { - "name": "netdev_add" - }, - { - "name": "netdev_del" - }, - { - "name": "block_resize" - }, - { - "name": "balloon" - }, - { - "name": "set_link" - }, - { - "name": "getfd" - }, - { - "name": "closefd" - }, - { - "name": "block_passwd" - }, - { - "name": "set_password" - }, - { - "name": "expire_password" - }, - { - "name": "qmp_capabilities" - }, - { - "name": "human-monitor-command" - }, - { - "name": "query-version" - }, - { - "name": "query-commands" - }, - { - "name": "query-chardev" - }, - { - "name": "query-block" - }, - { - "name": "query-blockstats" - }, - { - "name": "query-cpus" - }, - { - "name": "query-pci" - }, - { - "name": "query-kvm" - }, - { - "name": "query-status" - }, - { - "name": "query-mice" - }, - { - "name": "query-vnc" - }, - { - "name": "query-spice" - }, - { - "name": "query-name" - }, - { - "name": "query-uuid" - }, - { - "name": "query-migrate" - }, - { - "name": "query-balloon" - } - ], - "id": "libvirt-2" + "return": [ + { + "name": "quit" + }, + { + "name": "eject" + }, + { + "name": "change" + }, + { + "name": "screendump" + }, + { + "name": "stop" + }, + { + "name": "cont" + }, + { + "name": "system_reset" + }, + { + "name": "system_powerdown" + }, + { + "name": "device_add" + }, + { + "name": "device_del" + }, + { + "name": "cpu" + }, + { + "name": "memsave" + }, + { + "name": "pmemsave" + }, + { + "name": "migrate" + }, + { + "name": "migrate_cancel" + }, + { + "name": "migrate_set_speed" + }, + { + "name": "client_migrate_info" + }, + { + "name": "migrate_set_downtime" + }, + { + "name": "netdev_add" + }, + { + "name": "netdev_del" + }, + { + "name": "block_resize" + }, + { + "name": "balloon" + }, + { + "name": "set_link" + }, + { + "name": "getfd" + }, + { + "name": "closefd" + }, + { + "name": "block_passwd" + }, + { + "name": "set_password" + }, + { + "name": "expire_password" + }, + { + "name": "qmp_capabilities" + }, + { + "name": "human-monitor-command" + }, + { + "name": "query-version" + }, + { + "name": "query-commands" + }, + { + "name": "query-chardev" + }, + { + "name": "query-block" + }, + { + "name": "query-blockstats" + }, + { + "name": "query-cpus" + }, + { + "name": "query-pci" + }, + { + "name": "query-kvm" + }, + { + "name": "query-status" + }, + { + "name": "query-mice" + }, + { + "name": "query-vnc" + }, + { + "name": "query-spice" + }, + { + "name": "query-name" + }, + { + "name": "query-uuid" + }, + { + "name": "query-migrate" + }, + { + "name": "query-balloon" + } + ], + "id": "libvirt-2" } diff --git a/tests/virjsontest.c b/tests/virjsontest.c index 4a33aff785..9dcdd90b2d 100644 --- a/tests/virjsontest.c +++ b/tests/virjsontest.c @@ -52,7 +52,7 @@ testJSONFromFile(const void *data) } } - if (!(actual = virJSONValueToString(injson, false))) + if (!(actual = virJSONValueToString(injson, true))) return -1; if (virTestCompareToFile(actual, outfile) < 0) -- 2.19.2
participants (2)
-
Ján Tomko
-
Peter Krempa