Remove building with NOCRYPTO option
[minix3.git] / external / bsd / atf / dist / atf-c / detail / list_test.c
blob3aa576cae6b3c5618fe959530603666fc50b9d11
1 /*
2 * Automated Testing Framework (atf)
4 * Copyright (c) 2008 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include <stdio.h>
31 #include <string.h>
33 #include <atf-c.h>
35 #include "atf-c/utils.h"
37 #include "list.h"
38 #include "test_helpers.h"
40 /* ---------------------------------------------------------------------
41 * Tests for the "atf_list" type.
42 * --------------------------------------------------------------------- */
45 * Constructors and destructors.
48 ATF_TC(list_init);
49 ATF_TC_HEAD(list_init, tc)
51 atf_tc_set_md_var(tc, "descr", "Checks the atf_list_init function");
53 ATF_TC_BODY(list_init, tc)
55 atf_list_t list;
57 RE(atf_list_init(&list));
58 ATF_REQUIRE_EQ(atf_list_size(&list), 0);
59 atf_list_fini(&list);
63 * Getters.
66 ATF_TC(list_index);
67 ATF_TC_HEAD(list_index, tc)
69 atf_tc_set_md_var(tc, "descr", "Checks the atf_list_index function");
71 ATF_TC_BODY(list_index, tc)
73 atf_list_t list;
74 int i1 = 1;
75 int i2 = 5;
76 int i3 = 9;
78 RE(atf_list_init(&list));
79 RE(atf_list_append(&list, &i1, false));
80 RE(atf_list_append(&list, &i2, false));
81 RE(atf_list_append(&list, &i3, false));
83 ATF_CHECK_EQ(*(int *)atf_list_index(&list, 0), 1);
84 ATF_CHECK_EQ(*(int *)atf_list_index(&list, 1), 5);
85 ATF_CHECK_EQ(*(int *)atf_list_index(&list, 2), 9);
87 atf_list_fini(&list);
90 ATF_TC(list_index_c);
91 ATF_TC_HEAD(list_index_c, tc)
93 atf_tc_set_md_var(tc, "descr", "Checks the atf_list_index_c function");
95 ATF_TC_BODY(list_index_c, tc)
97 atf_list_t list;
98 int i1 = 1;
99 int i2 = 5;
100 int i3 = 9;
102 RE(atf_list_init(&list));
103 RE(atf_list_append(&list, &i1, false));
104 RE(atf_list_append(&list, &i2, false));
105 RE(atf_list_append(&list, &i3, false));
107 ATF_CHECK_EQ(*(const int *)atf_list_index_c(&list, 0), 1);
108 ATF_CHECK_EQ(*(const int *)atf_list_index_c(&list, 1), 5);
109 ATF_CHECK_EQ(*(const int *)atf_list_index_c(&list, 2), 9);
111 atf_list_fini(&list);
114 ATF_TC_WITHOUT_HEAD(list_to_charpp_empty);
115 ATF_TC_BODY(list_to_charpp_empty, tc)
117 atf_list_t list;
118 char **array;
120 RE(atf_list_init(&list));
121 ATF_REQUIRE((array = atf_list_to_charpp(&list)) != NULL);
122 atf_list_fini(&list);
124 ATF_CHECK_EQ(NULL, array[0]);
125 atf_utils_free_charpp(array);
128 ATF_TC_WITHOUT_HEAD(list_to_charpp_some);
129 ATF_TC_BODY(list_to_charpp_some, tc)
131 atf_list_t list;
132 char **array;
134 char s1[] = "one";
135 char s2[] = "two";
136 char s3[] = "three";
138 RE(atf_list_init(&list));
139 RE(atf_list_append(&list, s1, false));
140 RE(atf_list_append(&list, s2, false));
141 RE(atf_list_append(&list, s3, false));
142 ATF_REQUIRE((array = atf_list_to_charpp(&list)) != NULL);
143 atf_list_fini(&list);
145 ATF_CHECK_STREQ("one", array[0]);
146 ATF_CHECK_STREQ("two", array[1]);
147 ATF_CHECK_STREQ("three", array[2]);
148 ATF_CHECK_EQ(NULL, array[3]);
149 atf_utils_free_charpp(array);
153 * Modifiers.
156 ATF_TC(list_append);
157 ATF_TC_HEAD(list_append, tc)
159 atf_tc_set_md_var(tc, "descr", "Checks the atf_list_append function");
161 ATF_TC_BODY(list_append, tc)
163 atf_list_t list;
164 size_t i;
165 char buf[] = "Test string";
167 RE(atf_list_init(&list));
168 for (i = 0; i < 1024; i++) {
169 ATF_REQUIRE_EQ(atf_list_size(&list), i);
170 RE(atf_list_append(&list, buf, false));
172 atf_list_fini(&list);
175 ATF_TC(list_append_list);
176 ATF_TC_HEAD(list_append_list, tc)
178 atf_tc_set_md_var(tc, "descr", "Checks the atf_list_append_list "
179 "function");
181 ATF_TC_BODY(list_append_list, tc)
184 atf_list_t l1, l2;
186 RE(atf_list_init(&l1));
187 RE(atf_list_init(&l2));
189 atf_list_append_list(&l1, &l2);
190 ATF_CHECK_EQ(atf_list_size(&l1), 0);
192 atf_list_fini(&l1);
196 atf_list_t l1, l2;
197 int item = 5;
199 RE(atf_list_init(&l1));
200 RE(atf_list_append(&l1, &item, false));
201 RE(atf_list_init(&l2));
203 atf_list_append_list(&l1, &l2);
204 ATF_CHECK_EQ(atf_list_size(&l1), 1);
205 ATF_CHECK_EQ(*(int *)atf_list_index(&l1, 0), item);
207 atf_list_fini(&l1);
211 atf_list_t l1, l2;
212 int item = 5;
214 RE(atf_list_init(&l1));
215 RE(atf_list_init(&l2));
216 RE(atf_list_append(&l2, &item, false));
218 atf_list_append_list(&l1, &l2);
219 ATF_CHECK_EQ(atf_list_size(&l1), 1);
220 ATF_CHECK_EQ(*(int *)atf_list_index(&l1, 0), item);
222 atf_list_fini(&l1);
226 atf_list_t l1, l2;
227 int item1 = 5;
228 int item2 = 9;
230 RE(atf_list_init(&l1));
231 RE(atf_list_append(&l1, &item1, false));
232 RE(atf_list_init(&l2));
233 RE(atf_list_append(&l2, &item2, false));
235 atf_list_append_list(&l1, &l2);
236 ATF_CHECK_EQ(atf_list_size(&l1), 2);
237 ATF_CHECK_EQ(*(int *)atf_list_index(&l1, 0), item1);
238 ATF_CHECK_EQ(*(int *)atf_list_index(&l1, 1), item2);
240 atf_list_fini(&l1);
244 atf_list_t l1, l2;
245 atf_list_citer_t end1, end2;
247 RE(atf_list_init(&l1));
248 RE(atf_list_init(&l2));
250 end1 = atf_list_end_c(&l1);
251 end2 = atf_list_end_c(&l2);
252 /* XXX Shouldn't query m_entry here. */
253 ATF_CHECK(end1.m_entry != end2.m_entry);
255 atf_list_append_list(&l1, &l2);
256 ATF_CHECK(atf_list_end_c(&l1).m_entry == end2.m_entry);
258 atf_list_fini(&l1);
263 * Macros.
266 ATF_TC(list_for_each);
267 ATF_TC_HEAD(list_for_each, tc)
269 atf_tc_set_md_var(tc, "descr", "Checks the atf_list_for_each macro");
271 ATF_TC_BODY(list_for_each, tc)
273 atf_list_t list;
274 atf_list_iter_t iter;
275 size_t count, i, size;
276 int nums[10];
278 printf("Iterating over empty list\n");
279 RE(atf_list_init(&list));
280 count = 0;
281 atf_list_for_each(iter, &list) {
282 count++;
283 printf("Item count is now %zd\n", count);
285 ATF_REQUIRE_EQ(count, 0);
286 atf_list_fini(&list);
288 for (size = 0; size <= 10; size++) {
289 printf("Iterating over list of %zd elements\n", size);
290 RE(atf_list_init(&list));
291 for (i = 0; i < size; i++) {
292 nums[i] = i + 1;
293 RE(atf_list_append(&list, &nums[i], false));
295 count = 0;
296 atf_list_for_each(iter, &list) {
297 printf("Retrieved item: %d\n", *(int *)atf_list_iter_data(iter));
298 count++;
300 ATF_REQUIRE_EQ(count, size);
301 atf_list_fini(&list);
305 ATF_TC(list_for_each_c);
306 ATF_TC_HEAD(list_for_each_c, tc)
308 atf_tc_set_md_var(tc, "descr", "Checks the atf_list_for_each_c macro");
310 ATF_TC_BODY(list_for_each_c, tc)
312 atf_list_t list;
313 atf_list_citer_t iter;
314 size_t count, i, size;
315 int nums[10];
317 printf("Iterating over empty list\n");
318 RE(atf_list_init(&list));
319 count = 0;
320 atf_list_for_each_c(iter, &list) {
321 count++;
322 printf("Item count is now %zd\n", count);
324 ATF_REQUIRE_EQ(count, 0);
325 atf_list_fini(&list);
327 for (size = 0; size <= 10; size++) {
328 printf("Iterating over list of %zd elements\n", size);
329 RE(atf_list_init(&list));
330 for (i = 0; i < size; i++) {
331 nums[i] = i + 1;
332 RE(atf_list_append(&list, &nums[i], false));
334 count = 0;
335 atf_list_for_each_c(iter, &list) {
336 printf("Retrieved item: %d\n",
337 *(const int *)atf_list_citer_data(iter));
338 count++;
340 ATF_REQUIRE_EQ(count, size);
341 atf_list_fini(&list);
345 /* ---------------------------------------------------------------------
346 * Main.
347 * --------------------------------------------------------------------- */
349 ATF_TP_ADD_TCS(tp)
351 /* Constructors and destructors. */
352 ATF_TP_ADD_TC(tp, list_init);
354 /* Getters. */
355 ATF_TP_ADD_TC(tp, list_index);
356 ATF_TP_ADD_TC(tp, list_index_c);
357 ATF_TP_ADD_TC(tp, list_to_charpp_empty);
358 ATF_TP_ADD_TC(tp, list_to_charpp_some);
360 /* Modifiers. */
361 ATF_TP_ADD_TC(tp, list_append);
362 ATF_TP_ADD_TC(tp, list_append_list);
364 /* Macros. */
365 ATF_TP_ADD_TC(tp, list_for_each);
366 ATF_TP_ADD_TC(tp, list_for_each_c);
368 return atf_no_error();