This source file includes following definitions.
- empty_input_string
- missing_separator
- only_separator
- no_range_end
- no_range_start
- range_start_and_end
- garbage
- 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
77 static void
78 garbage(void **state)
79 {
80 long long start, end;
81
82 assert_int_equal(pcmk__parse_ll_range("2000x-", &start, &end), pcmk_rc_unknown_format);
83 assert_int_equal(start, PCMK__PARSE_INT_DEFAULT);
84 assert_int_equal(end, PCMK__PARSE_INT_DEFAULT);
85
86 assert_int_equal(pcmk__parse_ll_range("-x2000", &start, &end), pcmk_rc_unknown_format);
87 assert_int_equal(start, PCMK__PARSE_INT_DEFAULT);
88 assert_int_equal(end, PCMK__PARSE_INT_DEFAULT);
89 }
90
91 int main(int argc, char **argv)
92 {
93 const struct CMUnitTest tests[] = {
94 cmocka_unit_test(empty_input_string),
95 cmocka_unit_test(missing_separator),
96 cmocka_unit_test(only_separator),
97 cmocka_unit_test(no_range_end),
98 cmocka_unit_test(no_range_start),
99 cmocka_unit_test(range_start_and_end),
100
101 cmocka_unit_test(garbage),
102 };
103
104 cmocka_set_message_output(CM_OUTPUT_TAP);
105 return cmocka_run_group_tests(tests, NULL, NULL);
106 }