From nobody Mon Apr 29 17:10:26 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1499777796051339.6006828241832; Tue, 11 Jul 2017 05:56:36 -0700 (PDT) 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 CAC3F3DE3D; Tue, 11 Jul 2017 12:56:32 +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 6E1F37FB8E; Tue, 11 Jul 2017 12:56:32 +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 B376B1841C41; Tue, 11 Jul 2017 12:56:31 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v6BCuOvS013107 for ; Tue, 11 Jul 2017 08:56:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id CE35F757D0; Tue, 11 Jul 2017 12:56:24 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.201]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9B8B7757C7; Tue, 11 Jul 2017 12:56:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CAC3F3DE3D Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com CAC3F3DE3D From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 11 Jul 2017 14:56:22 +0200 Message-Id: <9b616f2791bc14cdfb50ca421e2559f7c23158ce.1499777674.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH v2 1/4] tests: virjson: Modify logic in testJSONFromString 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: , MIME-Version: 1.0 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.29]); Tue, 11 Jul 2017 12:56:34 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" To allow better testing in case where the string was parsed, modify the logic so that the regular code path is not included in a conditional block. Reviewed-by: John Ferlan --- tests/virjsontest.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/virjsontest.c b/tests/virjsontest.c index b9c210620..a5ffc4707 100644 --- a/tests/virjsontest.c +++ b/tests/virjsontest.c @@ -27,24 +27,24 @@ testJSONFromString(const void *data) json =3D virJSONValueFromString(info->doc); - if (info->pass) { - if (!json) { + if (!json) { + if (info->pass) { VIR_TEST_VERBOSE("Fail to parse %s\n", info->doc); - ret =3D -1; - goto cleanup; - } else { - VIR_TEST_DEBUG("Parsed %s\n", info->doc); - } - } else { - if (json) { - VIR_TEST_VERBOSE("Should not have parsed %s\n", info->doc); - ret =3D -1; goto cleanup; } else { VIR_TEST_DEBUG("Fail to parse %s\n", info->doc); + ret =3D 0; + goto cleanup; } } + if (!info->pass) { + VIR_TEST_VERBOSE("Should not have parsed %s\n", info->doc); + goto cleanup; + } + + VIR_TEST_DEBUG("Parsed %s\n", info->doc); + ret =3D 0; cleanup: --=20 2.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 17:10:26 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1499777803008100.6190235816033; Tue, 11 Jul 2017 05:56:43 -0700 (PDT) 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 95437C04B92C; Tue, 11 Jul 2017 12:56:39 +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 580827FB9D; Tue, 11 Jul 2017 12:56:39 +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 EAC613FAE3; Tue, 11 Jul 2017 12:56:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v6BCuTjm013125 for ; Tue, 11 Jul 2017 08:56:29 -0400 Received: by smtp.corp.redhat.com (Postfix) id D38BC757D5; Tue, 11 Jul 2017 12:56:29 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.201]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0D59F757D1; Tue, 11 Jul 2017 12:56:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 95437C04B92C Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 95437C04B92C From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 11 Jul 2017 14:56:23 +0200 Message-Id: <457f5b34b192d6c6d6afabbee579cc125ca2040b.1499777674.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH v2 2/4] tests: virjson: Remove spaces from 'very-hard' parsing example 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: , MIME-Version: 1.0 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.31]); Tue, 11 Jul 2017 12:56:40 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The example is rather long and upcomming patch will check whether the string can be formatted back. As the formatted string lacks spaces and adding the 'expect' string with spaces would be rather long, just drop spaces from this test case. There are other test cases which do contain spaces. Reviewed-by: John Ferlan --- tests/virjsontest.c | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/tests/virjsontest.c b/tests/virjsontest.c index a5ffc4707..029a580f4 100644 --- a/tests/virjsontest.c +++ b/tests/virjsontest.c @@ -386,30 +386,30 @@ mymain(void) "\"label\": \"charmonitor\"}, {\"filename\": \"pty:/dev/= pts/158\"," "\"label\": \"charserial0\"}], \"id\": \"libvirt-3\"}"); - DO_TEST_PARSE("VeryHard", "{\"return\": [{\"name\": \"quit\"}, {\"name= \":" - "\"eject\"}, {\"name\": \"change\"}, {\"name\": \"screen= dump\"}," - "{\"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\"}, {\"n= ame\":" - "\"getfd\"}, {\"name\": \"closefd\"}, {\"name\": \"block= _passwd\"}," - "{\"name\": \"set_password\"}, {\"name\": \"expire_passw= ord\"}," - "{\"name\": \"qmp_capabilities\"}, {\"name\": " - "\"human-monitor-command\"}, {\"name\": \"query-version\= "}," - "{\"name\": \"query-commands\"}, {\"name\": \"query-char= dev\"}," - "{\"name\": \"query-block\"}, {\"name\": \"query-blockst= ats\"}, " - "{\"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("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\"}"); DO_TEST_FULL("add and remove", AddRemove, "{\"name\": \"sample\", \"value\": true}", --=20 2.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 17:10:26 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1499777801133475.8972355262995; Tue, 11 Jul 2017 05:56:41 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 85B5AC04B938; Tue, 11 Jul 2017 12:56:34 +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 4E6601836F; Tue, 11 Jul 2017 12:56:34 +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 E41A23FAE1; Tue, 11 Jul 2017 12:56:33 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v6BCuXla013136 for ; Tue, 11 Jul 2017 08:56:33 -0400 Received: by smtp.corp.redhat.com (Postfix) id 58BD7757C7; Tue, 11 Jul 2017 12:56:33 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.201]) by smtp.corp.redhat.com (Postfix) with ESMTP id E5566757D0; Tue, 11 Jul 2017 12:56:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 85B5AC04B938 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 85B5AC04B938 From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 11 Jul 2017 14:56:24 +0200 Message-Id: <924149866230d606476c3c806b963dab463c9b9d.1499777674.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH v2 3/4] tests: virjson: Test formatting along with parsing of JSON objects 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: , MIME-Version: 1.0 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 11 Jul 2017 12:56:35 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Format the parsed string back and compare it to the original (or modified) string for back and forth comparison. Reviewed-by: John Ferlan --- tests/virjsontest.c | 58 ++++++++++++++++++++++++++++++++++++++++---------= ---- 1 file changed, 44 insertions(+), 14 deletions(-) diff --git a/tests/virjsontest.c b/tests/virjsontest.c index 029a580f4..a6e158179 100644 --- a/tests/virjsontest.c +++ b/tests/virjsontest.c @@ -23,6 +23,8 @@ testJSONFromString(const void *data) { const struct testInfo *info =3D data; virJSONValuePtr json; + const char *expectstr =3D info->expect ? info->expect : info->doc; + char *formatted =3D NULL; int ret =3D -1; json =3D virJSONValueFromString(info->doc); @@ -45,9 +47,20 @@ testJSONFromString(const void *data) VIR_TEST_DEBUG("Parsed %s\n", info->doc); + if (!(formatted =3D virJSONValueToString(json, false))) { + VIR_TEST_VERBOSE("Failed to format json data\n"); + goto cleanup; + } + + if (STRNEQ(expectstr, formatted)) { + virTestDifference(stderr, expectstr, formatted); + goto cleanup; + } + ret =3D 0; cleanup: + VIR_FREE(formatted); virJSONValueFree(json); return ret; } @@ -368,23 +381,39 @@ mymain(void) ret =3D -1; \ } while (0) -#define DO_TEST_PARSE(name, doc) \ - DO_TEST_FULL(name, FromString, doc, NULL, true) +/** + * DO_TEST_PARSE: + * @name: test name + * @doc: source JSON string + * @expect: expected output JSON formatted from parsed @doc + * + * Parses @doc and formats it back. If @expect is NULL the result has to be + * identical to @doc. + */ +#define DO_TEST_PARSE(name, doc, expect) \ + DO_TEST_FULL(name, FromString, doc, expect, true) #define DO_TEST_PARSE_FAIL(name, doc) \ DO_TEST_FULL(name, FromString, doc, NULL, false) - DO_TEST_PARSE("Simple", "{\"return\": {}, \"id\": \"libvirt-1\"}"); + 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\": = []}}"); - + "\"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\"}"); + "\"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= \"}," @@ -409,7 +438,7 @@ mymain(void) "\"query-mice\"},{\"name\":\"query-vnc\"},{\"name\":" "\"query-spice\"},{\"name\":\"query-name\"},{\"name\":" "\"query-uuid\"},{\"name\":\"query-migrate\"},{\"name\":" - "\"query-balloon\"}],\"id\":\"libvirt-2\"}"); + "\"query-balloon\"}],\"id\":\"libvirt-2\"}", NULL); DO_TEST_FULL("add and remove", AddRemove, "{\"name\": \"sample\", \"value\": true}", @@ -445,21 +474,22 @@ mymain(void) "\"query-balloon\"}], \"id\": \"libvirt-2\"}", NULL, true= ); - DO_TEST_PARSE("almost nothing", "[]"); + DO_TEST_PARSE("almost nothing", "[]", NULL); DO_TEST_PARSE_FAIL("nothing", ""); - DO_TEST_PARSE("number without garbage", "[ 234545 ]"); + DO_TEST_PARSE("number without garbage", "[ 234545 ]", "[234545]"); DO_TEST_PARSE_FAIL("number with garbage", "[ 2345b45 ]"); - DO_TEST_PARSE("float without garbage", "[ 0.0314159e+100 ]"); + DO_TEST_PARSE("float without garbage", "[ 0.0314159e+100 ]", "[0.03141= 59e+100]"); DO_TEST_PARSE_FAIL("float with garbage", "[ 0.0314159ee+100 ]"); - DO_TEST_PARSE("string", "[ \"The meaning of life\" ]"); + DO_TEST_PARSE("string", "[ \"The meaning of life\" ]", + "[\"The meaning of life\"]"); DO_TEST_PARSE_FAIL("unterminated string", "[ \"The meaning of lif ]"); - DO_TEST_PARSE("integer", "1"); - DO_TEST_PARSE("boolean", "true"); - DO_TEST_PARSE("null", "null"); + DO_TEST_PARSE("integer", "1", NULL); + DO_TEST_PARSE("boolean", "true", NULL); + DO_TEST_PARSE("null", "null", NULL); DO_TEST_PARSE_FAIL("incomplete keyword", "tr"); DO_TEST_PARSE_FAIL("overdone keyword", "[ truest ]"); DO_TEST_PARSE_FAIL("unknown keyword", "huh"); --=20 2.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Mon Apr 29 17:10:26 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1499777802978217.94262978340157; Tue, 11 Jul 2017 05:56:42 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C53253345AF; Tue, 11 Jul 2017 12:56:39 +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 8E7097D4ED; Tue, 11 Jul 2017 12:56:39 +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 C94A51853E30; Tue, 11 Jul 2017 12:56:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v6BCuZqe013148 for ; Tue, 11 Jul 2017 08:56:35 -0400 Received: by smtp.corp.redhat.com (Postfix) id 18423757D0; Tue, 11 Jul 2017 12:56:35 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.201]) by smtp.corp.redhat.com (Postfix) with ESMTP id E4209757D2; Tue, 11 Jul 2017 12:56:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C53253345AF Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com C53253345AF From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 11 Jul 2017 14:56:25 +0200 Message-Id: <361d5f0019ed973f12c7221c1e6b45fe36dcef63.1499777674.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH v2 4/4] tests: virjson: Test string escaping 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: , MIME-Version: 1.0 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 11 Jul 2017 12:56:40 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Make sure that JSON strings can contain characters which need to be escaped (double quotes, backslashes, tabs, etc.) and that JSON objects formatted into strings can be nested into strings. --- tests/virjsontest.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 66 insertions(+) diff --git a/tests/virjsontest.c b/tests/virjsontest.c index a6e158179..30457d118 100644 --- a/tests/virjsontest.c +++ b/tests/virjsontest.c @@ -365,7 +365,67 @@ testJSONDeflatten(const void *data) VIR_FREE(actual); return ret; +} + + +static int +testJSONEscapeObj(const void *data ATTRIBUTE_UNUSED) +{ + virJSONValuePtr json =3D NULL; + virJSONValuePtr nestjson =3D NULL; + virJSONValuePtr parsejson =3D NULL; + char *neststr =3D NULL; + char *result =3D NULL; + const char *parsednestedstr; + int ret =3D -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; + } + + if (!(neststr =3D virJSONValueToString(nestjson, false))) { + VIR_TEST_VERBOSE("failed to format nested json object"); + goto cleanup; + } + + if (virJSONValueObjectCreate(&json, "s:test", neststr, NULL) < 0) { + VIR_TEST_VERBOSE("Failed to create json object"); + goto cleanup; + } + + if (!(result =3D virJSONValueToString(json, false))) { + VIR_TEST_VERBOSE("Failed to format json object"); + goto cleanup; + } + + if (!(parsejson =3D virJSONValueFromString(result))) { + VIR_TEST_VERBOSE("Failed to parse JSON with nested JSON in string"= ); + goto cleanup; + } + if (!(parsednestedstr =3D virJSONValueObjectGetString(parsejson, "test= "))) { + VIR_TEST_VERBOSE("Failed to retrieve string containing nested json= "); + goto cleanup; + } + + if (STRNEQ(parsednestedstr, neststr)) { + virTestDifference(stderr, neststr, parsednestedstr); + goto cleanup; + } + + ret =3D 0; + + cleanup: + VIR_FREE(neststr); + VIR_FREE(result); + virJSONValueFree(json); + virJSONValueFree(nestjson); + virJSONValueFree(parsejson); + return ret; } @@ -490,6 +550,10 @@ mymain(void) DO_TEST_PARSE("integer", "1", NULL); DO_TEST_PARSE("boolean", "true", NULL); DO_TEST_PARSE("null", "null", NULL); + + DO_TEST_PARSE("escaping symbols", "[\"\\\"\\t\\n\\\\\"]", NULL); + DO_TEST_PARSE("escaped strings", "[\"{\\\"blurb\\\":\\\"test\\\"}\"]",= NULL); + DO_TEST_PARSE_FAIL("incomplete keyword", "tr"); DO_TEST_PARSE_FAIL("overdone keyword", "[ truest ]"); DO_TEST_PARSE_FAIL("unknown keyword", "huh"); @@ -522,6 +586,8 @@ mymain(void) DO_TEST_FULL("lookup with correct type", Lookup, "{ \"a\": {}, \"b\": 1, \"c\": \"str\", \"d\": [] }", NULL, true); + DO_TEST_FULL("create object with nested json in attribute", EscapeObj, + NULL, NULL, true); #define DO_TEST_DEFLATTEN(name, pass) \ DO_TEST_FULL(name, Deflatten, name, NULL, pass) --=20 2.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list