From patchwork Thu Aug 13 13:50:26 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 31330 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 19349B6F2B for ; Fri, 14 Aug 2009 00:49:10 +1000 (EST) Received: from localhost ([127.0.0.1]:40214 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mbbc3-0000ul-37 for incoming@patchwork.ozlabs.org; Thu, 13 Aug 2009 10:49:07 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Mbais-0001Q8-KJ for qemu-devel@nongnu.org; Thu, 13 Aug 2009 09:52:07 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Mbain-0001J7-Go for qemu-devel@nongnu.org; Thu, 13 Aug 2009 09:52:03 -0400 Received: from [199.232.76.173] (port=33530 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mbain-0001J1-Br for qemu-devel@nongnu.org; Thu, 13 Aug 2009 09:52:01 -0400 Received: from mx2.redhat.com ([66.187.237.31]:45150) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Mbaim-0003Pw-2U for qemu-devel@nongnu.org; Thu, 13 Aug 2009 09:52:00 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n7DDpxH8023456; Thu, 13 Aug 2009 09:51:59 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n7DDpwJc027554; Thu, 13 Aug 2009 09:51:58 -0400 Received: from localhost (vpn-10-83.bos.redhat.com [10.16.10.83]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n7DDpu2W012284; Thu, 13 Aug 2009 09:51:57 -0400 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Thu, 13 Aug 2009 10:50:26 -0300 Message-Id: <1250171428-29308-28-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1250171428-29308-1-git-send-email-lcapitulino@redhat.com> References: <1250171428-29308-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.58 on 172.16.27.26 X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) Cc: aliguori@us.ibm.com, avi@redhat.com Subject: [Qemu-devel] [PATCH 27/29] Introduce QString unit-tests 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 This suite contains tests to assure that QString API works as expected. To execute it you should have check installed and build QEMU with check support enabled (--enable-check) and then run: $ ./check-qstring Signed-off-by: Luiz Capitulino --- Makefile | 1 + check-qstring.c | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ configure | 2 +- 3 files changed, 102 insertions(+), 1 deletions(-) create mode 100644 check-qstring.c diff --git a/Makefile b/Makefile index f97ae4c..6f111d1 100644 --- a/Makefile +++ b/Makefile @@ -183,6 +183,7 @@ qemu-img-cmds.h: $(SRC_PATH)/qemu-img-cmds.hx ifdef CONFIG_CHECK LIBS += $(CHECK_LIBS) check-qint: check-qint.o qint.o qemu-malloc.o +check-qstring: check-qstring.o qstring.o qemu-malloc.o endif clean: diff --git a/check-qstring.c b/check-qstring.c new file mode 100644 index 0000000..6903701 --- /dev/null +++ b/check-qstring.c @@ -0,0 +1,100 @@ +/* + * QString unit-tests. + * + * Copyright (C) 2009 Red Hat Inc. + * + * Authors: + * Luiz Capitulino + */ +#include + +#include "qstring.h" +#include "qemu-common.h" + +/* + * Public Interface test-cases + * + * (with some violations to access 'private' data) + */ + +START_TEST(qstring_from_str_test) +{ + QString *qstring; + const char *str = "QEMU"; + + qstring = qstring_from_str(str); + fail_unless(qstring != NULL); + fail_unless(qstring->base.refcnt == 1); + fail_unless(strcmp(str, qstring->string) == 0); + fail_unless(qobject_type(QOBJECT(qstring)) == QTYPE_QSTRING); + + // destroy doesn't exit yet + qemu_free(qstring->string); + qemu_free(qstring); +} +END_TEST + +START_TEST(qstring_destroy_test) +{ + QString *qstring = qstring_from_str("destroy test"); + qobject_decref(QOBJECT(qstring)); +} +END_TEST + +START_TEST(qstring_get_str_test) +{ + QString *qstring; + const char *ret_str; + const char *str = "QEMU/KVM"; + + qstring = qstring_from_str(str); + ret_str = qstring_get_str(qstring); + fail_unless(strcmp(ret_str, str) == 0); + + qobject_decref(QOBJECT(qstring)); +} +END_TEST + +START_TEST(qobject_to_qstring_test) +{ + QString *qstring; + + qstring = qstring_from_str("foo"); + fail_unless(qobject_to_qstring(QOBJECT(qstring)) == qstring); + + qobject_decref(QOBJECT(qstring)); +} +END_TEST + +static Suite *qstring_suite(void) +{ + Suite *s; + TCase *qstring_public_tcase; + + s = suite_create("QString test-suite"); + + qstring_public_tcase = tcase_create("Public Interface"); + suite_add_tcase(s, qstring_public_tcase); + tcase_add_test(qstring_public_tcase, qstring_from_str_test); + tcase_add_test(qstring_public_tcase, qstring_destroy_test); + tcase_add_test(qstring_public_tcase, qstring_get_str_test); + tcase_add_test(qstring_public_tcase, qobject_to_qstring_test); + + return s; +} + +int main(void) +{ + int nf; + Suite *s; + SRunner *sr; + + s = qstring_suite(); + sr = srunner_create(s); + + srunner_run_all(sr, CK_NORMAL); + nf = srunner_ntests_failed(sr); + srunner_free(sr); + + return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/configure b/configure index 8fbed8f..1a2634a 100755 --- a/configure +++ b/configure @@ -1783,7 +1783,7 @@ if test `expr "$target_list" : ".*softmmu.*"` != 0 ; then if [ "$linux" = "yes" ] ; then tools="qemu-nbd\$(EXESUF) qemu-io\$(EXESUF) $tools" if [ "$check" = "yes" ]; then - tools="check-qint $tools" + tools="check-qint check-qstring $tools" fi fi fi