From nobody Sun Feb 8 17:22:12 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 1488703764321584.477184049756; Sun, 5 Mar 2017 00:49:24 -0800 (PST) Received: from localhost ([::1]:37997 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ckRr0-0001uc-Hb for importer@patchew.org; Sun, 05 Mar 2017 03:49:22 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45699) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ckReC-0000Ow-3E for qemu-devel@nongnu.org; Sun, 05 Mar 2017 03:36:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ckRe9-0002zq-DP for qemu-devel@nongnu.org; Sun, 05 Mar 2017 03:36:08 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42578) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ckRe8-0002ye-TG for qemu-devel@nongnu.org; Sun, 05 Mar 2017 03:36:05 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 14EFF81231 for ; Sun, 5 Mar 2017 08:36:05 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-55.ams2.redhat.com [10.36.116.55]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v258a3Dx022785 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Sun, 5 Mar 2017 03:36:04 -0500 Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id AA790113861F; Sun, 5 Mar 2017 09:35:58 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Sun, 5 Mar 2017 09:35:52 +0100 Message-Id: <1488702958-24336-22-git-send-email-armbru@redhat.com> In-Reply-To: <1488702958-24336-1-git-send-email-armbru@redhat.com> References: <1488702958-24336-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Sun, 05 Mar 2017 08:36:05 +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] [PULL v2 21/27] test-string-input-visitor: Improve list coverage 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: , 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" Lists with elements above INT64_MAX don't work (known bug). Empty lists don't work (weird). Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Message-Id: <1488544368-30622-23-git-send-email-armbru@redhat.com> --- tests/test-string-input-visitor.c | 85 +++++++++++++++++++++++++++++++++--= ---- 1 file changed, 72 insertions(+), 13 deletions(-) diff --git a/tests/test-string-input-visitor.c b/tests/test-string-input-vi= sitor.c index a32828c..72f8732 100644 --- a/tests/test-string-input-visitor.c +++ b/tests/test-string-input-visitor.c @@ -65,31 +65,90 @@ static void test_visitor_in_int(TestInputVisitorData *d= ata, error_free_or_abort(&err); } =20 +static void check_ilist(Visitor *v, int64_t *expected, size_t n) +{ + int64List *res =3D NULL; + int64List *tail; + int i; + + visit_type_int64List(v, NULL, &res, &error_abort); + tail =3D res; + for (i =3D 0; i < n; i++) { + g_assert(tail); + g_assert_cmpint(tail->value, =3D=3D, expected[i]); + tail =3D tail->next; + } + g_assert(!tail); + + qapi_free_int64List(res); +} + +static void check_ulist(Visitor *v, uint64_t *expected, size_t n) +{ + uint64List *res =3D NULL; + uint64List *tail; + int i; + + /* BUG: unsigned numbers above INT64_MAX don't work */ + for (i =3D 0; i < n; i++) { + if (expected[i] > INT64_MAX) { + Error *err =3D NULL; + visit_type_uint64List(v, NULL, &res, &err); + error_free_or_abort(&err); + return; + } + } + + visit_type_uint64List(v, NULL, &res, &error_abort); + tail =3D res; + for (i =3D 0; i < n; i++) { + g_assert(tail); + g_assert_cmpuint(tail->value, =3D=3D, expected[i]); + tail =3D tail->next; + } + g_assert(!tail); + + qapi_free_uint64List(res); +} + static void test_visitor_in_intList(TestInputVisitorData *data, const void *unused) { - int64_t value[] =3D {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 20}; - int16List *res =3D NULL, *tmp; + /* Note: the visitor *sorts* ranges *unsigned* */ + int64_t expect1[] =3D { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 20 }; + int64_t expect2[] =3D { 32767, -32768, -32767 }; + int64_t expect3[] =3D { INT64_MAX, INT64_MIN }; + uint64_t expect4[] =3D { UINT64_MAX }; Error *err =3D NULL; + int64List *res =3D NULL; Visitor *v; - int i =3D 0; + + /* Valid lists */ =20 v =3D visitor_input_test_init(data, "1,2,0,2-4,20,5-9,1-8"); + check_ilist(v, expect1, ARRAY_SIZE(expect1)); =20 - visit_type_int16List(v, NULL, &res, &error_abort); - tmp =3D res; - while (i < sizeof(value) / sizeof(value[0])) { - g_assert(tmp); - g_assert_cmpint(tmp->value, =3D=3D, value[i++]); - tmp =3D tmp->next; - } - g_assert(!tmp); + v =3D visitor_input_test_init(data, "32767,-32768--32767"); + check_ilist(v, expect2, ARRAY_SIZE(expect2)); =20 - qapi_free_int16List(res); + v =3D visitor_input_test_init(data, + "-9223372036854775808,9223372036854775807"= ); + check_ilist(v, expect3, ARRAY_SIZE(expect3)); + + v =3D visitor_input_test_init(data, "18446744073709551615"); + check_ulist(v, expect4, ARRAY_SIZE(expect4)); + + /* Empty list is invalid (weird) */ + + v =3D visitor_input_test_init(data, ""); + visit_type_int64List(v, NULL, &res, &err); + error_free_or_abort(&err); + + /* Not a list */ =20 v =3D visitor_input_test_init(data, "not an int list"); =20 - visit_type_int16List(v, NULL, &res, &err); + visit_type_int64List(v, NULL, &res, &err); error_free_or_abort(&err); g_assert(!res); } --=20 2.7.4