This source file includes following definitions.
- empty_input_string
- missing_separator
- only_separator
- no_range_end
- no_range_start
- range_start_and_end
- garbage
- strtoll_errors
- main
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <stdarg.h>
13 #include <stddef.h>
14 #include <stdint.h>
15 #include <setjmp.h>
16 #include <cmocka.h>
17
18 static void
19 empty_input_string(void **state)
20 {
21 long long start, end;
22
23 assert_int_equal(pcmk__parse_ll_range(NULL, &start, &end), pcmk_rc_unknown_format);
24 assert_int_equal(pcmk__parse_ll_range("", &start, &end), pcmk_rc_unknown_format);
25 }
26
27 static void
28 missing_separator(void **state)
29 {
30 long long start, end;
31
32 assert_int_equal(pcmk__parse_ll_range("1234", &start, &end), pcmk_rc_ok);
33 assert_int_equal(start, 1234);
34 assert_int_equal(end, 1234);
35 }
36
37 static void
38 only_separator(void **state)
39 {
40 long long start, end;
41
42 assert_int_equal(pcmk__parse_ll_range("-", &start, &end), pcmk_rc_unknown_format);
43 assert_int_equal(start, PCMK__PARSE_INT_DEFAULT);
44 assert_int_equal(end, PCMK__PARSE_INT_DEFAULT);
45 }
46
47 static void
48 no_range_end(void **state)
49 {
50 long long start, end;
51
52 assert_int_equal(pcmk__parse_ll_range("2000-", &start, &end), pcmk_rc_ok);
53 assert_int_equal(start, 2000);
54 assert_int_equal(end, PCMK__PARSE_INT_DEFAULT);
55 }
56
57 static void
58 no_range_start(void **state)
59 {
60 long long start, end;
61
62 assert_int_equal(pcmk__parse_ll_range("-2020", &start, &end), pcmk_rc_ok);
63 assert_int_equal(start, PCMK__PARSE_INT_DEFAULT);
64 assert_int_equal(end, 2020);
65 }
66
67 static void
68 range_start_and_end(void **state)
69 {
70 long long start, end;
71
72 assert_int_equal(pcmk__parse_ll_range("2000-2020", &start, &end), pcmk_rc_ok);
73 assert_int_equal(start, 2000);
74 assert_int_equal(end, 2020);
75
76 assert_int_equal(pcmk__parse_ll_range("2000-2020-2030", &start, &end), pcmk_rc_unknown_format);
77 }
78
79 static void
80 garbage(void **state)
81 {
82 long long start, end;
83
84 assert_int_equal(pcmk__parse_ll_range("2000x-", &start, &end), pcmk_rc_unknown_format);
85 assert_int_equal(start, PCMK__PARSE_INT_DEFAULT);
86 assert_int_equal(end, PCMK__PARSE_INT_DEFAULT);
87
88 assert_int_equal(pcmk__parse_ll_range("-x2000", &start, &end), pcmk_rc_unknown_format);
89 assert_int_equal(start, PCMK__PARSE_INT_DEFAULT);
90 assert_int_equal(end, PCMK__PARSE_INT_DEFAULT);
91 }
92
93 static void
94 strtoll_errors(void **state)
95 {
96 long long start, end;
97
98 assert_int_equal(pcmk__parse_ll_range("20000000000000000000-", &start, &end), pcmk_rc_unknown_format);
99 assert_int_equal(pcmk__parse_ll_range("100-20000000000000000000", &start, &end), pcmk_rc_unknown_format);
100 }
101
102 int main(int argc, char **argv)
103 {
104 const struct CMUnitTest tests[] = {
105 cmocka_unit_test(empty_input_string),
106 cmocka_unit_test(missing_separator),
107 cmocka_unit_test(only_separator),
108 cmocka_unit_test(no_range_end),
109 cmocka_unit_test(no_range_start),
110 cmocka_unit_test(range_start_and_end),
111 cmocka_unit_test(strtoll_errors),
112
113 cmocka_unit_test(garbage),
114 };
115
116 cmocka_set_message_output(CM_OUTPUT_TAP);
117 return cmocka_run_group_tests(tests, NULL, NULL);
118 }