pacemaker  2.1.4-dc6eb4362
Scalable High-Availability cluster resource manager
pcmk_str_is_minus_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_minus_infinity("-INFINITY"));
22 }
23 
24 static void
25 mixed_case_str_fails(void **state)
26 {
27  assert_false(pcmk_str_is_minus_infinity("-infinity"));
28  assert_false(pcmk_str_is_minus_infinity("-Infinity"));
29 }
30 
31 static void
32 added_whitespace_fails(void **state)
33 {
34  assert_false(pcmk_str_is_minus_infinity(" -INFINITY"));
35  assert_false(pcmk_str_is_minus_infinity("-INFINITY "));
36  assert_false(pcmk_str_is_minus_infinity(" -INFINITY "));
37  assert_false(pcmk_str_is_minus_infinity("- INFINITY"));
38 }
39 
40 static void
41 empty_str_fails(void **state)
42 {
43  assert_false(pcmk_str_is_minus_infinity(NULL));
44  assert_false(pcmk_str_is_minus_infinity(""));
45 }
46 
47 static void
48 infinity_fails(void **state)
49 {
50  assert_false(pcmk_str_is_minus_infinity("INFINITY"));
51 }
52 
53 int main(int argc, char **argv)
54 {
55  const struct CMUnitTest tests[] = {
56  cmocka_unit_test(uppercase_str_passes),
57  cmocka_unit_test(mixed_case_str_fails),
58  cmocka_unit_test(added_whitespace_fails),
59  cmocka_unit_test(empty_str_fails),
60  cmocka_unit_test(infinity_fails),
61  };
62 
63  cmocka_set_message_output(CM_OUTPUT_TAP);
64  return cmocka_run_group_tests(tests, NULL, NULL);
65 }
int main(int argc, char **argv)
bool pcmk_str_is_minus_infinity(const char *s)
Definition: utils.c:518