summaryrefslogtreecommitdiff
path: root/check-qfloat.c
diff options
context:
space:
mode:
authorAnthony Liguori <aliguori@us.ibm.com>2009-11-11 10:36:51 -0600
committerAnthony Liguori <aliguori@us.ibm.com>2009-11-17 08:49:38 -0600
commit9c9efb6b2962de5eec1cf0e394a96a55c36f714d (patch)
treec49ecc66d3ca51dc7f3ec170a7287d6dec89fa88 /check-qfloat.c
parentec072ced1e48cccbdd2275d7b910ad29efb0f2d0 (diff)
Add unit test for QFloat
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'check-qfloat.c')
-rw-r--r--check-qfloat.c81
1 files changed, 81 insertions, 0 deletions
diff --git a/check-qfloat.c b/check-qfloat.c
new file mode 100644
index 000000000..3758700cb
--- /dev/null
+++ b/check-qfloat.c
@@ -0,0 +1,81 @@
+/*
+ * QFloat unit-tests.
+ *
+ * Copyright (C) 2009 Red Hat Inc.
+ *
+ * Authors:
+ * Luiz Capitulino <lcapitulino@redhat.com>
+ *
+ * Copyright IBM, Corp. 2009
+ *
+ * Authors:
+ * Anthony Liguori <aliguori@us.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ *
+ */
+#include <check.h>
+
+#include "qfloat.h"
+#include "qemu-common.h"
+
+/*
+ * Public Interface test-cases
+ *
+ * (with some violations to access 'private' data)
+ */
+
+START_TEST(qfloat_from_double_test)
+{
+ QFloat *qf;
+ const double value = -42.23423;
+
+ qf = qfloat_from_double(value);
+ fail_unless(qf != NULL);
+ fail_unless(qf->value == value);
+ fail_unless(qf->base.refcnt == 1);
+ fail_unless(qobject_type(QOBJECT(qf)) == QTYPE_QFLOAT);
+
+ // destroy doesn't exit yet
+ qemu_free(qf);
+}
+END_TEST
+
+START_TEST(qfloat_destroy_test)
+{
+ QFloat *qf = qfloat_from_double(0.0);
+ QDECREF(qf);
+}
+END_TEST
+
+static Suite *qfloat_suite(void)
+{
+ Suite *s;
+ TCase *qfloat_public_tcase;
+
+ s = suite_create("QFloat test-suite");
+
+ qfloat_public_tcase = tcase_create("Public Interface");
+ suite_add_tcase(s, qfloat_public_tcase);
+ tcase_add_test(qfloat_public_tcase, qfloat_from_double_test);
+ tcase_add_test(qfloat_public_tcase, qfloat_destroy_test);
+
+ return s;
+}
+
+int main(void)
+{
+ int nf;
+ Suite *s;
+ SRunner *sr;
+
+ s = qfloat_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;
+}