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 1525886764825563.4995654796039; Wed, 9 May 2018 10:26:04 -0700 (PDT) Received: from localhost ([::1]:57921 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGSqp-0003fV-Q3 for importer@patchew.org; Wed, 09 May 2018 13:26:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59807) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGSNc-0003dG-Ab for qemu-devel@nongnu.org; Wed, 09 May 2018 12:55:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fGSNb-0006pp-KW for qemu-devel@nongnu.org; Wed, 09 May 2018 12:55:52 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:45182 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 1fGSNZ-0006ly-7H; Wed, 09 May 2018 12:55:49 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 650E2818F6E3; Wed, 9 May 2018 16:55:48 +0000 (UTC) Received: from localhost (unknown [10.40.205.23]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1265AD7B0F; Wed, 9 May 2018 16:55:47 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Wed, 9 May 2018 18:55:25 +0200 Message-Id: <20180509165530.29561-9-mreitz@redhat.com> In-Reply-To: <20180509165530.29561-1-mreitz@redhat.com> References: <20180509165530.29561-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 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:48 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Wed, 09 May 2018 16:55:48 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.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 08/13] tests: Add qdict_stringify_for_keyval() 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" Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- tests/check-qdict.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 54 insertions(+) diff --git a/tests/check-qdict.c b/tests/check-qdict.c index 93e2112b6d..ef5d17f815 100644 --- a/tests/check-qdict.c +++ b/tests/check-qdict.c @@ -973,6 +973,57 @@ static void qdict_stress_test(void) qobject_unref(qdict); } =20 +static void qdict_stringify_for_keyval_test(void) +{ + QDict *dict =3D qdict_new(); + + /* + * Test stringification of: + * + * { + * "a": "null", + * "b": 42, + * "c": -23, + * "d": false, + * "e": null, + * "f": "", + * "g": 0.5, + * "h": 0xffffffffffffffff, + * "i": true, + * "j": 0 + * } + * + * Note that null is not transformed into a string and remains a + * QNull. + */ + + qdict_put_str(dict, "a", "null"); + qdict_put_int(dict, "b", 42); + qdict_put_int(dict, "c", -23); + qdict_put_bool(dict, "d", false); + qdict_put_null(dict, "e"); + qdict_put_str(dict, "f", ""); + qdict_put(dict, "g", qnum_from_double(0.5)); + qdict_put(dict, "h", qnum_from_uint(0xffffffffffffffffull)); + qdict_put_bool(dict, "i", true); + qdict_put_int(dict, "j", 0); + + qdict_stringify_for_keyval(dict); + + g_assert(!strcmp(qdict_get_str(dict, "a"), "null")); + g_assert(!strcmp(qdict_get_str(dict, "b"), "42")); + g_assert(!strcmp(qdict_get_str(dict, "c"), "-23")); + g_assert(!strcmp(qdict_get_str(dict, "d"), "off")); + g_assert(qobject_type(qdict_get(dict, "e")) =3D=3D QTYPE_QNULL); + g_assert(!strcmp(qdict_get_str(dict, "f"), "")); + g_assert(!strcmp(qdict_get_str(dict, "g"), "0.5")); + g_assert(!strcmp(qdict_get_str(dict, "h"), "18446744073709551615")); + g_assert(!strcmp(qdict_get_str(dict, "i"), "on")); + g_assert(!strcmp(qdict_get_str(dict, "j"), "0")); + + qobject_unref(dict); +} + int main(int argc, char **argv) { g_test_init(&argc, &argv, NULL); @@ -1010,6 +1061,9 @@ int main(int argc, char **argv) =20 g_test_add_func("/public/rename_keys", qdict_rename_keys_test); =20 + g_test_add_func("/public/stringify_for_keyval", + qdict_stringify_for_keyval_test); + /* The Big one */ if (g_test_slow()) { g_test_add_func("/stress/test", qdict_stress_test); --=20 2.14.3