mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 05:35:25 +00:00
virjsontest: switch DO_TEST_PARSE_FILE to use output files
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>
This commit is contained in:
parent
adaaa91724
commit
12f3ca248a
4
tests/virjsondata/parse-Harder-out.json
Normal file
4
tests/virjsondata/parse-Harder-out.json
Normal file
@ -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"}
|
3
tests/virjsondata/parse-NotSoSimple-out.json
Normal file
3
tests/virjsondata/parse-NotSoSimple-out.json
Normal file
@ -0,0 +1,3 @@
|
||||
{"QMP":{"version":{"qemu":\
|
||||
{"micro":91,"minor":13,"major":0},\
|
||||
"package":" (qemu-kvm-devel)"},"capabilities":[]}}
|
1
tests/virjsondata/parse-Simple-out.json
Normal file
1
tests/virjsondata/parse-Simple-out.json
Normal file
@ -0,0 +1 @@
|
||||
{"return":{},"id":"libvirt-1"}
|
24
tests/virjsondata/parse-VeryHard-out.json
Normal file
24
tests/virjsondata/parse-VeryHard-out.json
Normal file
@ -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"}
|
@ -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)
|
||||
#define DO_TEST_PARSE_FILE(name) \
|
||||
DO_TEST_FULL(name, FromFile, NULL, NULL, 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_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);
|
||||
|
Loading…
Reference in New Issue
Block a user