From nobody Mon Apr 29 12:33:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1549987069414744.7200138688208; Tue, 12 Feb 2019 07:57:49 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A2AFB8E5A7; Tue, 12 Feb 2019 15:57:46 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 73DE6BA5C; Tue, 12 Feb 2019 15:57:46 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 211BE3F774; Tue, 12 Feb 2019 15:57:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x1CFvidR028645 for ; Tue, 12 Feb 2019 10:57:44 -0500 Received: by smtp.corp.redhat.com (Postfix) id DAE355C257; Tue, 12 Feb 2019 15:57:44 +0000 (UTC) Received: from icr.brq.redhat.com (unknown [10.43.2.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5F4F45C23F for ; Tue, 12 Feb 2019 15:57:40 +0000 (UTC) From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Tue, 12 Feb 2019 16:57:29 +0100 Message-Id: <993be1377fbf52fed3f6fb5ae626183479014cbd.1549987014.git.jtomko@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/3] virjsontest: introduce DO_TEST_PARSE_FILE X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 12 Feb 2019 15:57:47 +0000 (UTC) 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=C3=A1n Tomko --- 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/par= se-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/virjsondat= a/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/par= se-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/p= arse-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 a4bd4fb07b..1d9fc6ccb6 100644 --- a/tests/virjsontest.c +++ b/tests/virjsontest.c @@ -16,6 +16,51 @@ struct testInfo { }; =20 =20 +static int +testJSONFromFile(const void *data) +{ + const struct testInfo *info =3D data; + VIR_AUTOPTR(virJSONValue) injson =3D NULL; + VIR_AUTOFREE(char *) infile =3D NULL; + VIR_AUTOFREE(char *) indata =3D NULL; + VIR_AUTOFREE(char *) actual =3D 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 =3D virJSONValueFromString(indata); + + if (!injson) { + if (info->pass) { + VIR_TEST_VERBOSE("Fail to parse %s\n", info->name); + return -1; + } else { + VIR_TEST_DEBUG("Fail to parse %s\n", info->name); + return 0; + } + } + + if (!info->pass) { + VIR_TEST_VERBOSE("Should not have parsed %s\n", info->name); + return -1; + } + + if (!(actual =3D 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) { @@ -499,49 +544,47 @@ mymain(void) #define DO_TEST_PARSE_FAIL(name, doc) \ DO_TEST_FULL(name, FromString, doc, NULL, false) =20 - - 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,ser= ver\"," - "\"label\": \"charmonitor\"}, {\"filename\": \"pty:/dev/= pts/158\"," - "\"label\": \"charserial0\"}], \"id\": \"libvirt-3\"}", - "{\"return\":[{\"filename\":" - "\"unix:/home/berrange/.libvirt/qemu/lib/tck.monitor,ser= ver\"," - "\"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_pas= swd\"}," - "{\"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\"},{\"n= ame\":" - "\"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.monito= r,server\"," + "\"label\":\"charmonitor\"},{\"filename\":\"pty:/de= v/pts/158\"," + "\"label\":\"charserial0\"}],\"id\":\"libvirt-3\"}"= ); + + DO_TEST_PARSE_FILE("VeryHard", "{\"return\":[{\"name\":\"quit\"},{\"na= me\":" + "\"eject\"},{\"name\":\"change\"},{\"name\":\"scree= ndump\"}," + "{\"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\":\"bloc= k_passwd\"}," + "{\"name\":\"set_password\"},{\"name\":\"expire_pas= sword\"}," + "{\"name\":\"qmp_capabilities\"},{\"name\":" + "\"human-monitor-command\"},{\"name\":\"query-versi= on\"}," + "{\"name\":\"query-commands\"},{\"name\":\"query-ch= ardev\"}," + "{\"name\":\"query-block\"},{\"name\":\"query-block= stats\"}," + "{\"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\"},{\"na= me\":" + "\"query-balloon\"}],\"id\":\"libvirt-2\"}"); =20 DO_TEST_FULL("add and remove", AddRemove, "{\"name\": \"sample\", \"value\": true}", --=20 2.19.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 12:33:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1549987069919807.9879866384201; Tue, 12 Feb 2019 07:57:49 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5E3EB80467; Tue, 12 Feb 2019 15:57:47 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2CFC85C25A; Tue, 12 Feb 2019 15:57:47 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id D59A31819AF9; Tue, 12 Feb 2019 15:57:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x1CFvjEM028650 for ; Tue, 12 Feb 2019 10:57:45 -0500 Received: by smtp.corp.redhat.com (Postfix) id AD63F5C23F; Tue, 12 Feb 2019 15:57:45 +0000 (UTC) Received: from icr.brq.redhat.com (unknown [10.43.2.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 33E1B5C241 for ; Tue, 12 Feb 2019 15:57:45 +0000 (UTC) From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Tue, 12 Feb 2019 16:57:30 +0100 Message-Id: <189d9c75b6e4048e55b15666999bcf76d5c2e26b.1549987014.git.jtomko@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/3] virjsontest: switch DO_TEST_PARSE_FILE to use output files X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 12 Feb 2019 15:57:48 +0000 (UTC) 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=C3=A1n Tomko --- 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/pa= rse-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/virjsonda= ta/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/pa= rse-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 =3D NULL; VIR_AUTOFREE(char *) infile =3D NULL; VIR_AUTOFREE(char *) indata =3D NULL; + VIR_AUTOFREE(char *) outfile =3D NULL; VIR_AUTOFREE(char *) actual =3D NULL; =20 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; =20 @@ -52,10 +55,8 @@ testJSONFromFile(const void *data) if (!(actual =3D virJSONValueToString(injson, false))) return -1; =20 - if (STRNEQ(info->expect, actual)) { - virTestDifference(stderr, info->expect, actual); + if (virTestCompareToFile(actual, outfile) < 0) return -1; - } =20 return 0; } @@ -544,47 +545,14 @@ mymain(void) #define DO_TEST_PARSE_FAIL(name, doc) \ DO_TEST_FULL(name, FromString, doc, NULL, false) =20 -#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.monito= r,server\"," - "\"label\":\"charmonitor\"},{\"filename\":\"pty:/de= v/pts/158\"," - "\"label\":\"charserial0\"}],\"id\":\"libvirt-3\"}"= ); - - DO_TEST_PARSE_FILE("VeryHard", "{\"return\":[{\"name\":\"quit\"},{\"na= me\":" - "\"eject\"},{\"name\":\"change\"},{\"name\":\"scree= ndump\"}," - "{\"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\":\"bloc= k_passwd\"}," - "{\"name\":\"set_password\"},{\"name\":\"expire_pas= sword\"}," - "{\"name\":\"qmp_capabilities\"},{\"name\":" - "\"human-monitor-command\"},{\"name\":\"query-versi= on\"}," - "{\"name\":\"query-commands\"},{\"name\":\"query-ch= ardev\"}," - "{\"name\":\"query-block\"},{\"name\":\"query-block= stats\"}," - "{\"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\"},{\"na= me\":" - "\"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"); =20 DO_TEST_FULL("add and remove", AddRemove, "{\"name\": \"sample\", \"value\": true}", --=20 2.19.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 12:33:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1549987075923158.39125725568476; Tue, 12 Feb 2019 07:57:55 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A54ADA342F; Tue, 12 Feb 2019 15:57:52 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 288CA17DD4; Tue, 12 Feb 2019 15:57:52 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id A4CBE1819AFF; Tue, 12 Feb 2019 15:57:51 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x1CFvkjH028660 for ; Tue, 12 Feb 2019 10:57:46 -0500 Received: by smtp.corp.redhat.com (Postfix) id 7DCC45C23F; Tue, 12 Feb 2019 15:57:46 +0000 (UTC) Received: from icr.brq.redhat.com (unknown [10.43.2.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 04E7D5C241 for ; Tue, 12 Feb 2019 15:57:45 +0000 (UTC) From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Tue, 12 Feb 2019 16:57:31 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 3/3] virjsontest: switch AddAndRemove tests to work with files X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 12 Feb 2019 15:57:54 +0000 (UTC) Instead of using JSON in C strings, put it in separate files for easier manipulation. Signed-off-by: J=C3=A1n Tomko Reviewed-by: Andrea Bolognani --- 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/virjsonda= ta/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/virjsonda= ta/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/virjsond= ata/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 48cf5df5a9..5bac08d039 100644 --- a/tests/virjsontest.c +++ b/tests/virjsontest.c @@ -114,12 +114,24 @@ static int testJSONAddRemove(const void *data) { const struct testInfo *info =3D data; - virJSONValuePtr json; + virJSONValuePtr json =3D NULL; virJSONValuePtr name =3D NULL; - char *result =3D NULL; + char *infile =3D NULL; + char *indata =3D NULL; + char *outfile =3D NULL; + char *actual =3D NULL; int ret =3D -1; =20 - json =3D 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 =3D virJSONValueFromString(indata); if (!json) { VIR_TEST_VERBOSE("Fail to parse %s\n", info->name); ret =3D -1; @@ -159,20 +171,22 @@ testJSONAddRemove(const void *data) VIR_TEST_VERBOSE("%s", "unexpected failure adding new key\n"); goto cleanup; } - if (!(result =3D virJSONValueToString(json, false))) { + if (!(actual =3D 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 =3D 0; =20 cleanup: virJSONValueFree(json); virJSONValueFree(name); - VIR_FREE(result); + VIR_FREE(infile); + VIR_FREE(indata); + VIR_FREE(outfile); + VIR_FREE(actual); return ret; } =20 @@ -554,12 +568,8 @@ mymain(void) DO_TEST_PARSE_FILE("Harder"); DO_TEST_PARSE_FILE("VeryHard"); =20 - 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); =20 DO_TEST_FULL("copy and free", Copy, "{\"return\": [{\"name\": \"quit\"}, {\"name\": \"eject\"= }," --=20 2.19.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list