This source file includes following definitions.
- setup
- teardown
- START_PARAMETRIZED_TEST
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 #define TEST_SUITE_NAME "/lib/strutil"
27
28 #include "tests/mctest.h"
29
30 #include <inttypes.h>
31
32 #include "lib/strutil.h"
33
34
35
36
37 static void
38 setup (void)
39 {
40 }
41
42
43
44
45 static void
46 teardown (void)
47 {
48 }
49
50
51
52
53
54 static const struct parse_integer_test_ds
55 {
56 const char *haystack;
57 uintmax_t expected_result;
58 gboolean invalid;
59 } parse_integer_test_ds[] =
60 {
61 {
62
63 "99999999999999999999999999999999999999999999999999999999999999999999",
64 0,
65 TRUE
66 },
67 {
68 "x",
69 0,
70 TRUE
71 },
72 {
73 "9x",
74 0,
75 TRUE
76 },
77 {
78 "1",
79 1,
80 FALSE
81 },
82 {
83 "-1",
84 0,
85 TRUE
86 },
87 {
88 "1k",
89 1024,
90 FALSE
91 },
92 {
93 "1K",
94 1024,
95 FALSE
96 },
97 {
98 "1M",
99 1024 * 1024,
100 FALSE
101 },
102 {
103 "1m",
104 0,
105 TRUE
106 },
107 {
108 "64M",
109 64 * 1024 * 1024,
110 FALSE
111 },
112 {
113 "1G",
114 1 * 1024 * 1024 * 1024,
115 FALSE
116 }
117 };
118
119
120
121
122 START_PARAMETRIZED_TEST (parse_integer_test, parse_integer_test_ds)
123
124 {
125
126 uintmax_t actual_result;
127 gboolean invalid = FALSE;
128
129
130 actual_result = parse_integer (data->haystack, &invalid);
131
132
133 ck_assert_msg (invalid == data->invalid && actual_result == data->expected_result,
134 "actual ( %" PRIuMAX ") not equal to\nexpected (%" PRIuMAX ")",
135 actual_result, data->expected_result);
136 }
137
138 END_PARAMETRIZED_TEST
139
140
141
142
143 int
144 main (void)
145 {
146 TCase *tc_core;
147
148 tc_core = tcase_create ("Core");
149
150 tcase_add_checked_fixture (tc_core, setup, teardown);
151
152
153 mctest_add_parameterized_test (tc_core, parse_integer_test, parse_integer_test_ds);
154
155
156 return mctest_run_all (tc_core);
157 }
158
159