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"
15 #include "qapi/qmp/qint.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
);
33 // destroy doesn't exist yet
37 static void qlist_append_test(void)
43 qi
= qint_from_int(42);
46 qlist_append(qlist
, qi
);
48 entry
= QTAILQ_FIRST(&qlist
->head
);
49 g_assert(entry
!= NULL
);
50 g_assert(entry
->value
== QOBJECT(qi
));
52 // destroy doesn't exist yet
58 static void qobject_to_qlist_test(void)
64 g_assert(qobject_to_qlist(QOBJECT(qlist
)) == qlist
);
66 // destroy doesn't exist yet
70 static void qlist_destroy_test(void)
77 for (i
= 0; i
< 42; i
++)
78 qlist_append(qlist
, qint_from_int(i
));
83 static int iter_called
;
84 static const int iter_max
= 42;
86 static void iter_func(QObject
*obj
, void *opaque
)
90 g_assert(opaque
== NULL
);
92 qi
= qobject_to_qint(obj
);
94 g_assert((qint_get_int(qi
) >= 0) && (qint_get_int(qi
) <= iter_max
));
99 static void qlist_iter_test(void)
106 for (i
= 0; i
< iter_max
; i
++)
107 qlist_append(qlist
, qint_from_int(i
));
110 qlist_iter(qlist
, iter_func
, NULL
);
112 g_assert(iter_called
== iter_max
);
117 int main(int argc
, char **argv
)
119 g_test_init(&argc
, &argv
, NULL
);
121 g_test_add_func("/public/new", qlist_new_test
);
122 g_test_add_func("/public/append", qlist_append_test
);
123 g_test_add_func("/public/to_qlist", qobject_to_qlist_test
);
124 g_test_add_func("/public/destroy", qlist_destroy_test
);
125 g_test_add_func("/public/iter", qlist_iter_test
);