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 static const struct parse_integer_test_ds
54 {
55 const char *haystack;
56 uintmax_t expected_result;
57 gboolean invalid;
58 } parse_integer_test_ds[] = {
59 {
60 "99999999999999999999999999999999999999999999999999999999999999999999", 0, TRUE },
61 { "x", 0, TRUE },
62 { "9x", 0, TRUE },
63 { "1", 1, FALSE },
64 { "-1", 0, TRUE },
65 { "1k", 1024, FALSE },
66 { "1K", 1024, FALSE },
67 { "1M", 1024 * 1024, FALSE },
68 { "1m", 0, TRUE },
69 { "64M", 64 * 1024 * 1024, FALSE },
70 { "1G", 1 * 1024 * 1024 * 1024, FALSE },
71 };
72
73
74 START_PARAMETRIZED_TEST (parse_integer_test, parse_integer_test_ds)
75 {
76
77 uintmax_t actual_result;
78 gboolean invalid = FALSE;
79
80
81 actual_result = parse_integer (data->haystack, &invalid);
82
83
84 ck_assert_msg (invalid == data->invalid && actual_result == data->expected_result,
85 "actual ( %" PRIuMAX ") not equal to\nexpected (%" PRIuMAX ")", actual_result,
86 data->expected_result);
87 }
88 END_PARAMETRIZED_TEST
89
90
91
92 int
93 main (void)
94 {
95 TCase *tc_core;
96
97 tc_core = tcase_create ("Core");
98
99 tcase_add_checked_fixture (tc_core, setup, teardown);
100
101
102 mctest_add_parameterized_test (tc_core, parse_integer_test, parse_integer_test_ds);
103
104
105 return mctest_run_all (tc_core);
106 }
107
108