pacemaker  2.1.0-7c3f660
Scalable High-Availability cluster resource manager
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
pcmk__parse_ll_range_test.c
Go to the documentation of this file.
1 /*
2  * Copyright 2020-2021 the Pacemaker project contributors
3  *
4  * The version control history for this file may have further details.
5  *
6  * This source code is licensed under the GNU Lesser General Public License
7  * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
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), ==,
21  g_assert_cmpint(pcmk__parse_ll_range("", &start, &end), ==,
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), ==,
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), ==,
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), ==,
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 }
int main(int argc, char **argv)
#define PCMK__PARSE_INT_DEFAULT
int pcmk__parse_ll_range(const char *srcstring, long long *start, long long *end)
Definition: strings.c:812