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.
18 * Public Interface test-cases
20 * (with some violations to access 'private' data)
23 START_TEST(qlist_new_test
)
28 fail_unless(qlist
!= NULL
);
29 fail_unless(qlist
->base
.refcnt
== 1);
30 fail_unless(qobject_type(QOBJECT(qlist
)) == QTYPE_QLIST
);
32 // destroy doesn't exist yet
37 START_TEST(qlist_append_test
)
43 qi
= qint_from_int(42);
46 qlist_append(qlist
, qi
);
48 entry
= QTAILQ_FIRST(&qlist
->head
);
49 fail_unless(entry
!= NULL
);
50 fail_unless(entry
->value
== QOBJECT(qi
));
52 // destroy doesn't exist yet
59 START_TEST(qobject_to_qlist_test
)
65 fail_unless(qobject_to_qlist(QOBJECT(qlist
)) == qlist
);
67 // destroy doesn't exist yet
72 START_TEST(qlist_destroy_test
)
79 for (i
= 0; i
< 42; i
++)
80 qlist_append(qlist
, qint_from_int(i
));
86 static int iter_called
;
87 static const int iter_max
= 42;
89 static void iter_func(QObject
*obj
, void *opaque
)
93 fail_unless(opaque
== NULL
);
95 qi
= qobject_to_qint(obj
);
96 fail_unless(qi
!= NULL
);
97 fail_unless((qint_get_int(qi
) >= 0) && (qint_get_int(qi
) <= iter_max
));
102 START_TEST(qlist_iter_test
)
109 for (i
= 0; i
< iter_max
; i
++)
110 qlist_append(qlist
, qint_from_int(i
));
113 qlist_iter(qlist
, iter_func
, NULL
);
115 fail_unless(iter_called
== iter_max
);
121 static Suite
*QList_suite(void)
124 TCase
*qlist_public_tcase
;
126 s
= suite_create("QList suite");
128 qlist_public_tcase
= tcase_create("Public Interface");
129 suite_add_tcase(s
, qlist_public_tcase
);
130 tcase_add_test(qlist_public_tcase
, qlist_new_test
);
131 tcase_add_test(qlist_public_tcase
, qlist_append_test
);
132 tcase_add_test(qlist_public_tcase
, qobject_to_qlist_test
);
133 tcase_add_test(qlist_public_tcase
, qlist_destroy_test
);
134 tcase_add_test(qlist_public_tcase
, qlist_iter_test
);
146 sr
= srunner_create(s
);
148 srunner_run_all(sr
, CK_NORMAL
);
149 nf
= srunner_ntests_failed(sr
);
152 return (nf
== 0) ? EXIT_SUCCESS
: EXIT_FAILURE
;