From nobody Thu Oct 30 15:17:02 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.zohomail.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 152588707068069.53887074009754; Wed, 9 May 2018 10:31:10 -0700 (PDT) Received: from localhost ([::1]:57969 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGSvk-0000J9-Bh for importer@patchew.org; Wed, 09 May 2018 13:31:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59878) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGSNj-0003lJ-KY for qemu-devel@nongnu.org; Wed, 09 May 2018 12:56:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fGSNi-00075W-T6 for qemu-devel@nongnu.org; Wed, 09 May 2018 12:55:59 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:45194 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fGSNd-0006tG-95; Wed, 09 May 2018 12:55:53 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A62AE8010F67; Wed, 9 May 2018 16:55:52 +0000 (UTC) Received: from localhost (unknown [10.40.205.23]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5182610B2B4F; Wed, 9 May 2018 16:55:52 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Wed, 9 May 2018 18:55:27 +0200 Message-Id: <20180509165530.29561-11-mreitz@redhat.com> In-Reply-To: <20180509165530.29561-1-mreitz@redhat.com> References: <20180509165530.29561-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Wed, 09 May 2018 16:55:52 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Wed, 09 May 2018 16:55:52 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mreitz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH 10/13] tests: Add QDict clone-flatten test 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: Kevin Wolf , qemu-devel@nongnu.org, Markus Armbruster , Michael Roth , Max Reitz 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" This new test verifies that qdict_flatten() does not modify a shallow clone of the given QDict. Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- tests/check-qdict.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/check-qdict.c b/tests/check-qdict.c index ef5d17f815..7960b4a385 100644 --- a/tests/check-qdict.c +++ b/tests/check-qdict.c @@ -329,6 +329,38 @@ static void qdict_flatten_test(void) qobject_unref(dict3); } =20 +static void qdict_clone_flatten_test(void) +{ + QDict *dict1 =3D qdict_new(); + QDict *dict2 =3D qdict_new(); + QDict *cloned_dict1; + + /* + * Test that we can clone and flatten + * { "a": { "b": 42 } } + * without modifying the clone. + */ + + qdict_put_int(dict2, "b", 42); + qdict_put(dict1, "a", dict2); + + cloned_dict1 =3D qdict_clone_shallow(dict1); + + qdict_flatten(dict1); + + g_assert(qdict_size(dict1) =3D=3D 1); + g_assert(qdict_get_int(dict1, "a.b") =3D=3D 42); + + g_assert(qdict_size(cloned_dict1) =3D=3D 1); + g_assert(qdict_get_qdict(cloned_dict1, "a") =3D=3D dict2); + + g_assert(qdict_size(dict2) =3D=3D 1); + g_assert(qdict_get_int(dict2, "b") =3D=3D 42); + + qobject_unref(dict1); + qobject_unref(cloned_dict1); +} + static void qdict_array_split_test(void) { QDict *test_dict =3D qdict_new(); @@ -1045,6 +1077,7 @@ int main(int argc, char **argv) g_test_add_func("/public/to_qdict", qobject_to_qdict_test); g_test_add_func("/public/iterapi", qdict_iterapi_test); g_test_add_func("/public/flatten", qdict_flatten_test); + g_test_add_func("/public/clone-flatten", qdict_clone_flatten_test); g_test_add_func("/public/array_split", qdict_array_split_test); g_test_add_func("/public/array_entries", qdict_array_entries_test); g_test_add_func("/public/join", qdict_join_test); --=20 2.14.3