Debian Codegraph @

tests/unit/test_filelist.template

raw
1 /**
2 * This file is part of the Detox package.
3 *
4 * Copyright (c) Doug Harple <[email protected]>
5 *
6 * For the full copyright and license information, please view the LICENSE
7 * file that was distributed with this source code.
8 */
9
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13
14 #include "filelist.h"
15
16 #define STRLEN 128
17
18 struct test_definition {
19 int pass;
20 int count;
21 };
22
23 static struct test_definition tests[8] = {
24 { .pass = 1, .count = 1 },
25 { .pass = 2, .count = 2 },
26 { .pass = 3, .count = 15 },
27 { .pass = 4, .count = 16 },
28 { .pass = 5, .count = 17 },
29 { .pass = 6, .count = 1024 },
30 { .pass = 7, .count = 100000 },
31 { .pass = -1 }
32 };
33
34 #test test_filelist
35 char *work;
36 filelist_t *test_list;
37 int i;
38 int j;
39 char *check, *last;
40
41 work = alloca(STRLEN);
42 last = NULL;
43
44 for (i = 0; tests[i].pass != -1; i++) {
45 test_list = filelist_init();
46
47 for (j = 0; j < tests[i].count; j++) {
48 snprintf(work, STRLEN, "test-%04d", j);
49 filelist_put(test_list, work);
50 }
51
52 ck_assert_int_eq(filelist_count(test_list), tests[i].count);
53
54 while ((check = filelist_get(test_list))) {
55 last = check;
56 }
57
58 ck_assert_str_eq(last, work);
59
60 // walk the pointer back to the beginning
61 ck_assert_str_eq(filelist_get(test_list), "test-0000");
62 if (tests[i].count > 1) {
63 ck_assert_str_eq(filelist_get(test_list), "test-0001");
64 }
65
66 filelist_reset(test_list);
67
68 // walk the pointer back to the beginning
69 ck_assert_str_eq(filelist_get(test_list), "test-0000");
70
71 ck_assert_int_eq(filelist_count(test_list), tests[i].count);
72
73 filelist_free(test_list);
74 }
75
76 #test test_filelist_get_null
77 filelist_get(NULL);
78 ck_assert_int_eq(filelist_count(NULL), 0);
79
80 #test test_filelist_get_empty
81 char *work;
82 filelist_t *test_list;
83
84 test_list = filelist_init();
85
86 work = filelist_get(test_list);
87
88 ck_assert(work == NULL);
89
90 ck_assert_int_eq(filelist_count(test_list), 0);
91
92 filelist_free(test_list);
93
94 #test test_filelist_get_one
95 filelist_t *test_list;
96
97 test_list = filelist_init();
98
99 filelist_put(test_list, "whatever");
100
101 ck_assert_str_eq(filelist_get(test_list), "whatever");
102
103 ck_assert(filelist_get(test_list) == NULL);
104
105 ck_assert_str_eq(filelist_get(test_list), "whatever");
106
107 ck_assert_int_eq(filelist_count(test_list), 1);
108
109 filelist_free(test_list);
110
111 #test-exit(1) test_filelist_put_null
112 filelist_put(NULL, NULL);