pacemaker  2.1.2-ada5c3b36
Scalable High-Availability cluster resource manager
pcmk__char_in_any_str_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 empty_list(void **state)
20 {
21  assert_false(pcmk__char_in_any_str('x', NULL));
22  assert_false(pcmk__char_in_any_str('\0', NULL));
23 }
24 
25 static void
26 null_char(void **state)
27 {
28  assert_true(pcmk__char_in_any_str('\0', "xxx", "yyy", NULL));
29  assert_true(pcmk__char_in_any_str('\0', "", NULL));
30 }
31 
32 static void
33 in_list(void **state)
34 {
35  assert_true(pcmk__char_in_any_str('x', "aaa", "bbb", "xxx", NULL));
36 }
37 
38 static void
39 not_in_list(void **state)
40 {
41  assert_false(pcmk__char_in_any_str('x', "aaa", "bbb", NULL));
42  assert_false(pcmk__char_in_any_str('A', "aaa", "bbb", NULL));
43  assert_false(pcmk__char_in_any_str('x', "", NULL));
44 }
45 
46 int main(int argc, char **argv)
47 {
48  const struct CMUnitTest tests[] = {
49  cmocka_unit_test(empty_list),
50  cmocka_unit_test(null_char),
51  cmocka_unit_test(in_list),
52  cmocka_unit_test(not_in_list),
53  };
54 
55  cmocka_set_message_output(CM_OUTPUT_TAP);
56  return cmocka_run_group_tests(tests, NULL, NULL);
57 }
58 
bool pcmk__char_in_any_str(int ch,...) G_GNUC_NULL_TERMINATED
Definition: strings.c:978
int main(int argc, char **argv)