pacemaker  2.1.4-dc6eb4362
Scalable High-Availability cluster resource manager
pcmk__str_any_of_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_input_list(void **state) {
20  assert_false(pcmk__strcase_any_of("xxx", NULL));
21  assert_false(pcmk__str_any_of("xxx", NULL));
22  assert_false(pcmk__strcase_any_of("", NULL));
23  assert_false(pcmk__str_any_of("", NULL));
24 }
25 
26 static void
27 empty_string(void **state) {
28  assert_false(pcmk__strcase_any_of("", "xxx", "yyy", NULL));
29  assert_false(pcmk__str_any_of("", "xxx", "yyy", NULL));
30  assert_false(pcmk__strcase_any_of(NULL, "xxx", "yyy", NULL));
31  assert_false(pcmk__str_any_of(NULL, "xxx", "yyy", NULL));
32 }
33 
34 static void
35 in_list(void **state) {
36  assert_true(pcmk__strcase_any_of("xxx", "aaa", "bbb", "xxx", NULL));
37  assert_true(pcmk__str_any_of("xxx", "aaa", "bbb", "xxx", NULL));
38  assert_true(pcmk__strcase_any_of("XXX", "aaa", "bbb", "xxx", NULL));
39 }
40 
41 static void
42 not_in_list(void **state) {
43  assert_false(pcmk__strcase_any_of("xxx", "aaa", "bbb", NULL));
44  assert_false(pcmk__str_any_of("xxx", "aaa", "bbb", NULL));
45  assert_false(pcmk__str_any_of("AAA", "aaa", "bbb", NULL));
46 }
47 
48 int main(int argc, char **argv)
49 {
50  const struct CMUnitTest tests[] = {
51  cmocka_unit_test(empty_input_list),
52  cmocka_unit_test(empty_string),
53  cmocka_unit_test(in_list),
54  cmocka_unit_test(not_in_list),
55  };
56 
57  cmocka_set_message_output(CM_OUTPUT_TAP);
58  return cmocka_run_group_tests(tests, NULL, NULL);
59 }
int main(int argc, char **argv)
bool pcmk__strcase_any_of(const char *s,...) G_GNUC_NULL_TERMINATED
Definition: strings.c:931
bool pcmk__str_any_of(const char *s,...) G_GNUC_NULL_TERMINATED
Definition: strings.c:955