pacemaker  2.0.4-2deceaa
Scalable High-Availability cluster resource manager
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
pcmk__parse_ll_range.c
Go to the documentation of this file.
1 #include <glib.h>
2 
3 #include <crm_internal.h>
4 
5 static void
6 empty_input_string(void) {
7  long long start, end;
8 
9  g_assert(pcmk__parse_ll_range(NULL, &start, &end) == pcmk_rc_unknown_format);
10  g_assert(pcmk__parse_ll_range("", &start, &end) == pcmk_rc_unknown_format);
11 }
12 
13 static void
14 missing_separator(void) {
15  long long start, end;
16 
17  g_assert(pcmk__parse_ll_range("1234", &start, &end) == pcmk_rc_ok);
18  g_assert_cmpint(start, ==, 1234);
19  g_assert_cmpint(end, ==, 1234);
20 }
21 
22 static void
23 only_separator(void) {
24  long long start, end;
25 
26  g_assert(pcmk__parse_ll_range("-", &start, &end) == pcmk_rc_unknown_format);
27  g_assert_cmpint(start, ==, -1);
28  g_assert_cmpint(end, ==, -1);
29 }
30 
31 static void
32 no_range_end(void) {
33  long long start, end;
34 
35  g_assert(pcmk__parse_ll_range("2000-", &start, &end) == pcmk_rc_ok);
36  g_assert_cmpint(start, ==, 2000);
37  g_assert_cmpint(end, ==, -1);
38 }
39 
40 static void
41 no_range_start(void) {
42  long long start, end;
43 
44  g_assert(pcmk__parse_ll_range("-2020", &start, &end) == pcmk_rc_ok);
45  g_assert_cmpint(start, ==, -1);
46  g_assert_cmpint(end, ==, 2020);
47 }
48 
49 static void
50 range_start_and_end(void) {
51  long long start, end;
52 
53  g_assert(pcmk__parse_ll_range("2000-2020", &start, &end) == pcmk_rc_ok);
54  g_assert_cmpint(start, ==, 2000);
55  g_assert_cmpint(end, ==, 2020);
56 }
57 
58 static void
59 garbage(void) {
60  long long start, end;
61 
62  g_assert(pcmk__parse_ll_range("2000x-", &start, &end) == pcmk_rc_unknown_format);
63  g_assert_cmpint(start, ==, -1);
64  g_assert_cmpint(end, ==, -1);
65 
66  g_assert(pcmk__parse_ll_range("-x2000", &start, &end) == pcmk_rc_unknown_format);
67  g_assert_cmpint(start, ==, -1);
68  g_assert_cmpint(end, ==, -1);
69 }
70 
71 int main(int argc, char **argv) {
72  g_test_init(&argc, &argv, NULL);
73 
74  g_test_add_func("/common/strings/range/empty", empty_input_string);
75  g_test_add_func("/common/strings/range/no_sep", missing_separator);
76  g_test_add_func("/common/strings/range/only_sep", only_separator);
77  g_test_add_func("/common/strings/range/no_end", no_range_end);
78  g_test_add_func("/common/strings/range/no_start", no_range_start);
79  g_test_add_func("/common/strings/range/start_and_end", range_start_and_end);
80 
81  g_test_add_func("/common/strings/range/garbage", garbage);
82 
83  return g_test_run();
84 }
int main(int argc, char **argv)
char int pcmk__parse_ll_range(const char *srcstring, long long *start, long long *end)
Definition: strings.c:605