aboutsummaryrefslogtreecommitdiff
path: root/tests/unit/check-qlist.c
diff options
context:
space:
mode:
authorThomas Huth <thuth@redhat.com>2021-03-10 07:33:14 +0100
committerThomas Huth <thuth@redhat.com>2021-03-12 15:46:30 +0100
commitda668aa15b99150a8595c491aee00d5d2426aaf9 (patch)
tree0463b0a303e807bdab46460f6c702be611bd7179 /tests/unit/check-qlist.c
parent363fc963054d8e82cfd55fa9b9aa130692a8dbd7 (diff)
tests: Move unit tests into a separate directory
The main tests directory still looks very crowded, and it's not clear which files are part of a unit tests and which belong to a different test subsystem. Let's clean up the mess and move the unit tests to a separate directory. Message-Id: <20210310063314.1049838-1-thuth@redhat.com> Acked-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Thomas Huth <thuth@redhat.com>
Diffstat (limited to 'tests/unit/check-qlist.c')
-rw-r--r--tests/unit/check-qlist.c103
1 files changed, 103 insertions, 0 deletions
diff --git a/tests/unit/check-qlist.c b/tests/unit/check-qlist.c
new file mode 100644
index 0000000000..3cd0ccbf19
--- /dev/null
+++ b/tests/unit/check-qlist.c
@@ -0,0 +1,103 @@
+/*
+ * 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 LGPL, version 2.1 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ */
+#include "qemu/osdep.h"
+
+#include "qapi/qmp/qnum.h"
+#include "qapi/qmp/qlist.h"
+
+/*
+ * Public Interface test-cases
+ *
+ * (with some violations to access 'private' data)
+ */
+
+static void qlist_new_test(void)
+{
+ QList *qlist;
+
+ qlist = qlist_new();
+ g_assert(qlist != NULL);
+ g_assert(qlist->base.refcnt == 1);
+ g_assert(qobject_type(QOBJECT(qlist)) == QTYPE_QLIST);
+
+ qobject_unref(qlist);
+}
+
+static void qlist_append_test(void)
+{
+ QNum *qi;
+ QList *qlist;
+ QListEntry *entry;
+
+ qi = qnum_from_int(42);
+
+ qlist = qlist_new();
+ qlist_append(qlist, qi);
+
+ entry = QTAILQ_FIRST(&qlist->head);
+ g_assert(entry != NULL);
+ g_assert(entry->value == QOBJECT(qi));
+
+ qobject_unref(qlist);
+}
+
+static void qobject_to_qlist_test(void)
+{
+ QList *qlist;
+
+ qlist = qlist_new();
+
+ g_assert(qobject_to(QList, QOBJECT(qlist)) == qlist);
+
+ qobject_unref(qlist);
+}
+
+static void qlist_iter_test(void)
+{
+ const int iter_max = 42;
+ int i;
+ QList *qlist;
+ QListEntry *entry;
+ QNum *qi;
+ int64_t val;
+
+ qlist = qlist_new();
+
+ for (i = 0; i < iter_max; i++)
+ qlist_append_int(qlist, i);
+
+ i = 0;
+ QLIST_FOREACH_ENTRY(qlist, entry) {
+ qi = qobject_to(QNum, qlist_entry_obj(entry));
+ g_assert(qi != NULL);
+
+ g_assert(qnum_get_try_int(qi, &val));
+ g_assert_cmpint(val, ==, i);
+ i++;
+ }
+
+ g_assert(i == iter_max);
+
+ qobject_unref(qlist);
+}
+
+int main(int argc, char **argv)
+{
+ g_test_init(&argc, &argv, NULL);
+
+ g_test_add_func("/public/new", qlist_new_test);
+ g_test_add_func("/public/append", qlist_append_test);
+ g_test_add_func("/public/to_qlist", qobject_to_qlist_test);
+ g_test_add_func("/public/iter", qlist_iter_test);
+
+ return g_test_run();
+}