From nobody Fri May 16 05:35:49 2025 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 15010633725321015.5170400151097; Wed, 26 Jul 2017 03:02:52 -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 6EDAB4A70C; Wed, 26 Jul 2017 10:02:47 +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 36F186FB61; Wed, 26 Jul 2017 10:02: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 E37C614B28; Wed, 26 Jul 2017 10:02:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v6QA121U008805 for ; Wed, 26 Jul 2017 06:01:02 -0400 Received: by smtp.corp.redhat.com (Postfix) id F41EF6FE6A; Wed, 26 Jul 2017 10:01:02 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.201]) by smtp.corp.redhat.com (Postfix) with ESMTP id 45DF06FE6D; Wed, 26 Jul 2017 10:01:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6EDAB4A70C Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com From: Peter Krempa To: libvir-list@redhat.com Date: Wed, 26 Jul 2017 12:00:39 +0200 Message-Id: <61e5bf7a11dd34dbda8642741a65ec7e74fa8995.1501062802.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 09/24] tests: utils: Add virTestLoadFileJSON helper 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.38]); Wed, 26 Jul 2017 10:02:48 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This new helper loads, parses and returns a JSON file from 'abs_srcdir' By using variable arguments for the function, it's not necessary to format the path separately in the test cases. --- tests/testutils.c | 34 ++++++++++++++++++++++++++++++++++ tests/testutils.h | 4 ++++ 2 files changed, 38 insertions(+) diff --git a/tests/testutils.c b/tests/testutils.c index f193cdf8b..75f69e1c3 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -407,6 +407,40 @@ virTestLoadFilePath(const char *p, ...) } +/** + * virTestLoadFileJSON: + * @...: name components + * + * Constructs the test file path from variable arguments and loads and par= ses + * the JSON file. 'abs_srcdir' is automatically prepended to the path. + */ +virJSONValuePtr +virTestLoadFileJSON(const char *p, ...) +{ + virJSONValuePtr ret =3D NULL; + char *jsonstr =3D NULL; + char *path =3D NULL; + va_list ap; + + va_start(ap, p); + + if (!(path =3D virTestLoadFileGetPath(p, ap))) + goto cleanup; + + if (virTestLoadFile(path, &jsonstr) < 0) + goto cleanup; + + if (!(ret =3D virJSONValueFromString(jsonstr))) + VIR_TEST_VERBOSE("failed to parse json from file '%s'", path); + + cleanup: + va_end(ap); + VIR_FREE(jsonstr); + VIR_FREE(path); + return ret; +} + + #ifndef WIN32 static void virTestCaptureProgramExecChild(const char *const argv[], diff --git a/tests/testutils.h b/tests/testutils.h index 98dfa990e..49649c4f5 100644 --- a/tests/testutils.h +++ b/tests/testutils.h @@ -27,6 +27,7 @@ # include "viralloc.h" # include "virfile.h" # include "virstring.h" +# include "virjson.h" # include "capabilities.h" # include "domain_conf.h" @@ -54,6 +55,9 @@ int virTestRun(const char *title, int virTestLoadFile(const char *file, char **buf); char *virTestLoadFilePath(const char *p, ...) ATTRIBUTE_SENTINEL; +virJSONValuePtr virTestLoadFileJSON(const char *p, ...) + ATTRIBUTE_SENTINEL; + int virTestCaptureProgramOutput(const char *const argv[], char **buf, int = maxlen); void virTestClearCommandPath(char *cmdset); --=20 2.13.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list