From nobody Sat Sep 28 15:23:30 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1648052216; cv=none; d=zohomail.com; s=zohoarc; b=KoOjvJDBt3DczC/J4xgBPux24Ns0zAGkyjKfh89AXzY2FAEJELRzPqyH2/RVAssQV5ut+Sx45tRrLNM5nJZ0pscbRsSy/YasOu6ShzzSwMQJ1NIlnR2+fnaQ8Gd8vNktrzMu0yao7WrS+OuJlRYS4tVo9GUaPPucJdTj5HC9Vg4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1648052216; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=g2wl/WON0DnlIUHcKBeft4l6C8oe3AH31RxJEpQWvms=; b=GuXdWFX5q7kSLr1HQqbFtrJWG6YAh1fIf2PtpZjrrc0//ADtn5hDTX/bxHFiRYv2tM4kt+JwCO2KYqeNemzBbEennZ/lwbB4QjBFhJZ8yCeOZnLfymufEYp1cOMzahX4WRVbytk7l5T3doDv5TFdiXmgYi2vv6bVPv8vykXreBE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1648052216165508.0425285295436; Wed, 23 Mar 2022 09:16:56 -0700 (PDT) Received: from localhost ([::1]:52986 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nX3fK-0000T3-UJ for importer@patchew.org; Wed, 23 Mar 2022 12:16:54 -0400 Received: from eggs.gnu.org ([209.51.188.92]:38232) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nX3OV-00044B-6Q for qemu-devel@nongnu.org; Wed, 23 Mar 2022 11:59:32 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:42962) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nX3OT-0004wR-Gp for qemu-devel@nongnu.org; Wed, 23 Mar 2022 11:59:30 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-539--6dQW6_TNd2NzrNX4dO5ZQ-1; Wed, 23 Mar 2022 11:59:28 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9F7F818E0042 for ; Wed, 23 Mar 2022 15:59:27 +0000 (UTC) Received: from localhost (unknown [10.39.208.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4ABE1469A51; Wed, 23 Mar 2022 15:59:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1648051169; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=g2wl/WON0DnlIUHcKBeft4l6C8oe3AH31RxJEpQWvms=; b=U0D0yoTdpftfpm7RIwD6EP5ozm8xkx8OIMzyptCZREKAx/yO3HmOGEXLGTyUpW69Y/NnzX 09szpSBd1QuYvVtx3vH1oh94H4DtwQaNcjCmBiWp/Kfl6RswBKQxO1L3Wdsy4/2KW8XYLu hoZYU5iwqwcNjiQ4sdMlFAhPiTP88jo= X-MC-Unique: -6dQW6_TNd2NzrNX4dO5ZQ-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [PATCH 10/32] tests: replace free_all() usage with g_auto Date: Wed, 23 Mar 2022 19:57:21 +0400 Message-Id: <20220323155743.1585078-11-marcandre.lureau@redhat.com> In-Reply-To: <20220323155743.1585078-1-marcandre.lureau@redhat.com> References: <20220323155743.1585078-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=marcandre.lureau@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Markus Armbruster Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1648052217767100001 From: Marc-Andr=C3=A9 Lureau Use more idiomatic glib/auto-style code. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Richard Henderson --- tests/unit/check-qobject.c | 127 ++++++++++++------------------------- 1 file changed, 40 insertions(+), 87 deletions(-) diff --git a/tests/unit/check-qobject.c b/tests/unit/check-qobject.c index c3d50e99949a..7903ebf4cf80 100644 --- a/tests/unit/check-qobject.c +++ b/tests/unit/check-qobject.c @@ -74,21 +74,6 @@ static void do_test_equality(bool expected, int _, ...) #define check_unequal(...) \ do_test_equality(false, 0, __VA_ARGS__, &test_equality_end_of_argument= s) =20 -static void do_free_all(int _, ...) -{ - va_list ap; - QObject *obj; - - va_start(ap, _); - while ((obj =3D va_arg(ap, QObject *)) !=3D NULL) { - qobject_unref(obj); - } - va_end(ap); -} - -#define free_all(...) \ - do_free_all(0, __VA_ARGS__, NULL) - static void qobject_is_equal_null_test(void) { check_unequal(qnull(), NULL); @@ -96,15 +81,14 @@ static void qobject_is_equal_null_test(void) =20 static void qobject_is_equal_num_test(void) { - QNum *u0, *i0, *d0, *dnan, *um42, *im42, *dm42; + g_autoptr(QNum) u0 =3D qnum_from_uint(0u); + g_autoptr(QNum) i0 =3D qnum_from_int(0); + g_autoptr(QNum) d0 =3D qnum_from_double(0.0); + g_autoptr(QNum) dnan =3D qnum_from_double(NAN); + g_autoptr(QNum) um42 =3D qnum_from_uint((uint64_t)-42); + g_autoptr(QNum) im42 =3D qnum_from_int(-42); + g_autoptr(QNum) dm42 =3D qnum_from_double(-42.0); =20 - u0 =3D qnum_from_uint(0u); - i0 =3D qnum_from_int(0); - d0 =3D qnum_from_double(0.0); - dnan =3D qnum_from_double(NAN); - um42 =3D qnum_from_uint((uint64_t)-42); - im42 =3D qnum_from_int(-42); - dm42 =3D qnum_from_double(-42.0); =20 /* Integers representing a mathematically equal number should * compare equal */ @@ -121,60 +105,45 @@ static void qobject_is_equal_num_test(void) check_unequal(um42, im42); check_unequal(um42, dm42); check_unequal(im42, dm42); - - free_all(u0, i0, d0, dnan, um42, im42, dm42); } =20 static void qobject_is_equal_bool_test(void) { - QBool *btrue_0, *btrue_1, *bfalse_0, *bfalse_1; - - btrue_0 =3D qbool_from_bool(true); - btrue_1 =3D qbool_from_bool(true); - bfalse_0 =3D qbool_from_bool(false); - bfalse_1 =3D qbool_from_bool(false); + g_autoptr(QBool) btrue_0 =3D qbool_from_bool(true); + g_autoptr(QBool) btrue_1 =3D qbool_from_bool(true); + g_autoptr(QBool) bfalse_0 =3D qbool_from_bool(false); + g_autoptr(QBool) bfalse_1 =3D qbool_from_bool(false); =20 check_equal(btrue_0, btrue_1); check_equal(bfalse_0, bfalse_1); check_unequal(btrue_0, bfalse_0); - - free_all(btrue_0, btrue_1, bfalse_0, bfalse_1); } =20 static void qobject_is_equal_string_test(void) { - QString *str_base, *str_whitespace_0, *str_whitespace_1, *str_whitespa= ce_2; - QString *str_whitespace_3, *str_case, *str_built; - - str_base =3D qstring_from_str("foo"); - str_whitespace_0 =3D qstring_from_str(" foo"); - str_whitespace_1 =3D qstring_from_str("foo "); - str_whitespace_2 =3D qstring_from_str("foo\b"); - str_whitespace_3 =3D qstring_from_str("fooo\b"); - str_case =3D qstring_from_str("Foo"); - + g_autoptr(QString) str_base =3D qstring_from_str("foo"); + g_autoptr(QString) str_whitespace_0 =3D qstring_from_str(" foo"); + g_autoptr(QString) str_whitespace_1 =3D qstring_from_str("foo "); + g_autoptr(QString) str_whitespace_2 =3D qstring_from_str("foo\b"); + g_autoptr(QString) str_whitespace_3 =3D qstring_from_str("fooo\b"); + g_autoptr(QString) str_case =3D qstring_from_str("Foo"); /* Should yield "foo" */ - str_built =3D qstring_from_substr("buffoon", 3, 6); + g_autoptr(QString) str_built =3D qstring_from_substr("buffoon", 3, 6); =20 check_unequal(str_base, str_whitespace_0, str_whitespace_1, str_whitespace_2, str_whitespace_3, str_case); =20 check_equal(str_base, str_built); - - free_all(str_base, str_whitespace_0, str_whitespace_1, str_whitespace_= 2, - str_whitespace_3, str_case, str_built); } =20 static void qobject_is_equal_list_test(void) { - QList *list_0, *list_1, *list_cloned; - QList *list_reordered, *list_longer, *list_shorter; - - list_0 =3D qlist_new(); - list_1 =3D qlist_new(); - list_reordered =3D qlist_new(); - list_longer =3D qlist_new(); - list_shorter =3D qlist_new(); + g_autoptr(QList) list_0 =3D qlist_new(); + g_autoptr(QList) list_1 =3D qlist_new(); + g_autoptr(QList) list_reordered =3D qlist_new(); + g_autoptr(QList) list_longer =3D qlist_new(); + g_autoptr(QList) list_shorter =3D qlist_new(); + g_autoptr(QList) list_cloned =3D NULL; =20 qlist_append_int(list_0, 1); qlist_append_int(list_0, 2); @@ -205,26 +174,20 @@ static void qobject_is_equal_list_test(void) * itself */ qlist_append(list_0, qnum_from_double(NAN)); g_assert(qobject_is_equal(QOBJECT(list_0), QOBJECT(list_0)) =3D=3D fal= se); - - free_all(list_0, list_1, list_cloned, list_reordered, list_longer, - list_shorter); } =20 static void qobject_is_equal_dict_test(void) { - QDict *dict_0, *dict_1, *dict_cloned; - QDict *dict_different_key, *dict_different_value, *dict_different_null= _key; - QDict *dict_longer, *dict_shorter, *dict_nested; - QDict *dict_crumpled; - - dict_0 =3D qdict_new(); - dict_1 =3D qdict_new(); - dict_different_key =3D qdict_new(); - dict_different_value =3D qdict_new(); - dict_different_null_key =3D qdict_new(); - dict_longer =3D qdict_new(); - dict_shorter =3D qdict_new(); - dict_nested =3D qdict_new(); + g_autoptr(QDict) dict_cloned =3D NULL; + g_autoptr(QDict) dict_crumpled =3D NULL; + g_autoptr(QDict) dict_0 =3D qdict_new(); + g_autoptr(QDict) dict_1 =3D qdict_new(); + g_autoptr(QDict) dict_different_key =3D qdict_new(); + g_autoptr(QDict) dict_different_value =3D qdict_new(); + g_autoptr(QDict) dict_different_null_key =3D qdict_new(); + g_autoptr(QDict) dict_longer =3D qdict_new(); + g_autoptr(QDict) dict_shorter =3D qdict_new(); + g_autoptr(QDict) dict_nested =3D qdict_new(); =20 qdict_put_int(dict_0, "f.o", 1); qdict_put_int(dict_0, "bar", 2); @@ -284,31 +247,21 @@ static void qobject_is_equal_dict_test(void) * itself */ qdict_put(dict_0, "NaN", qnum_from_double(NAN)); g_assert(qobject_is_equal(QOBJECT(dict_0), QOBJECT(dict_0)) =3D=3D fal= se); - - free_all(dict_0, dict_1, dict_cloned, dict_different_key, - dict_different_value, dict_different_null_key, dict_longer, - dict_shorter, dict_nested, dict_crumpled); } =20 static void qobject_is_equal_conversion_test(void) { - QNum *u0, *i0, *d0; - QString *s0, *s_empty; - QBool *bfalse; - - u0 =3D qnum_from_uint(0u); - i0 =3D qnum_from_int(0); - d0 =3D qnum_from_double(0.0); - s0 =3D qstring_from_str("0"); - s_empty =3D qstring_new(); - bfalse =3D qbool_from_bool(false); + g_autoptr(QNum) u0 =3D qnum_from_uint(0u); + g_autoptr(QNum) i0 =3D qnum_from_int(0); + g_autoptr(QNum) d0 =3D qnum_from_double(0.0); + g_autoptr(QString) s0 =3D qstring_from_str("0"); + g_autoptr(QString) s_empty =3D qstring_new(); + g_autoptr(QBool) bfalse =3D qbool_from_bool(false); =20 /* No automatic type conversion */ check_unequal(u0, s0, s_empty, bfalse, qnull(), NULL); check_unequal(i0, s0, s_empty, bfalse, qnull(), NULL); check_unequal(d0, s0, s_empty, bfalse, qnull(), NULL); - - free_all(u0, i0, d0, s0, s_empty, bfalse); } =20 int main(int argc, char **argv) --=20 2.35.1.273.ge6ebfd0e8cbb