[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 27/29] Introduce QString unit-tests
From: |
Luiz Capitulino |
Subject: |
[Qemu-devel] [PATCH 27/29] Introduce QString unit-tests |
Date: |
Fri, 28 Aug 2009 15:27:30 -0300 |
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-utests) and then run:
$ ./check-qstring
Signed-off-by: Luiz Capitulino <address@hidden>
---
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 d08df6c..6537f77 100644
--- a/Makefile
+++ b/Makefile
@@ -182,6 +182,7 @@ qemu-img-cmds.h: $(SRC_PATH)/qemu-img-cmds.hx
$(call quiet-command,sh $(SRC_PATH)/hxtool -h < $< > $@," GEN $@")
check-qint: check-qint.o qint.o qemu-malloc.o
+check-qstring: check-qstring.o qstring.o qemu-malloc.o
clean:
# avoid old build problems by removing potentially incorrect old files
diff --git a/check-qstring.c b/check-qstring.c
new file mode 100644
index 0000000..ea4dfd0
--- /dev/null
+++ b/check-qstring.c
@@ -0,0 +1,100 @@
+/*
+ * QString unit-tests.
+ *
+ * Copyright (C) 2009 Red Hat Inc.
+ *
+ * Authors:
+ * Luiz Capitulino <address@hidden>
+ */
+#include <check.h>
+
+#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");
+ QDECREF(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);
+
+ QDECREF(qstring);
+}
+END_TEST
+
+START_TEST(qobject_to_qstring_test)
+{
+ QString *qstring;
+
+ qstring = qstring_from_str("foo");
+ fail_unless(qobject_to_qstring(QOBJECT(qstring)) == qstring);
+
+ QDECREF(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 248cc0b..c2944c5 100755
--- a/configure
+++ b/configure
@@ -1927,7 +1927,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 $tools"
+ tools="check-qint check-qstring $tools"
fi
fi
fi
--
1.6.4.1.184.g2e117
- [Qemu-devel] [PATCH 19/29] monitor: Split monitor_handle_command(), (continued)
- [Qemu-devel] [PATCH 19/29] monitor: Split monitor_handle_command(), Luiz Capitulino, 2009/08/28
- [Qemu-devel] [PATCH 20/29] monitor: Drop unused macros, Luiz Capitulino, 2009/08/28
- [Qemu-devel] [PATCH 21/29] monitor: Drop str_allocated[], Luiz Capitulino, 2009/08/28
- [Qemu-devel] [PATCH 22/29] monitor: Drop args[] handling code, Luiz Capitulino, 2009/08/28
- [Qemu-devel] [PATCH 23/29] monitor: fail when 'i' type is greater than 32-bit, Luiz Capitulino, 2009/08/28
- [Qemu-devel] [PATCH 24/29] monitor: Update supported types documentation, Luiz Capitulino, 2009/08/28
- [Qemu-devel] [PATCH 25/29] Add check support, Luiz Capitulino, 2009/08/28
- [Qemu-devel] [PATCH 26/29] Introduce QInt unit-tests, Luiz Capitulino, 2009/08/28
- [Qemu-devel] [PATCH 27/29] Introduce QString unit-tests,
Luiz Capitulino <=
- [Qemu-devel] [PATCH 28/29] Introduce QDict test data file, Luiz Capitulino, 2009/08/28
- [Qemu-devel] [PATCH 29/29] Introduce QDict unit-tests, Luiz Capitulino, 2009/08/28