pacemaker  2.1.4-dc6eb4362
Scalable High-Availability cluster resource manager
pcmk_str_is_infinity_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 <stdarg.h>
13 #include <stddef.h>
14 #include <stdint.h>
15 #include <setjmp.h>
16 #include <cmocka.h>
17 
18 static void
19 uppercase_str_passes(void **state)
20 {
21  assert_true(pcmk_str_is_infinity("INFINITY"));
22  assert_true(pcmk_str_is_infinity("+INFINITY"));
23 }
24 
25 static void
26 mixed_case_str_fails(void **state)
27 {
28  assert_false(pcmk_str_is_infinity("infinity"));
29  assert_false(pcmk_str_is_infinity("+infinity"));
30  assert_false(pcmk_str_is_infinity("Infinity"));
31  assert_false(pcmk_str_is_infinity("+Infinity"));
32 }
33 
34 static void
35 added_whitespace_fails(void **state)
36 {
37  assert_false(pcmk_str_is_infinity(" INFINITY"));
38  assert_false(pcmk_str_is_infinity("INFINITY "));
39  assert_false(pcmk_str_is_infinity(" INFINITY "));
40  assert_false(pcmk_str_is_infinity("+ INFINITY"));
41 }
42 
43 static void
44 empty_str_fails(void **state)
45 {
46  assert_false(pcmk_str_is_infinity(NULL));
47  assert_false(pcmk_str_is_infinity(""));
48 }
49 
50 static void
51 minus_infinity_fails(void **state)
52 {
53  assert_false(pcmk_str_is_infinity("-INFINITY"));
54 }
55 
56 int main(int argc, char **argv)
57 {
58  const struct CMUnitTest tests[] = {
59  cmocka_unit_test(uppercase_str_passes),
60  cmocka_unit_test(mixed_case_str_fails),
61  cmocka_unit_test(added_whitespace_fails),
62  cmocka_unit_test(empty_str_fails),
63  cmocka_unit_test(minus_infinity_fails),
64  };
65 
66  cmocka_set_message_output(CM_OUTPUT_TAP);
67  return cmocka_run_group_tests(tests, NULL, NULL);
68 }
bool pcmk_str_is_infinity(const char *s)
Definition: utils.c:513
int main(int argc, char **argv)