From patchwork Tue Oct 13 16:56:59 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 35874 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id BEB3CB7B9E for ; Wed, 14 Oct 2009 04:01:19 +1100 (EST) Received: from localhost ([127.0.0.1]:34760 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MxkkO-0006Et-QI for incoming@patchwork.ozlabs.org; Tue, 13 Oct 2009 13:01:16 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Mxkgr-00044o-Qd for qemu-devel@nongnu.org; Tue, 13 Oct 2009 12:57:38 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Mxkgm-0003yT-Pv for qemu-devel@nongnu.org; Tue, 13 Oct 2009 12:57:36 -0400 Received: from [199.232.76.173] (port=51961 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mxkgm-0003xw-Dp for qemu-devel@nongnu.org; Tue, 13 Oct 2009 12:57:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:23783) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Mxkgl-00023E-VA for qemu-devel@nongnu.org; Tue, 13 Oct 2009 12:57:32 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n9DGvU4i012679; Tue, 13 Oct 2009 12:57:31 -0400 Received: from localhost (vpn-13-167.rdu.redhat.com [10.11.13.167]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n9DGvTvZ013298; Tue, 13 Oct 2009 12:57:30 -0400 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Tue, 13 Oct 2009 13:56:59 -0300 Message-Id: <1255453026-18637-3-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1255453026-18637-1-git-send-email-lcapitulino@redhat.com> References: <1255453026-18637-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: aliguori@us.ibm.com, kraxel@redhat.com Subject: [Qemu-devel] [PATCH 2/9] check-qdict: Add test for qdict_iter() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Luiz Capitulino --- check-qdict.c | 35 +++++++++++++++++++++++++++++++++++ 1 files changed, 35 insertions(+), 0 deletions(-) diff --git a/check-qdict.c b/check-qdict.c index c37d448..c80ff22 100644 --- a/check-qdict.c +++ b/check-qdict.c @@ -191,6 +191,40 @@ START_TEST(qobject_to_qdict_test) } END_TEST +static int iter_called; +static const int iter_max = 42; + +static void iter_func(const char *key, QObject *obj, void *opaque) +{ + QInt *qi; + + fail_unless(key != NULL); + fail_unless(strstr(key, "key_") != NULL); + fail_unless(opaque == NULL), + + qi = qobject_to_qint(obj); + fail_unless(qi != NULL); + fail_unless((qint_get_int(qi) >= 0) && (qint_get_int(qi) <= iter_max)); + + iter_called++; +} + +START_TEST(qdict_iter_test) +{ + int i; + + for (i = 0; i < iter_max; i++) { + char key[12]; + sprintf(key, "key_%d", i); + qdict_put(tests_dict, key, qint_from_int(i)); + } + + iter_called = 0; + qdict_iter(tests_dict, iter_func, NULL); + fail_unless(iter_called == iter_max, "%d\n", iter_called); +} +END_TEST + /* * Errors test-cases */ @@ -333,6 +367,7 @@ static Suite *qdict_suite(void) tcase_add_test(qdict_public2_tcase, qdict_haskey_test); tcase_add_test(qdict_public2_tcase, qdict_del_test); tcase_add_test(qdict_public2_tcase, qobject_to_qdict_test); + tcase_add_test(qdict_public2_tcase, qdict_iter_test); qdict_errors_tcase = tcase_create("Errors"); suite_add_tcase(s, qdict_errors_tcase);