4 * Copyright (C) 2009 Red Hat Inc.
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/error.h"
15 #include "qapi/qmp/qnum.h"
16 #include "qapi/qmp/qlist.h"
19 * Public Interface test-cases
21 * (with some violations to access 'private' data)
24 static void qlist_new_test(void)
29 g_assert(qlist
!= NULL
);
30 g_assert(qlist
->base
.refcnt
== 1);
31 g_assert(qobject_type(QOBJECT(qlist
)) == QTYPE_QLIST
);
36 static void qlist_append_test(void)
42 qi
= qnum_from_int(42);
45 qlist_append(qlist
, qi
);
47 entry
= QTAILQ_FIRST(&qlist
->head
);
48 g_assert(entry
!= NULL
);
49 g_assert(entry
->value
== QOBJECT(qi
));
54 static void qobject_to_qlist_test(void)
60 g_assert(qobject_to_qlist(QOBJECT(qlist
)) == qlist
);
65 static int iter_called
;
66 static const int iter_max
= 42;
68 static void iter_func(QObject
*obj
, void *opaque
)
73 g_assert(opaque
== NULL
);
75 qi
= qobject_to_qnum(obj
);
78 g_assert(qnum_get_try_int(qi
, &val
));
79 g_assert_cmpint(val
, >=, 0);
80 g_assert_cmpint(val
, <=, iter_max
);
85 static void qlist_iter_test(void)
92 for (i
= 0; i
< iter_max
; i
++)
93 qlist_append_int(qlist
, i
);
96 qlist_iter(qlist
, iter_func
, NULL
);
98 g_assert(iter_called
== iter_max
);
103 int main(int argc
, char **argv
)
105 g_test_init(&argc
, &argv
, NULL
);
107 g_test_add_func("/public/new", qlist_new_test
);
108 g_test_add_func("/public/append", qlist_append_test
);
109 g_test_add_func("/public/to_qlist", qobject_to_qlist_test
);
110 g_test_add_func("/public/iter", qlist_iter_test
);