From nobody Mon Feb 9 00:02:27 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 149001491952046.0829428152407; Mon, 20 Mar 2017 06:01:59 -0700 (PDT) Received: from localhost ([::1]:32865 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cpwwg-000464-1m for importer@patchew.org; Mon, 20 Mar 2017 09:01:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44485) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cpwqs-00005d-Kl for qemu-devel@nongnu.org; Mon, 20 Mar 2017 08:55:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cpwqr-0005Lp-Bm for qemu-devel@nongnu.org; Mon, 20 Mar 2017 08:55:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46292) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cpwql-0005D1-Q5; Mon, 20 Mar 2017 08:55:52 -0400 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 41BB1C0094CE; Mon, 20 Mar 2017 12:55:51 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-26.ams2.redhat.com [10.36.116.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D3AA089F6D; Mon, 20 Mar 2017 12:55:50 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 51C661138650; Mon, 20 Mar 2017 13:55:48 +0100 (CET) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 41BB1C0094CE Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=armbru@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 41BB1C0094CE From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 20 Mar 2017 13:55:46 +0100 Message-Id: <1490014548-15083-4-git-send-email-armbru@redhat.com> In-Reply-To: <1490014548-15083-1-git-send-email-armbru@redhat.com> References: <1490014548-15083-1-git-send-email-armbru@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.32]); Mon, 20 Mar 2017 12:55:51 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-2.9 3/5] test-keyval: Cover alternate and 'any' type X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- tests/Makefile.include | 2 +- tests/test-keyval.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/tests/Makefile.include b/tests/Makefile.include index 402e71c..86f9490 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -736,7 +736,7 @@ tests/vhost-user-test$(EXESUF): tests/vhost-user-test.o= $(test-util-obj-y) \ $(chardev-obj-y) tests/qemu-iotests/socket_scm_helper$(EXESUF): tests/qemu-iotests/socket_s= cm_helper.o tests/test-qemu-opts$(EXESUF): tests/test-qemu-opts.o $(test-util-obj-y) -tests/test-keyval$(EXESUF): tests/test-keyval.o $(test-util-obj-y) +tests/test-keyval$(EXESUF): tests/test-keyval.o $(test-util-obj-y) $(test-= qapi-obj-y) tests/test-write-threshold$(EXESUF): tests/test-write-threshold.o $(test-b= lock-obj-y) tests/test-netfilter$(EXESUF): tests/test-netfilter.o $(qtest-obj-y) tests/test-filter-mirror$(EXESUF): tests/test-filter-mirror.o $(qtest-obj-= y) diff --git a/tests/test-keyval.c b/tests/test-keyval.c index e97f6d5..ba19560 100644 --- a/tests/test-keyval.c +++ b/tests/test-keyval.c @@ -14,6 +14,7 @@ #include "qapi/error.h" #include "qapi/qmp/qstring.h" #include "qapi/qobject-input-visitor.h" +#include "test-qapi-visit.h" #include "qemu/cutils.h" #include "qemu/option.h" =20 @@ -608,6 +609,56 @@ static void test_keyval_visit_optional(void) visit_free(v); } =20 +static void test_keyval_visit_alternate(void) +{ + Error *err =3D NULL; + Visitor *v; + QDict *qdict; + AltNumStr *ans; + AltNumInt *ani; + + /* + * Can't do scalar alternate variants other than string. You get + * the string variant if there is one, else an error. + */ + qdict =3D keyval_parse("a=3D1,b=3D2", NULL, &error_abort); + v =3D qobject_input_visitor_new_keyval(QOBJECT(qdict)); + QDECREF(qdict); + visit_start_struct(v, NULL, NULL, 0, &error_abort); + visit_type_AltNumStr(v, "a", &ans, &error_abort); + g_assert_cmpint(ans->type, =3D=3D, QTYPE_QSTRING); + g_assert_cmpstr(ans->u.s, =3D=3D, "1"); + visit_type_AltNumInt(v, "a", &ani, &err); + error_free_or_abort(&err); + visit_end_struct(v, NULL); + visit_free(v); +} + +static void test_keyval_visit_any(void) +{ + Visitor *v; + QDict *qdict; + QObject *any; + QList *qlist; + QString *qstr; + + qdict =3D keyval_parse("a.0=3Dnull,a.1=3D1", NULL, &error_abort); + v =3D qobject_input_visitor_new_keyval(QOBJECT(qdict)); + QDECREF(qdict); + visit_start_struct(v, NULL, NULL, 0, &error_abort); + visit_type_any(v, "a", &any, &error_abort); + qlist =3D qobject_to_qlist(any); + g_assert(qlist); + qstr =3D qobject_to_qstring(qlist_pop(qlist)); + g_assert_cmpstr(qstring_get_str(qstr), =3D=3D, "null"); + qstr =3D qobject_to_qstring(qlist_pop(qlist)); + g_assert_cmpstr(qstring_get_str(qstr), =3D=3D, "1"); + g_assert(qlist_empty(qlist)); + visit_check_struct(v, &error_abort); + visit_end_struct(v, NULL); + visit_free(v); +} + int main(int argc, char *argv[]) { g_test_init(&argc, &argv, NULL); @@ -619,6 +670,8 @@ int main(int argc, char *argv[]) g_test_add_func("/keyval/visit/dict", test_keyval_visit_dict); g_test_add_func("/keyval/visit/list", test_keyval_visit_list); g_test_add_func("/keyval/visit/optional", test_keyval_visit_optional); + g_test_add_func("/keyval/visit/alternate", test_keyval_visit_alternate= ); + g_test_add_func("/keyval/visit/any", test_keyval_visit_any); g_test_run(); return 0; } --=20 2.7.4