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