root / check-qdict.c @ 1bb62099
History | View | Annotate | Download (7.9 kB)
1 | 7b8c51ad | Luiz Capitulino | /*
|
---|---|---|---|
2 | 7b8c51ad | Luiz Capitulino | * QDict unit-tests.
|
3 | 7b8c51ad | Luiz Capitulino | *
|
4 | 7b8c51ad | Luiz Capitulino | * Copyright (C) 2009 Red Hat Inc.
|
5 | 7b8c51ad | Luiz Capitulino | *
|
6 | 7b8c51ad | Luiz Capitulino | * Authors:
|
7 | 7b8c51ad | Luiz Capitulino | * Luiz Capitulino <lcapitulino@redhat.com>
|
8 | 7b8c51ad | Luiz Capitulino | */
|
9 | 7b8c51ad | Luiz Capitulino | #include <check.h> |
10 | 7b8c51ad | Luiz Capitulino | |
11 | 7b8c51ad | Luiz Capitulino | #include "qint.h" |
12 | 7b8c51ad | Luiz Capitulino | #include "qdict.h" |
13 | 7b8c51ad | Luiz Capitulino | #include "qstring.h" |
14 | 7b8c51ad | Luiz Capitulino | #include "qemu-common.h" |
15 | 7b8c51ad | Luiz Capitulino | |
16 | 7b8c51ad | Luiz Capitulino | /*
|
17 | 7b8c51ad | Luiz Capitulino | * Public Interface test-cases
|
18 | 7b8c51ad | Luiz Capitulino | *
|
19 | 7b8c51ad | Luiz Capitulino | * (with some violations to access 'private' data)
|
20 | 7b8c51ad | Luiz Capitulino | */
|
21 | 7b8c51ad | Luiz Capitulino | |
22 | 7b8c51ad | Luiz Capitulino | START_TEST(qdict_new_test) |
23 | 7b8c51ad | Luiz Capitulino | { |
24 | 7b8c51ad | Luiz Capitulino | QDict *qdict; |
25 | 7b8c51ad | Luiz Capitulino | |
26 | 7b8c51ad | Luiz Capitulino | qdict = qdict_new(); |
27 | 7b8c51ad | Luiz Capitulino | fail_unless(qdict != NULL);
|
28 | 7b8c51ad | Luiz Capitulino | fail_unless(qdict_size(qdict) == 0);
|
29 | 7b8c51ad | Luiz Capitulino | fail_unless(qdict->base.refcnt == 1);
|
30 | 7b8c51ad | Luiz Capitulino | fail_unless(qobject_type(QOBJECT(qdict)) == QTYPE_QDICT); |
31 | 7b8c51ad | Luiz Capitulino | |
32 | 7b8c51ad | Luiz Capitulino | // destroy doesn't exit yet
|
33 | 7b8c51ad | Luiz Capitulino | free(qdict); |
34 | 7b8c51ad | Luiz Capitulino | } |
35 | 7b8c51ad | Luiz Capitulino | END_TEST |
36 | 7b8c51ad | Luiz Capitulino | |
37 | 7b8c51ad | Luiz Capitulino | START_TEST(qdict_put_obj_test) |
38 | 7b8c51ad | Luiz Capitulino | { |
39 | 7b8c51ad | Luiz Capitulino | QInt *qi; |
40 | 7b8c51ad | Luiz Capitulino | QDict *qdict; |
41 | 7b8c51ad | Luiz Capitulino | QDictEntry *ent; |
42 | 7b8c51ad | Luiz Capitulino | const int num = 42; |
43 | 7b8c51ad | Luiz Capitulino | |
44 | 7b8c51ad | Luiz Capitulino | qdict = qdict_new(); |
45 | 7b8c51ad | Luiz Capitulino | |
46 | 7b8c51ad | Luiz Capitulino | // key "" will have tdb hash 12345
|
47 | 7b8c51ad | Luiz Capitulino | qdict_put_obj(qdict, "", QOBJECT(qint_from_int(num)));
|
48 | 7b8c51ad | Luiz Capitulino | |
49 | 7b8c51ad | Luiz Capitulino | fail_unless(qdict_size(qdict) == 1);
|
50 | 72cf2d4f | Blue Swirl | ent = QLIST_FIRST(&qdict->table[12345 % QDICT_HASH_SIZE]);
|
51 | 7b8c51ad | Luiz Capitulino | qi = qobject_to_qint(ent->value); |
52 | 7b8c51ad | Luiz Capitulino | fail_unless(qint_get_int(qi) == num); |
53 | 7b8c51ad | Luiz Capitulino | |
54 | 7b8c51ad | Luiz Capitulino | // destroy doesn't exit yet
|
55 | 7b8c51ad | Luiz Capitulino | QDECREF(qi); |
56 | 7b8c51ad | Luiz Capitulino | qemu_free(ent->key); |
57 | 7b8c51ad | Luiz Capitulino | qemu_free(ent); |
58 | 7b8c51ad | Luiz Capitulino | qemu_free(qdict); |
59 | 7b8c51ad | Luiz Capitulino | } |
60 | 7b8c51ad | Luiz Capitulino | END_TEST |
61 | 7b8c51ad | Luiz Capitulino | |
62 | 7b8c51ad | Luiz Capitulino | START_TEST(qdict_destroy_simple_test) |
63 | 7b8c51ad | Luiz Capitulino | { |
64 | 7b8c51ad | Luiz Capitulino | QDict *qdict; |
65 | 7b8c51ad | Luiz Capitulino | |
66 | 7b8c51ad | Luiz Capitulino | qdict = qdict_new(); |
67 | 7b8c51ad | Luiz Capitulino | qdict_put_obj(qdict, "num", QOBJECT(qint_from_int(0))); |
68 | 7b8c51ad | Luiz Capitulino | qdict_put_obj(qdict, "str", QOBJECT(qstring_from_str("foo"))); |
69 | 7b8c51ad | Luiz Capitulino | |
70 | 7b8c51ad | Luiz Capitulino | QDECREF(qdict); |
71 | 7b8c51ad | Luiz Capitulino | } |
72 | 7b8c51ad | Luiz Capitulino | END_TEST |
73 | 7b8c51ad | Luiz Capitulino | |
74 | 7b8c51ad | Luiz Capitulino | static QDict *tests_dict = NULL; |
75 | 7b8c51ad | Luiz Capitulino | |
76 | 7b8c51ad | Luiz Capitulino | static void qdict_setup(void) |
77 | 7b8c51ad | Luiz Capitulino | { |
78 | 7b8c51ad | Luiz Capitulino | tests_dict = qdict_new(); |
79 | 7b8c51ad | Luiz Capitulino | fail_unless(tests_dict != NULL);
|
80 | 7b8c51ad | Luiz Capitulino | } |
81 | 7b8c51ad | Luiz Capitulino | |
82 | 7b8c51ad | Luiz Capitulino | static void qdict_teardown(void) |
83 | 7b8c51ad | Luiz Capitulino | { |
84 | 7b8c51ad | Luiz Capitulino | QDECREF(tests_dict); |
85 | 7b8c51ad | Luiz Capitulino | tests_dict = NULL;
|
86 | 7b8c51ad | Luiz Capitulino | } |
87 | 7b8c51ad | Luiz Capitulino | |
88 | 7b8c51ad | Luiz Capitulino | START_TEST(qdict_get_test) |
89 | 7b8c51ad | Luiz Capitulino | { |
90 | 7b8c51ad | Luiz Capitulino | QInt *qi; |
91 | 7b8c51ad | Luiz Capitulino | QObject *obj; |
92 | 7b8c51ad | Luiz Capitulino | const int value = -42; |
93 | 7b8c51ad | Luiz Capitulino | const char *key = "test"; |
94 | 7b8c51ad | Luiz Capitulino | |
95 | 7b8c51ad | Luiz Capitulino | qdict_put(tests_dict, key, qint_from_int(value)); |
96 | 7b8c51ad | Luiz Capitulino | |
97 | 7b8c51ad | Luiz Capitulino | obj = qdict_get(tests_dict, key); |
98 | 7b8c51ad | Luiz Capitulino | fail_unless(obj != NULL);
|
99 | 7b8c51ad | Luiz Capitulino | |
100 | 7b8c51ad | Luiz Capitulino | qi = qobject_to_qint(obj); |
101 | 7b8c51ad | Luiz Capitulino | fail_unless(qint_get_int(qi) == value); |
102 | 7b8c51ad | Luiz Capitulino | } |
103 | 7b8c51ad | Luiz Capitulino | END_TEST |
104 | 7b8c51ad | Luiz Capitulino | |
105 | 7b8c51ad | Luiz Capitulino | START_TEST(qdict_get_int_test) |
106 | 7b8c51ad | Luiz Capitulino | { |
107 | 7b8c51ad | Luiz Capitulino | int ret;
|
108 | 7b8c51ad | Luiz Capitulino | const int value = 100; |
109 | 7b8c51ad | Luiz Capitulino | const char *key = "int"; |
110 | 7b8c51ad | Luiz Capitulino | |
111 | 7b8c51ad | Luiz Capitulino | qdict_put(tests_dict, key, qint_from_int(value)); |
112 | 7b8c51ad | Luiz Capitulino | |
113 | 7b8c51ad | Luiz Capitulino | ret = qdict_get_int(tests_dict, key); |
114 | 7b8c51ad | Luiz Capitulino | fail_unless(ret == value); |
115 | 7b8c51ad | Luiz Capitulino | } |
116 | 7b8c51ad | Luiz Capitulino | END_TEST |
117 | 7b8c51ad | Luiz Capitulino | |
118 | 7b8c51ad | Luiz Capitulino | START_TEST(qdict_get_try_int_test) |
119 | 7b8c51ad | Luiz Capitulino | { |
120 | 7b8c51ad | Luiz Capitulino | int ret;
|
121 | 7b8c51ad | Luiz Capitulino | const int value = 100; |
122 | 7b8c51ad | Luiz Capitulino | const char *key = "int"; |
123 | 7b8c51ad | Luiz Capitulino | |
124 | 7b8c51ad | Luiz Capitulino | qdict_put(tests_dict, key, qint_from_int(value)); |
125 | 7b8c51ad | Luiz Capitulino | |
126 | 7b8c51ad | Luiz Capitulino | ret = qdict_get_try_int(tests_dict, key, 0);
|
127 | 7b8c51ad | Luiz Capitulino | fail_unless(ret == value); |
128 | 7b8c51ad | Luiz Capitulino | } |
129 | 7b8c51ad | Luiz Capitulino | END_TEST |
130 | 7b8c51ad | Luiz Capitulino | |
131 | 7b8c51ad | Luiz Capitulino | START_TEST(qdict_get_str_test) |
132 | 7b8c51ad | Luiz Capitulino | { |
133 | 7b8c51ad | Luiz Capitulino | const char *p; |
134 | 7b8c51ad | Luiz Capitulino | const char *key = "key"; |
135 | 7b8c51ad | Luiz Capitulino | const char *str = "string"; |
136 | 7b8c51ad | Luiz Capitulino | |
137 | 7b8c51ad | Luiz Capitulino | qdict_put(tests_dict, key, qstring_from_str(str)); |
138 | 7b8c51ad | Luiz Capitulino | |
139 | 7b8c51ad | Luiz Capitulino | p = qdict_get_str(tests_dict, key); |
140 | 7b8c51ad | Luiz Capitulino | fail_unless(p != NULL);
|
141 | 7b8c51ad | Luiz Capitulino | fail_unless(strcmp(p, str) == 0);
|
142 | 7b8c51ad | Luiz Capitulino | } |
143 | 7b8c51ad | Luiz Capitulino | END_TEST |
144 | 7b8c51ad | Luiz Capitulino | |
145 | 7b8c51ad | Luiz Capitulino | START_TEST(qdict_get_try_str_test) |
146 | 7b8c51ad | Luiz Capitulino | { |
147 | 7b8c51ad | Luiz Capitulino | const char *p; |
148 | 7b8c51ad | Luiz Capitulino | const char *key = "key"; |
149 | 7b8c51ad | Luiz Capitulino | const char *str = "string"; |
150 | 7b8c51ad | Luiz Capitulino | |
151 | 7b8c51ad | Luiz Capitulino | qdict_put(tests_dict, key, qstring_from_str(str)); |
152 | 7b8c51ad | Luiz Capitulino | |
153 | 7b8c51ad | Luiz Capitulino | p = qdict_get_try_str(tests_dict, key); |
154 | 7b8c51ad | Luiz Capitulino | fail_unless(p != NULL);
|
155 | 7b8c51ad | Luiz Capitulino | fail_unless(strcmp(p, str) == 0);
|
156 | 7b8c51ad | Luiz Capitulino | } |
157 | 7b8c51ad | Luiz Capitulino | END_TEST |
158 | 7b8c51ad | Luiz Capitulino | |
159 | 7b8c51ad | Luiz Capitulino | START_TEST(qdict_haskey_not_test) |
160 | 7b8c51ad | Luiz Capitulino | { |
161 | 7b8c51ad | Luiz Capitulino | fail_unless(qdict_haskey(tests_dict, "test") == 0); |
162 | 7b8c51ad | Luiz Capitulino | } |
163 | 7b8c51ad | Luiz Capitulino | END_TEST |
164 | 7b8c51ad | Luiz Capitulino | |
165 | 7b8c51ad | Luiz Capitulino | START_TEST(qdict_haskey_test) |
166 | 7b8c51ad | Luiz Capitulino | { |
167 | 7b8c51ad | Luiz Capitulino | const char *key = "test"; |
168 | 7b8c51ad | Luiz Capitulino | |
169 | 7b8c51ad | Luiz Capitulino | qdict_put(tests_dict, key, qint_from_int(0));
|
170 | 7b8c51ad | Luiz Capitulino | fail_unless(qdict_haskey(tests_dict, key) == 1);
|
171 | 7b8c51ad | Luiz Capitulino | } |
172 | 7b8c51ad | Luiz Capitulino | END_TEST |
173 | 7b8c51ad | Luiz Capitulino | |
174 | 7b8c51ad | Luiz Capitulino | START_TEST(qdict_del_test) |
175 | 7b8c51ad | Luiz Capitulino | { |
176 | 7b8c51ad | Luiz Capitulino | const char *key = "key test"; |
177 | 7b8c51ad | Luiz Capitulino | |
178 | 7b8c51ad | Luiz Capitulino | qdict_put(tests_dict, key, qstring_from_str("foo"));
|
179 | 7b8c51ad | Luiz Capitulino | fail_unless(qdict_size(tests_dict) == 1);
|
180 | 7b8c51ad | Luiz Capitulino | |
181 | 7b8c51ad | Luiz Capitulino | qdict_del(tests_dict, key); |
182 | 7b8c51ad | Luiz Capitulino | |
183 | 7b8c51ad | Luiz Capitulino | fail_unless(qdict_size(tests_dict) == 0);
|
184 | 7b8c51ad | Luiz Capitulino | fail_unless(qdict_haskey(tests_dict, key) == 0);
|
185 | 7b8c51ad | Luiz Capitulino | } |
186 | 7b8c51ad | Luiz Capitulino | END_TEST |
187 | 7b8c51ad | Luiz Capitulino | |
188 | 7b8c51ad | Luiz Capitulino | START_TEST(qobject_to_qdict_test) |
189 | 7b8c51ad | Luiz Capitulino | { |
190 | 7b8c51ad | Luiz Capitulino | fail_unless(qobject_to_qdict(QOBJECT(tests_dict)) == tests_dict); |
191 | 7b8c51ad | Luiz Capitulino | } |
192 | 7b8c51ad | Luiz Capitulino | END_TEST |
193 | 7b8c51ad | Luiz Capitulino | |
194 | 7b8c51ad | Luiz Capitulino | /*
|
195 | 7b8c51ad | Luiz Capitulino | * Errors test-cases
|
196 | 7b8c51ad | Luiz Capitulino | */
|
197 | 7b8c51ad | Luiz Capitulino | |
198 | 7b8c51ad | Luiz Capitulino | START_TEST(qdict_put_exists_test) |
199 | 7b8c51ad | Luiz Capitulino | { |
200 | 7b8c51ad | Luiz Capitulino | int value;
|
201 | 7b8c51ad | Luiz Capitulino | const char *key = "exists"; |
202 | 7b8c51ad | Luiz Capitulino | |
203 | 7b8c51ad | Luiz Capitulino | qdict_put(tests_dict, key, qint_from_int(1));
|
204 | 7b8c51ad | Luiz Capitulino | qdict_put(tests_dict, key, qint_from_int(2));
|
205 | 7b8c51ad | Luiz Capitulino | |
206 | 7b8c51ad | Luiz Capitulino | value = qdict_get_int(tests_dict, key); |
207 | 7b8c51ad | Luiz Capitulino | fail_unless(value == 2);
|
208 | 7b8c51ad | Luiz Capitulino | } |
209 | 7b8c51ad | Luiz Capitulino | END_TEST |
210 | 7b8c51ad | Luiz Capitulino | |
211 | 7b8c51ad | Luiz Capitulino | START_TEST(qdict_get_not_exists_test) |
212 | 7b8c51ad | Luiz Capitulino | { |
213 | 7b8c51ad | Luiz Capitulino | fail_unless(qdict_get(tests_dict, "foo") == NULL); |
214 | 7b8c51ad | Luiz Capitulino | } |
215 | 7b8c51ad | Luiz Capitulino | END_TEST |
216 | 7b8c51ad | Luiz Capitulino | |
217 | 7b8c51ad | Luiz Capitulino | /*
|
218 | 7b8c51ad | Luiz Capitulino | * Stress test-case
|
219 | 7b8c51ad | Luiz Capitulino | *
|
220 | 7b8c51ad | Luiz Capitulino | * This is a lot big for a unit-test, but there is no other place
|
221 | 7b8c51ad | Luiz Capitulino | * to have it.
|
222 | 7b8c51ad | Luiz Capitulino | */
|
223 | 7b8c51ad | Luiz Capitulino | |
224 | 7b8c51ad | Luiz Capitulino | static void remove_dots(char *string) |
225 | 7b8c51ad | Luiz Capitulino | { |
226 | 7b8c51ad | Luiz Capitulino | char *p = strchr(string, ':'); |
227 | 7b8c51ad | Luiz Capitulino | if (p)
|
228 | 7b8c51ad | Luiz Capitulino | *p = '\0';
|
229 | 7b8c51ad | Luiz Capitulino | } |
230 | 7b8c51ad | Luiz Capitulino | |
231 | 7b8c51ad | Luiz Capitulino | static QString *read_line(FILE *file, char *key) |
232 | 7b8c51ad | Luiz Capitulino | { |
233 | 7b8c51ad | Luiz Capitulino | char value[128]; |
234 | 7b8c51ad | Luiz Capitulino | |
235 | 7b8c51ad | Luiz Capitulino | if (fscanf(file, "%s%s", key, value) == EOF) |
236 | 7b8c51ad | Luiz Capitulino | return NULL; |
237 | 7b8c51ad | Luiz Capitulino | remove_dots(key); |
238 | 7b8c51ad | Luiz Capitulino | return qstring_from_str(value);
|
239 | 7b8c51ad | Luiz Capitulino | } |
240 | 7b8c51ad | Luiz Capitulino | |
241 | 7b8c51ad | Luiz Capitulino | #define reset_file(file) fseek(file, 0L, SEEK_SET) |
242 | 7b8c51ad | Luiz Capitulino | |
243 | 7b8c51ad | Luiz Capitulino | START_TEST(qdict_stress_test) |
244 | 7b8c51ad | Luiz Capitulino | { |
245 | 7b8c51ad | Luiz Capitulino | size_t lines; |
246 | 7b8c51ad | Luiz Capitulino | char key[128]; |
247 | 7b8c51ad | Luiz Capitulino | FILE *test_file; |
248 | 7b8c51ad | Luiz Capitulino | QDict *qdict; |
249 | 7b8c51ad | Luiz Capitulino | QString *value; |
250 | 7b8c51ad | Luiz Capitulino | const char *test_file_path = "qdict-test-data.txt"; |
251 | 7b8c51ad | Luiz Capitulino | |
252 | 7b8c51ad | Luiz Capitulino | test_file = fopen(test_file_path, "r");
|
253 | 7b8c51ad | Luiz Capitulino | fail_unless(test_file != NULL);
|
254 | 7b8c51ad | Luiz Capitulino | |
255 | 7b8c51ad | Luiz Capitulino | // Create the dict
|
256 | 7b8c51ad | Luiz Capitulino | qdict = qdict_new(); |
257 | 7b8c51ad | Luiz Capitulino | fail_unless(qdict != NULL);
|
258 | 7b8c51ad | Luiz Capitulino | |
259 | 7b8c51ad | Luiz Capitulino | // Add everything from the test file
|
260 | 7b8c51ad | Luiz Capitulino | for (lines = 0;; lines++) { |
261 | 7b8c51ad | Luiz Capitulino | value = read_line(test_file, key); |
262 | 7b8c51ad | Luiz Capitulino | if (!value)
|
263 | 7b8c51ad | Luiz Capitulino | break;
|
264 | 7b8c51ad | Luiz Capitulino | |
265 | 7b8c51ad | Luiz Capitulino | qdict_put(qdict, key, value); |
266 | 7b8c51ad | Luiz Capitulino | } |
267 | 7b8c51ad | Luiz Capitulino | fail_unless(qdict_size(qdict) == lines); |
268 | 7b8c51ad | Luiz Capitulino | |
269 | 7b8c51ad | Luiz Capitulino | // Check if everything is really in there
|
270 | 7b8c51ad | Luiz Capitulino | reset_file(test_file); |
271 | 7b8c51ad | Luiz Capitulino | for (;;) {
|
272 | 7b8c51ad | Luiz Capitulino | const char *str1, *str2; |
273 | 7b8c51ad | Luiz Capitulino | |
274 | 7b8c51ad | Luiz Capitulino | value = read_line(test_file, key); |
275 | 7b8c51ad | Luiz Capitulino | if (!value)
|
276 | 7b8c51ad | Luiz Capitulino | break;
|
277 | 7b8c51ad | Luiz Capitulino | |
278 | 7b8c51ad | Luiz Capitulino | str1 = qstring_get_str(value); |
279 | 7b8c51ad | Luiz Capitulino | |
280 | 7b8c51ad | Luiz Capitulino | str2 = qdict_get_str(qdict, key); |
281 | 7b8c51ad | Luiz Capitulino | fail_unless(str2 != NULL);
|
282 | 7b8c51ad | Luiz Capitulino | |
283 | 7b8c51ad | Luiz Capitulino | fail_unless(strcmp(str1, str2) == 0);
|
284 | 7b8c51ad | Luiz Capitulino | |
285 | 7b8c51ad | Luiz Capitulino | QDECREF(value); |
286 | 7b8c51ad | Luiz Capitulino | } |
287 | 7b8c51ad | Luiz Capitulino | |
288 | 7b8c51ad | Luiz Capitulino | // Delete everything
|
289 | 7b8c51ad | Luiz Capitulino | reset_file(test_file); |
290 | 7b8c51ad | Luiz Capitulino | for (;;) {
|
291 | 7b8c51ad | Luiz Capitulino | value = read_line(test_file, key); |
292 | 7b8c51ad | Luiz Capitulino | if (!value)
|
293 | 7b8c51ad | Luiz Capitulino | break;
|
294 | 7b8c51ad | Luiz Capitulino | |
295 | 7b8c51ad | Luiz Capitulino | qdict_del(qdict, key); |
296 | 7b8c51ad | Luiz Capitulino | QDECREF(value); |
297 | 7b8c51ad | Luiz Capitulino | |
298 | 7b8c51ad | Luiz Capitulino | fail_unless(qdict_haskey(qdict, key) == 0);
|
299 | 7b8c51ad | Luiz Capitulino | } |
300 | 7b8c51ad | Luiz Capitulino | fclose(test_file); |
301 | 7b8c51ad | Luiz Capitulino | |
302 | 7b8c51ad | Luiz Capitulino | fail_unless(qdict_size(qdict) == 0);
|
303 | 7b8c51ad | Luiz Capitulino | QDECREF(qdict); |
304 | 7b8c51ad | Luiz Capitulino | } |
305 | 7b8c51ad | Luiz Capitulino | END_TEST |
306 | 7b8c51ad | Luiz Capitulino | |
307 | 7b8c51ad | Luiz Capitulino | static Suite *qdict_suite(void) |
308 | 7b8c51ad | Luiz Capitulino | { |
309 | 7b8c51ad | Luiz Capitulino | Suite *s; |
310 | 7b8c51ad | Luiz Capitulino | TCase *qdict_public_tcase; |
311 | 7b8c51ad | Luiz Capitulino | TCase *qdict_public2_tcase; |
312 | 7b8c51ad | Luiz Capitulino | TCase *qdict_stress_tcase; |
313 | 7b8c51ad | Luiz Capitulino | TCase *qdict_errors_tcase; |
314 | 7b8c51ad | Luiz Capitulino | |
315 | 7b8c51ad | Luiz Capitulino | s = suite_create("QDict test-suite");
|
316 | 7b8c51ad | Luiz Capitulino | |
317 | 7b8c51ad | Luiz Capitulino | qdict_public_tcase = tcase_create("Public Interface");
|
318 | 7b8c51ad | Luiz Capitulino | suite_add_tcase(s, qdict_public_tcase); |
319 | 7b8c51ad | Luiz Capitulino | tcase_add_test(qdict_public_tcase, qdict_new_test); |
320 | 7b8c51ad | Luiz Capitulino | tcase_add_test(qdict_public_tcase, qdict_put_obj_test); |
321 | 7b8c51ad | Luiz Capitulino | tcase_add_test(qdict_public_tcase, qdict_destroy_simple_test); |
322 | 7b8c51ad | Luiz Capitulino | |
323 | 7b8c51ad | Luiz Capitulino | /* Continue, but now with fixtures */
|
324 | 7b8c51ad | Luiz Capitulino | qdict_public2_tcase = tcase_create("Public Interface (2)");
|
325 | 7b8c51ad | Luiz Capitulino | suite_add_tcase(s, qdict_public2_tcase); |
326 | 7b8c51ad | Luiz Capitulino | tcase_add_checked_fixture(qdict_public2_tcase, qdict_setup, qdict_teardown); |
327 | 7b8c51ad | Luiz Capitulino | tcase_add_test(qdict_public2_tcase, qdict_get_test); |
328 | 7b8c51ad | Luiz Capitulino | tcase_add_test(qdict_public2_tcase, qdict_get_int_test); |
329 | 7b8c51ad | Luiz Capitulino | tcase_add_test(qdict_public2_tcase, qdict_get_try_int_test); |
330 | 7b8c51ad | Luiz Capitulino | tcase_add_test(qdict_public2_tcase, qdict_get_str_test); |
331 | 7b8c51ad | Luiz Capitulino | tcase_add_test(qdict_public2_tcase, qdict_get_try_str_test); |
332 | 7b8c51ad | Luiz Capitulino | tcase_add_test(qdict_public2_tcase, qdict_haskey_not_test); |
333 | 7b8c51ad | Luiz Capitulino | tcase_add_test(qdict_public2_tcase, qdict_haskey_test); |
334 | 7b8c51ad | Luiz Capitulino | tcase_add_test(qdict_public2_tcase, qdict_del_test); |
335 | 7b8c51ad | Luiz Capitulino | tcase_add_test(qdict_public2_tcase, qobject_to_qdict_test); |
336 | 7b8c51ad | Luiz Capitulino | |
337 | 7b8c51ad | Luiz Capitulino | qdict_errors_tcase = tcase_create("Errors");
|
338 | 7b8c51ad | Luiz Capitulino | suite_add_tcase(s, qdict_errors_tcase); |
339 | 7b8c51ad | Luiz Capitulino | tcase_add_checked_fixture(qdict_errors_tcase, qdict_setup, qdict_teardown); |
340 | 7b8c51ad | Luiz Capitulino | tcase_add_test(qdict_errors_tcase, qdict_put_exists_test); |
341 | 7b8c51ad | Luiz Capitulino | tcase_add_test(qdict_errors_tcase, qdict_get_not_exists_test); |
342 | 7b8c51ad | Luiz Capitulino | |
343 | 7b8c51ad | Luiz Capitulino | /* The Big one */
|
344 | 7b8c51ad | Luiz Capitulino | qdict_stress_tcase = tcase_create("Stress Test");
|
345 | 7b8c51ad | Luiz Capitulino | suite_add_tcase(s, qdict_stress_tcase); |
346 | 7b8c51ad | Luiz Capitulino | tcase_add_test(qdict_stress_tcase, qdict_stress_test); |
347 | 7b8c51ad | Luiz Capitulino | |
348 | 7b8c51ad | Luiz Capitulino | return s;
|
349 | 7b8c51ad | Luiz Capitulino | } |
350 | 7b8c51ad | Luiz Capitulino | |
351 | 7b8c51ad | Luiz Capitulino | int main(void) |
352 | 7b8c51ad | Luiz Capitulino | { |
353 | 7b8c51ad | Luiz Capitulino | int nf;
|
354 | 7b8c51ad | Luiz Capitulino | Suite *s; |
355 | 7b8c51ad | Luiz Capitulino | SRunner *sr; |
356 | 7b8c51ad | Luiz Capitulino | |
357 | 7b8c51ad | Luiz Capitulino | s = qdict_suite(); |
358 | 7b8c51ad | Luiz Capitulino | sr = srunner_create(s); |
359 | 7b8c51ad | Luiz Capitulino | |
360 | 7b8c51ad | Luiz Capitulino | srunner_run_all(sr, CK_NORMAL); |
361 | 7b8c51ad | Luiz Capitulino | nf = srunner_ntests_failed(sr); |
362 | 7b8c51ad | Luiz Capitulino | srunner_free(sr); |
363 | 7b8c51ad | Luiz Capitulino | |
364 | 7b8c51ad | Luiz Capitulino | return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE; |
365 | 7b8c51ad | Luiz Capitulino | } |