From nobody Thu Nov 6 20:29:54 2025 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 1487791972622942.7738830334191; Wed, 22 Feb 2017 11:32:52 -0800 (PST) Received: from localhost ([::1]:54935 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgceg-0004mn-6O for importer@patchew.org; Wed, 22 Feb 2017 14:32:50 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40704) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgcNY-0004gM-80 for qemu-devel@nongnu.org; Wed, 22 Feb 2017 14:15:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgcNT-0000fC-33 for qemu-devel@nongnu.org; Wed, 22 Feb 2017 14:15:08 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54268) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgcNS-0000eA-QA for qemu-devel@nongnu.org; Wed, 22 Feb 2017 14:15:03 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (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 08DC83A76B7 for ; Wed, 22 Feb 2017 19:15:03 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-55.ams2.redhat.com [10.36.116.55]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1MJF14N023306 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Wed, 22 Feb 2017 14:15:02 -0500 Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 70DB51138604; Wed, 22 Feb 2017 20:14:58 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Wed, 22 Feb 2017 20:14:54 +0100 Message-Id: <1487790898-24921-13-git-send-email-armbru@redhat.com> In-Reply-To: <1487790898-24921-1-git-send-email-armbru@redhat.com> References: <1487790898-24921-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 22 Feb 2017 19:15:03 +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 12/16] tests: Don't check qobject_type() before qobject_to_qint() 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" qobject_to_qint(obj) returns NULL when obj isn't a QInt. Check that instead of qobject_type(obj) =3D=3D QTYPE_QINT. Signed-off-by: Markus Armbruster Message-Id: <1487363905-9480-11-git-send-email-armbru@redhat.com> Reviewed-by: Eric Blake --- tests/check-qjson.c | 24 +++++------------------- tests/test-qobject-output-visitor.c | 28 ++++++++++++---------------- 2 files changed, 17 insertions(+), 35 deletions(-) diff --git a/tests/check-qjson.c b/tests/check-qjson.c index dd080a8..aab4e0a 100644 --- a/tests/check-qjson.c +++ b/tests/check-qjson.c @@ -884,19 +884,15 @@ static void simple_number(void) }; =20 for (i =3D 0; test_cases[i].encoded; i++) { - QObject *obj; QInt *qint; =20 - obj =3D qobject_from_json(test_cases[i].encoded); - g_assert(obj !=3D NULL); - g_assert(qobject_type(obj) =3D=3D QTYPE_QINT); - - qint =3D qobject_to_qint(obj); + qint =3D qobject_to_qint(qobject_from_json(test_cases[i].encoded)); + g_assert(qint); g_assert(qint_get_int(qint) =3D=3D test_cases[i].decoded); if (test_cases[i].skip =3D=3D 0) { QString *str; =20 - str =3D qobject_to_json(obj); + str =3D qobject_to_json(QOBJECT(qint)); g_assert(strcmp(qstring_get_str(str), test_cases[i].encoded) = =3D=3D 0); QDECREF(str); } @@ -952,22 +948,12 @@ static void vararg_number(void) long long value_ll =3D 0x2342342343LL; double valuef =3D 2.323423423; =20 - obj =3D qobject_from_jsonf("%d", value); - g_assert(obj !=3D NULL); - g_assert(qobject_type(obj) =3D=3D QTYPE_QINT); - - qint =3D qobject_to_qint(obj); + qint =3D qobject_to_qint(qobject_from_jsonf("%d", value)); g_assert(qint_get_int(qint) =3D=3D value); - QDECREF(qint); =20 - obj =3D qobject_from_jsonf("%lld", value_ll); - g_assert(obj !=3D NULL); - g_assert(qobject_type(obj) =3D=3D QTYPE_QINT); - - qint =3D qobject_to_qint(obj); + qint =3D qobject_to_qint(qobject_from_jsonf("%lld", value_ll)); g_assert(qint_get_int(qint) =3D=3D value_ll); - QDECREF(qint); =20 obj =3D qobject_from_jsonf("%f", valuef); diff --git a/tests/test-qobject-output-visitor.c b/tests/test-qobject-outpu= t-visitor.c index 3e34aa5..50b807e 100644 --- a/tests/test-qobject-output-visitor.c +++ b/tests/test-qobject-output-visitor.c @@ -58,13 +58,13 @@ static void test_visitor_out_int(TestOutputVisitorData = *data, const void *unused) { int64_t value =3D -42; - QObject *obj; + QInt *qint; =20 visit_type_int(data->ov, NULL, &value, &error_abort); =20 - obj =3D visitor_get(data); - g_assert(qobject_type(obj) =3D=3D QTYPE_QINT); - g_assert_cmpint(qint_get_int(qobject_to_qint(obj)), =3D=3D, value); + qint =3D qobject_to_qint(visitor_get(data)); + g_assert(qint); + g_assert_cmpint(qint_get_int(qint), =3D=3D, value); } =20 static void test_visitor_out_bool(TestOutputVisitorData *data, @@ -335,13 +335,12 @@ static void test_visitor_out_any(TestOutputVisitorDat= a *data, QBool *qbool; QString *qstring; QDict *qdict; - QObject *obj; =20 qobj =3D QOBJECT(qint_from_int(-42)); visit_type_any(data->ov, NULL, &qobj, &error_abort); - obj =3D visitor_get(data); - g_assert(qobject_type(obj) =3D=3D QTYPE_QINT); - g_assert_cmpint(qint_get_int(qobject_to_qint(obj)), =3D=3D, -42); + qint =3D qobject_to_qint(visitor_get(data)); + g_assert(qint); + g_assert_cmpint(qint_get_int(qint), =3D=3D, -42); qobject_decref(qobj); =20 visitor_reset(data); @@ -354,9 +353,7 @@ static void test_visitor_out_any(TestOutputVisitorData = *data, qobject_decref(qobj); qdict =3D qobject_to_qdict(visitor_get(data)); g_assert(qdict); - qobj =3D qdict_get(qdict, "integer"); - g_assert(qobj); - qint =3D qobject_to_qint(qobj); + qint =3D qobject_to_qint(qdict_get(qdict, "integer")); g_assert(qint); g_assert_cmpint(qint_get_int(qint), =3D=3D, -42); qobj =3D qdict_get(qdict, "boolean"); @@ -394,8 +391,8 @@ static void test_visitor_out_union_flat(TestOutputVisit= orData *data, static void test_visitor_out_alternate(TestOutputVisitorData *data, const void *unused) { - QObject *arg; UserDefAlternate *tmp; + QInt *qint; QString *qstr; QDict *qdict; =20 @@ -404,10 +401,9 @@ static void test_visitor_out_alternate(TestOutputVisit= orData *data, tmp->u.i =3D 42; =20 visit_type_UserDefAlternate(data->ov, NULL, &tmp, &error_abort); - arg =3D visitor_get(data); - - g_assert(qobject_type(arg) =3D=3D QTYPE_QINT); - g_assert_cmpint(qint_get_int(qobject_to_qint(arg)), =3D=3D, 42); + qint =3D qobject_to_qint(visitor_get(data)); + g_assert(qint); + g_assert_cmpint(qint_get_int(qint), =3D=3D, 42); =20 qapi_free_UserDefAlternate(tmp); =20 --=20 2.7.4