From nobody Sun Feb 8 18:14:07 2026 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 1554219792582844.6182371027384; Tue, 2 Apr 2019 08:43:12 -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 A3C6E356F6; Tue, 2 Apr 2019 15:43:00 +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 C64A25D78F; Tue, 2 Apr 2019 15:42:56 +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 BE0A741F3C; Tue, 2 Apr 2019 15:42:50 +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 x32Fg1uG011830 for ; Tue, 2 Apr 2019 11:42:01 -0400 Received: by smtp.corp.redhat.com (Postfix) id A77BE5C21A; Tue, 2 Apr 2019 15:42:01 +0000 (UTC) Received: from icr.brq.redhat.com (unknown [10.43.2.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2F6CA5C6A5 for ; Tue, 2 Apr 2019 15:41:59 +0000 (UTC) From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Tue, 2 Apr 2019 17:41:40 +0200 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] [PATCHv2 01/14] 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 02 Apr 2019 15:43:06 +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 a4bd4fb07b..429eb58704 100644 --- a/tests/virjsontest.c +++ b/tests/virjsontest.c @@ -68,12 +68,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; @@ -113,20 +125,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 @@ -543,12 +557,8 @@ mymain(void) "\"query-uuid\"},{\"name\":\"query-migrate\"},{\"name\":" "\"query-balloon\"}],\"id\":\"libvirt-2\"}", NULL); =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