pacemaker  2.1.0-7c3f660
Scalable High-Availability cluster resource manager
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 <stdio.h>
13 #include <stdbool.h>
14 #include <glib.h>
15 
16 static void
17 empty_input_list(void) {
18  g_assert_false(pcmk__strcase_any_of("xxx", NULL));
19  g_assert_false(pcmk__str_any_of("xxx", NULL));
20  g_assert_false(pcmk__strcase_any_of("", NULL));
21  g_assert_false(pcmk__str_any_of("", NULL));
22 }
23 
24 static void
25 empty_string(void) {
26  g_assert_false(pcmk__strcase_any_of("", "xxx", "yyy", NULL));
27  g_assert_false(pcmk__str_any_of("", "xxx", "yyy", NULL));
28  g_assert_false(pcmk__strcase_any_of(NULL, "xxx", "yyy", NULL));
29  g_assert_false(pcmk__str_any_of(NULL, "xxx", "yyy", NULL));
30 }
31 
32 static void
33 in_list(void) {
34  g_assert_true(pcmk__strcase_any_of("xxx", "aaa", "bbb", "xxx", NULL));
35  g_assert_true(pcmk__str_any_of("xxx", "aaa", "bbb", "xxx", NULL));
36  g_assert_true(pcmk__strcase_any_of("XXX", "aaa", "bbb", "xxx", NULL));
37 }
38 
39 static void
40 not_in_list(void) {
41  g_assert_false(pcmk__strcase_any_of("xxx", "aaa", "bbb", NULL));
42  g_assert_false(pcmk__str_any_of("xxx", "aaa", "bbb", NULL));
43  g_assert_false(pcmk__str_any_of("AAA", "aaa", "bbb", NULL));
44 }
45 
46 int main(int argc, char **argv)
47 {
48  g_test_init(&argc, &argv, NULL);
49 
50  g_test_add_func("/common/strings/any_of/empty_list", empty_input_list);
51  g_test_add_func("/common/strings/any_of/empty_string", empty_string);
52  g_test_add_func("/common/strings/any_of/in", in_list);
53  g_test_add_func("/common/strings/any_of/not_in", not_in_list);
54 
55  return g_test_run();
56 }
bool pcmk__strcase_any_of(const char *s,...) G_GNUC_NULL_TERMINATED
Definition: strings.c:929
int main(int argc, char **argv)
bool pcmk__str_any_of(const char *s,...) G_GNUC_NULL_TERMINATED
Definition: strings.c:953