mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-10-03 04:45:46 +00:00
virjsontest: switch AddAndRemove tests to work with files
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>
This commit is contained in:
parent
650e62e034
commit
ee3e23a790
1
tests/virjsondata/add-remove-failure-in.json
Normal file
1
tests/virjsondata/add-remove-failure-in.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
[ 1 ]
|
1
tests/virjsondata/add-remove-success-in.json
Normal file
1
tests/virjsondata/add-remove-success-in.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"name": "sample", "value": true}
|
1
tests/virjsondata/add-remove-success-out.json
Normal file
1
tests/virjsondata/add-remove-success-out.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"value":true,"newname":"foo"}
|
@ -68,12 +68,24 @@ static int
|
|||||||
testJSONAddRemove(const void *data)
|
testJSONAddRemove(const void *data)
|
||||||
{
|
{
|
||||||
const struct testInfo *info = data;
|
const struct testInfo *info = data;
|
||||||
virJSONValuePtr json;
|
virJSONValuePtr json = NULL;
|
||||||
virJSONValuePtr name = NULL;
|
virJSONValuePtr name = NULL;
|
||||||
char *result = NULL;
|
VIR_AUTOFREE(char *) infile = NULL;
|
||||||
|
VIR_AUTOFREE(char *) indata = NULL;
|
||||||
|
VIR_AUTOFREE(char *) outfile = NULL;
|
||||||
|
VIR_AUTOFREE(char *) actual = NULL;
|
||||||
int ret = -1;
|
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) {
|
if (!json) {
|
||||||
VIR_TEST_VERBOSE("Fail to parse %s\n", info->name);
|
VIR_TEST_VERBOSE("Fail to parse %s\n", info->name);
|
||||||
ret = -1;
|
ret = -1;
|
||||||
@ -113,20 +125,18 @@ testJSONAddRemove(const void *data)
|
|||||||
VIR_TEST_VERBOSE("%s", "unexpected failure adding new key\n");
|
VIR_TEST_VERBOSE("%s", "unexpected failure adding new key\n");
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if (!(result = virJSONValueToString(json, false))) {
|
if (!(actual = virJSONValueToString(json, false))) {
|
||||||
VIR_TEST_VERBOSE("%s", "failed to stringize result\n");
|
VIR_TEST_VERBOSE("%s", "failed to stringize result\n");
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if (STRNEQ(info->expect, result)) {
|
if (virTestCompareToFile(actual, outfile) < 0)
|
||||||
virTestDifference(stderr, info->expect, result);
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virJSONValueFree(json);
|
virJSONValueFree(json);
|
||||||
virJSONValueFree(name);
|
virJSONValueFree(name);
|
||||||
VIR_FREE(result);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -543,12 +553,8 @@ mymain(void)
|
|||||||
"\"query-uuid\"},{\"name\":\"query-migrate\"},{\"name\":"
|
"\"query-uuid\"},{\"name\":\"query-migrate\"},{\"name\":"
|
||||||
"\"query-balloon\"}],\"id\":\"libvirt-2\"}", NULL);
|
"\"query-balloon\"}],\"id\":\"libvirt-2\"}", NULL);
|
||||||
|
|
||||||
DO_TEST_FULL("add and remove", AddRemove,
|
DO_TEST_FULL("success", AddRemove, NULL, NULL, true);
|
||||||
"{\"name\": \"sample\", \"value\": true}",
|
DO_TEST_FULL("failure", AddRemove, NULL, NULL, false);
|
||||||
"{\"value\":true,\"newname\":\"foo\"}",
|
|
||||||
true);
|
|
||||||
DO_TEST_FULL("add and remove", AddRemove,
|
|
||||||
"[ 1 ]", NULL, false);
|
|
||||||
|
|
||||||
DO_TEST_FULL("copy and free", Copy,
|
DO_TEST_FULL("copy and free", Copy,
|
||||||
"{\"return\": [{\"name\": \"quit\"}, {\"name\": \"eject\"},"
|
"{\"return\": [{\"name\": \"quit\"}, {\"name\": \"eject\"},"
|
||||||
|
Loading…
Reference in New Issue
Block a user