From patchwork Wed May 9 16:55:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 10390301 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5979A60318 for ; Wed, 9 May 2018 17:25:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 49A652851D for ; Wed, 9 May 2018 17:25:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3DFD628520; Wed, 9 May 2018 17:25:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id DA3FE2851D for ; Wed, 9 May 2018 17:25:37 +0000 (UTC) Received: from localhost ([::1]:57921 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGSqO-0003fV-NV for patchwork-qemu-devel@patchwork.kernel.org; Wed, 09 May 2018 13:25:36 -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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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); } +static void qdict_stringify_for_keyval_test(void) +{ + QDict *dict = 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")) == 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) g_test_add_func("/public/rename_keys", qdict_rename_keys_test); + 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);