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 <glib.h>
13
14 static void
15 empty_input_string(void)
16 {
17 long long start, end;
18
19 g_assert_cmpint(pcmk__parse_ll_range(NULL, &start, &end), ==,
20 pcmk_rc_unknown_format);
21 g_assert_cmpint(pcmk__parse_ll_range("", &start, &end), ==,
22 pcmk_rc_unknown_format);
23 }
24
25 static void
26 missing_separator(void)
27 {
28 long long start, end;
29
30 g_assert_cmpint(pcmk__parse_ll_range("1234", &start, &end), ==, pcmk_rc_ok);
31 g_assert_cmpint(start, ==, 1234);
32 g_assert_cmpint(end, ==, 1234);
33 }
34
35 static void
36 only_separator(void)
37 {
38 long long start, end;
39
40 g_assert_cmpint(pcmk__parse_ll_range("-", &start, &end), ==,
41 pcmk_rc_unknown_format);
42 g_assert_cmpint(start, ==, PCMK__PARSE_INT_DEFAULT);
43 g_assert_cmpint(end, ==, PCMK__PARSE_INT_DEFAULT);
44 }
45
46 static void
47 no_range_end(void)
48 {
49 long long start, end;
50
51 g_assert_cmpint(pcmk__parse_ll_range("2000-", &start, &end), ==,
52 pcmk_rc_ok);
53 g_assert_cmpint(start, ==, 2000);
54 g_assert_cmpint(end, ==, PCMK__PARSE_INT_DEFAULT);
55 }
56
57 static void
58 no_range_start(void)
59 {
60 long long start, end;
61
62 g_assert_cmpint(pcmk__parse_ll_range("-2020", &start, &end), ==,
63 pcmk_rc_ok);
64 g_assert_cmpint(start, ==, PCMK__PARSE_INT_DEFAULT);
65 g_assert_cmpint(end, ==, 2020);
66 }
67
68 static void
69 range_start_and_end(void)
70 {
71 long long start, end;
72
73 g_assert_cmpint(pcmk__parse_ll_range("2000-2020", &start, &end), ==,
74 pcmk_rc_ok);
75 g_assert_cmpint(start, ==, 2000);
76 g_assert_cmpint(end, ==, 2020);
77 }
78
79 static void
80 garbage(void)
81 {
82 long long start, end;
83
84 g_assert_cmpint(pcmk__parse_ll_range("2000x-", &start, &end), ==,
85 pcmk_rc_unknown_format);
86 g_assert_cmpint(start, ==, PCMK__PARSE_INT_DEFAULT);
87 g_assert_cmpint(end, ==, PCMK__PARSE_INT_DEFAULT);
88
89 g_assert_cmpint(pcmk__parse_ll_range("-x2000", &start, &end), ==,
90 pcmk_rc_unknown_format);
91 g_assert_cmpint(start, ==, PCMK__PARSE_INT_DEFAULT);
92 g_assert_cmpint(end, ==, PCMK__PARSE_INT_DEFAULT);
93 }
94
95 int main(int argc, char **argv)
96 {
97 g_test_init(&argc, &argv, NULL);
98
99 g_test_add_func("/common/strings/range/empty", empty_input_string);
100 g_test_add_func("/common/strings/range/no_sep", missing_separator);
101 g_test_add_func("/common/strings/range/only_sep", only_separator);
102 g_test_add_func("/common/strings/range/no_end", no_range_end);
103 g_test_add_func("/common/strings/range/no_start", no_range_start);
104 g_test_add_func("/common/strings/range/start_and_end", range_start_and_end);
105
106 g_test_add_func("/common/strings/range/garbage", garbage);
107
108 return g_test_run();
109 }