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(a)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 1d9fc6ccb6..48cf5df5a9 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;
}
@@ -544,47 +545,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("add and remove", AddRemove,
"{\"name\": \"sample\", \"value\":
true}",
--
2.19.2