From: Luiz Capitulino <lcapitulino@redhat.com>
To: qemu-devel@nongnu.org
Cc: aliguori@us.ibm.com, avi@redhat.com
Subject: [Qemu-devel] [PATCH 03/15] Introduce QList unit-tests
Date: Tue, 6 Oct 2009 21:27:00 -0300 [thread overview]
Message-ID: <1254875232-25012-4-git-send-email-lcapitulino@redhat.com> (raw)
In-Reply-To: <1254875232-25012-1-git-send-email-lcapitulino@redhat.com>
This suite contains tests to assure that QList API works as expected.
To execute it you should have check installed and build QEMU with
check support enabled (--enable-check-utests) and then run:
$ ./check-qlist
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
Makefile | 1 +
check-qlist.c | 153 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
configure | 2 +-
3 files changed, 155 insertions(+), 1 deletions(-)
create mode 100644 check-qlist.c
diff --git a/Makefile b/Makefile
index 17bcbe4..d96fb4b 100644
--- a/Makefile
+++ b/Makefile
@@ -187,6 +187,7 @@ qemu-img-cmds.h: $(SRC_PATH)/qemu-img-cmds.hx
check-qint: check-qint.o qint.o qemu-malloc.o
check-qstring: check-qstring.o qstring.o qemu-malloc.o
check-qdict: check-qdict.o qdict.o qint.o qstring.o qemu-malloc.o
+check-qlist: check-qlist.o qlist.o qint.o qemu-malloc.o
clean:
# avoid old build problems by removing potentially incorrect old files
diff --git a/check-qlist.c b/check-qlist.c
new file mode 100644
index 0000000..0117ef3
--- /dev/null
+++ b/check-qlist.c
@@ -0,0 +1,153 @@
+/*
+ * QList unit-tests.
+ *
+ * Copyright (C) 2009 Red Hat Inc.
+ *
+ * Authors:
+ * Luiz Capitulino <lcapitulino@redhat.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2. See
+ * the COPYING file in the top-level directory.
+ */
+#include <check.h>
+
+#include "qint.h"
+#include "qlist.h"
+
+/*
+ * Public Interface test-cases
+ *
+ * (with some violations to access 'private' data)
+ */
+
+START_TEST(qlist_new_test)
+{
+ QList *qlist;
+
+ qlist = qlist_new();
+ fail_unless(qlist != NULL);
+ fail_unless(qlist->base.refcnt == 1);
+ fail_unless(qobject_type(QOBJECT(qlist)) == QTYPE_QLIST);
+
+ // destroy doesn't exist yet
+ qemu_free(qlist);
+}
+END_TEST
+
+START_TEST(qlist_append_test)
+{
+ QInt *qi;
+ QList *qlist;
+ QListEntry *entry;
+
+ qi = qint_from_int(42);
+
+ qlist = qlist_new();
+ qlist_append(qlist, qi);
+
+ entry = QTAILQ_FIRST(&qlist->head);
+ fail_unless(entry != NULL);
+ fail_unless(entry->value == QOBJECT(qi));
+
+ // destroy doesn't exist yet
+ QDECREF(qi);
+ qemu_free(entry);
+ qemu_free(qlist);
+}
+END_TEST
+
+START_TEST(qobject_to_qlist_test)
+{
+ QList *qlist;
+
+ qlist = qlist_new();
+
+ fail_unless(qobject_to_qlist(QOBJECT(qlist)) == qlist);
+
+ // destroy doesn't exist yet
+ qemu_free(qlist);
+}
+END_TEST
+
+START_TEST(qlist_destroy_test)
+{
+ int i;
+ QList *qlist;
+
+ qlist = qlist_new();
+
+ for (i = 0; i < 42; i++)
+ qlist_append(qlist, qint_from_int(i));
+
+ QDECREF(qlist);
+}
+END_TEST
+
+static int iter_called;
+static const int iter_max = 42;
+
+static void iter_func(QObject *obj, void *opaque)
+{
+ QInt *qi;
+
+ 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(qlist_iter_test)
+{
+ int i;
+ QList *qlist;
+
+ qlist = qlist_new();
+
+ for (i = 0; i < iter_max; i++)
+ qlist_append(qlist, qint_from_int(i));
+
+ iter_called = 0;
+ qlist_iter(qlist, iter_func, NULL);
+
+ fail_unless(iter_called == iter_max);
+
+ QDECREF(qlist);
+}
+END_TEST
+
+static Suite *QList_suite(void)
+{
+ Suite *s;
+ TCase *qlist_public_tcase;
+
+ s = suite_create("QList suite");
+
+ qlist_public_tcase = tcase_create("Public Interface");
+ suite_add_tcase(s, qlist_public_tcase);
+ tcase_add_test(qlist_public_tcase, qlist_new_test);
+ tcase_add_test(qlist_public_tcase, qlist_append_test);
+ tcase_add_test(qlist_public_tcase, qobject_to_qlist_test);
+ tcase_add_test(qlist_public_tcase, qlist_destroy_test);
+ tcase_add_test(qlist_public_tcase, qlist_iter_test);
+
+ return s;
+}
+
+int main(void)
+{
+ int nf;
+ Suite *s;
+ SRunner *sr;
+
+ s = QList_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 ad04880..4ea5483 100755
--- a/configure
+++ b/configure
@@ -2017,7 +2017,7 @@ if test `expr "$target_list" : ".*softmmu.*"` != 0 ; then
if [ "$linux" = "yes" ] ; then
tools="qemu-nbd\$(EXESUF) qemu-io\$(EXESUF) $tools"
if [ "$check_utests" = "yes" ]; then
- tools="check-qint check-qstring check-qdict $tools"
+ tools="check-qint check-qstring check-qdict check-qlist $tools"
fi
elif test "$mingw32" = "yes" ; then
tools="qemu-io\$(EXESUF) $tools"
--
1.6.5.rc2.17.gdbc1b
next prev parent reply other threads:[~2009-10-07 0:27 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-10-07 0:26 [Qemu-devel] [PATCH v2 00/15]: Initial QObject conversion Luiz Capitulino
2009-10-07 0:26 ` [Qemu-devel] [PATCH 01/15] QObject: Accept NULL Luiz Capitulino
2009-10-07 0:26 ` [Qemu-devel] [PATCH 02/15] Introduce QList Luiz Capitulino
2009-10-07 1:37 ` [Qemu-devel] " Anthony Liguori
2009-10-07 12:48 ` Luiz Capitulino
2009-10-07 0:27 ` Luiz Capitulino [this message]
2009-10-07 0:27 ` [Qemu-devel] [PATCH 04/15] monitor: Add user_print() to mon_cmd_t Luiz Capitulino
2009-10-07 1:40 ` [Qemu-devel] " Anthony Liguori
2009-10-07 12:52 ` Luiz Capitulino
2009-10-07 0:27 ` [Qemu-devel] [PATCH 05/15] monitor: Handle new and old style handlers Luiz Capitulino
2009-10-07 1:42 ` [Qemu-devel] " Anthony Liguori
2009-10-07 12:54 ` Luiz Capitulino
2009-10-07 0:27 ` [Qemu-devel] [PATCH 06/15] monitor: do_info(): handle new and old info handlers Luiz Capitulino
2009-10-07 0:27 ` [Qemu-devel] [PATCH 07/15] monitor: Convert do_quit() do QObject Luiz Capitulino
2009-10-07 0:27 ` [Qemu-devel] [PATCH 08/15] monitor: Convert do_stop() to QObject Luiz Capitulino
2009-10-07 0:27 ` [Qemu-devel] [PATCH 09/15] monitor: Convert do_system_reset() " Luiz Capitulino
2009-10-07 0:27 ` [Qemu-devel] [PATCH 10/15] monitor: Convert do_system_powerdown() " Luiz Capitulino
2009-10-07 0:27 ` [Qemu-devel] [PATCH 11/15] monitor: Convert do_cont() " Luiz Capitulino
2009-10-07 0:27 ` [Qemu-devel] [PATCH 12/15] monitor: Convert do_balloon() " Luiz Capitulino
2009-10-07 0:27 ` [Qemu-devel] [PATCH 13/15] monitor: Convert do_info_version() " Luiz Capitulino
2009-10-07 0:27 ` [Qemu-devel] [PATCH 14/15] monitor: Convert do_info_balloon() " Luiz Capitulino
2009-10-07 0:27 ` [Qemu-devel] [PATCH 15/15] monitor: Convert do_info_cpus() " Luiz Capitulino
2009-10-07 1:46 ` [Qemu-devel] " Anthony Liguori
2009-10-07 13:04 ` Luiz Capitulino
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1254875232-25012-4-git-send-email-lcapitulino@redhat.com \
--to=lcapitulino@redhat.com \
--cc=aliguori@us.ibm.com \
--cc=avi@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).