block/io: fix bdrv_co_block_status_above
[qemu/ar7.git] / tests / check-qlist.c
blob3cd0ccbf198d064ff50cb7538b5f8d85fabcc061
1 /*
2 * QList unit-tests.
4 * Copyright (C) 2009 Red Hat Inc.
6 * Authors:
7 * Luiz Capitulino <lcapitulino@redhat.com>
9 * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
10 * See the COPYING.LIB file in the top-level directory.
12 #include "qemu/osdep.h"
14 #include "qapi/qmp/qnum.h"
15 #include "qapi/qmp/qlist.h"
18 * Public Interface test-cases
20 * (with some violations to access 'private' data)
23 static void qlist_new_test(void)
25 QList *qlist;
27 qlist = qlist_new();
28 g_assert(qlist != NULL);
29 g_assert(qlist->base.refcnt == 1);
30 g_assert(qobject_type(QOBJECT(qlist)) == QTYPE_QLIST);
32 qobject_unref(qlist);
35 static void qlist_append_test(void)
37 QNum *qi;
38 QList *qlist;
39 QListEntry *entry;
41 qi = qnum_from_int(42);
43 qlist = qlist_new();
44 qlist_append(qlist, qi);
46 entry = QTAILQ_FIRST(&qlist->head);
47 g_assert(entry != NULL);
48 g_assert(entry->value == QOBJECT(qi));
50 qobject_unref(qlist);
53 static void qobject_to_qlist_test(void)
55 QList *qlist;
57 qlist = qlist_new();
59 g_assert(qobject_to(QList, QOBJECT(qlist)) == qlist);
61 qobject_unref(qlist);
64 static void qlist_iter_test(void)
66 const int iter_max = 42;
67 int i;
68 QList *qlist;
69 QListEntry *entry;
70 QNum *qi;
71 int64_t val;
73 qlist = qlist_new();
75 for (i = 0; i < iter_max; i++)
76 qlist_append_int(qlist, i);
78 i = 0;
79 QLIST_FOREACH_ENTRY(qlist, entry) {
80 qi = qobject_to(QNum, qlist_entry_obj(entry));
81 g_assert(qi != NULL);
83 g_assert(qnum_get_try_int(qi, &val));
84 g_assert_cmpint(val, ==, i);
85 i++;
88 g_assert(i == iter_max);
90 qobject_unref(qlist);
93 int main(int argc, char **argv)
95 g_test_init(&argc, &argv, NULL);
97 g_test_add_func("/public/new", qlist_new_test);
98 g_test_add_func("/public/append", qlist_append_test);
99 g_test_add_func("/public/to_qlist", qobject_to_qlist_test);
100 g_test_add_func("/public/iter", qlist_iter_test);
102 return g_test_run();