From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:43534) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T1hrK-0007EA-4s for qemu-devel@nongnu.org; Wed, 15 Aug 2012 13:58:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T1hrH-0002gj-KP for qemu-devel@nongnu.org; Wed, 15 Aug 2012 13:58:21 -0400 Received: from mail-gh0-f173.google.com ([209.85.160.173]:40959) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T1hrH-0002gF-Er for qemu-devel@nongnu.org; Wed, 15 Aug 2012 13:58:19 -0400 Received: by mail-gh0-f173.google.com with SMTP id r17so2082866ghr.4 for ; Wed, 15 Aug 2012 10:58:19 -0700 (PDT) Sender: fluxion From: Michael Roth Date: Wed, 15 Aug 2012 12:57:00 -0500 Message-Id: <1345053420-29974-3-git-send-email-mdroth@linux.vnet.ibm.com> In-Reply-To: <1345053420-29974-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1345053420-29974-1-git-send-email-mdroth@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH for-1.2 v2 3/3] check-qjson: add test for large JSON objects List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: aliguori@us.ibm.com, armbru@redhat.com, lcapitulino@redhat.com 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..ef9b529 100644 --- a/tests/check-qjson.c +++ b/tests/check-qjson.c @@ -690,6 +690,58 @@ static void unterminated_literal(void) g_assert(obj == NULL); } +/* + * 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); +} + int main(int argc, char **argv) { g_test_init(&argc, &argv, NULL); @@ -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); -- 1.7.9.5