From patchwork Tue Aug 21 17:05:50 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 179108 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 2B5B02C00A6 for ; Wed, 22 Aug 2012 03:08:01 +1000 (EST) Received: from localhost ([::1]:44319 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T3rvr-00014d-30 for incoming@patchwork.ozlabs.org; Tue, 21 Aug 2012 13:07:59 -0400 Received: from eggs.gnu.org ([208.118.235.92]:45664) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T3rue-0007lg-U5 for qemu-devel@nongnu.org; Tue, 21 Aug 2012 13:06:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T3rud-0002og-Rl for qemu-devel@nongnu.org; Tue, 21 Aug 2012 13:06:44 -0400 Received: from mail-gg0-f173.google.com ([209.85.161.173]:58041) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T3rud-0002fG-Lj for qemu-devel@nongnu.org; Tue, 21 Aug 2012 13:06:43 -0400 Received: by mail-gg0-f173.google.com with SMTP id a5so32818ggn.4 for ; Tue, 21 Aug 2012 10:06:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=t8ciGFcxKqi2peWvyKO7IK1bFBr0xU4gxn0n2Uva1P8=; b=sd2SoNKmkP9bVqYrtgskbhvI1CmYSR1Rnh56ibwW2kKirOEGNIiKHu8Oc5JR+EebL/ 1nd1CrICs2MGRe2+r13usaQlx41vzHeEgd4hbwPbpX5NVagHrRhCPpJLVOl8c+fSYyqb 7uCp34CdJUA6F4MAsay9oBfkJYtqz+RRj7oC3NvHNrC/NM8FTaGxmir6J2opdvy0Ariw sd9IqIwGQHaTo49WhhOh4/Yv75OpkHyzeo+d/2dhotPa8+39m+EnNu5aYBkC7Kw0d04Y CKy1nqFc6hBxnczgzeGdZOytFZK1PDy4gPoeiiaAWS/YDEk3hW+3BUNq9/pdtCb33WyI yDXw== Received: by 10.50.182.231 with SMTP id eh7mr13676302igc.42.1345568802974; Tue, 21 Aug 2012 10:06:42 -0700 (PDT) Received: from loki.morrigu.org (cpe-72-179-62-111.austin.res.rr.com. [72.179.62.111]) by mx.google.com with ESMTPS id xm2sm3717964igb.3.2012.08.21.10.06.41 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 21 Aug 2012 10:06:42 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Tue, 21 Aug 2012 12:05:50 -0500 Message-Id: <1345568757-14365-17-git-send-email-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1345568757-14365-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1345568757-14365-1-git-send-email-mdroth@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.161.173 Cc: aliguori@us.ibm.com Subject: [Qemu-devel] [PATCH 16/23] check-qjson: add test for large JSON objects X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Michael Roth Signed-off-by: Anthony Liguori (cherry picked from commit 7109edfeb69c1d3c2164175837784dfcd210fed0) Signed-off-by: Michael Roth --- tests/check-qjson.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/tests/check-qjson.c b/tests/check-qjson.c index 526e25e..3b896f5 100644 --- a/tests/check-qjson.c +++ b/tests/check-qjson.c @@ -466,6 +466,58 @@ static void simple_dict(void) } } +/* + * this generates json of the form: + * a(0,m) = [0, 1, ..., m-1] + * a(n,m) = { + * 'key0': a(0,m), + * 'key1': a(1,m), + * ... + * 'key(n-1)': a(n-1,m) + * } + */ +static void gen_test_json(GString *gstr, int nest_level_max, + int elem_count) +{ + int i; + + g_assert(gstr); + if (nest_level_max == 0) { + g_string_append(gstr, "["); + for (i = 0; i < elem_count; i++) { + g_string_append_printf(gstr, "%d", i); + if (i < elem_count - 1) { + g_string_append_printf(gstr, ", "); + } + } + g_string_append(gstr, "]"); + return; + } + + g_string_append(gstr, "{"); + for (i = 0; i < nest_level_max; i++) { + g_string_append_printf(gstr, "'key%d': ", i); + gen_test_json(gstr, i, elem_count); + if (i < nest_level_max - 1) { + g_string_append(gstr, ","); + } + } + g_string_append(gstr, "}"); +} + +static void large_dict(void) +{ + GString *gstr = g_string_new(""); + QObject *obj; + + gen_test_json(gstr, 10, 100); + obj = qobject_from_json(gstr->str); + g_assert(obj != NULL); + + qobject_decref(obj); + g_string_free(gstr, true); +} + static void simple_list(void) { int i; @@ -706,6 +758,7 @@ int main(int argc, char **argv) g_test_add_func("/literals/keyword", keyword_literal); g_test_add_func("/dicts/simple_dict", simple_dict); + g_test_add_func("/dicts/large_dict", large_dict); g_test_add_func("/lists/simple_list", simple_list); g_test_add_func("/whitespace/simple_whitespace", simple_whitespace);