pacemaker  2.1.7-0f7f88312f
Scalable High-Availability cluster resource manager
pcmk__str_in_list_test.c
Go to the documentation of this file.
1 /*
2  * Copyright 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 General Public License version 2
7  * or later (GPLv2+) WITHOUT ANY WARRANTY.
8  */
9 
10 #include <crm_internal.h>
11 
13 
14 #include <glib.h>
15 
16 static void
17 empty_input_list(void **state) {
18  assert_false(pcmk__str_in_list(NULL, NULL, pcmk__str_none));
19  assert_false(pcmk__str_in_list(NULL, NULL, pcmk__str_null_matches));
20  assert_false(pcmk__str_in_list("xxx", NULL, pcmk__str_none));
21  assert_false(pcmk__str_in_list("", NULL, pcmk__str_none));
22 }
23 
24 static void
25 empty_string(void **state) {
26  GList *list = NULL;
27 
28  list = g_list_prepend(list, (gpointer) "xxx");
29 
30  assert_false(pcmk__str_in_list(NULL, list, pcmk__str_none));
31  assert_true(pcmk__str_in_list(NULL, list, pcmk__str_null_matches));
32  assert_false(pcmk__str_in_list("", list, pcmk__str_none));
33  assert_false(pcmk__str_in_list("", list, pcmk__str_null_matches));
34 
35  g_list_free(list);
36 }
37 
38 static void
39 star_matches(void **state) {
40  GList *list = NULL;
41 
42  list = g_list_prepend(list, (gpointer) "*");
43  list = g_list_append(list, (gpointer) "more");
44 
45  assert_true(pcmk__str_in_list("xxx", list, pcmk__str_star_matches));
46  assert_true(pcmk__str_in_list("yyy", list, pcmk__str_star_matches));
47  assert_true(pcmk__str_in_list("XXX", list, pcmk__str_star_matches|pcmk__str_casei));
48  assert_true(pcmk__str_in_list("", list, pcmk__str_star_matches));
49 
50  g_list_free(list);
51 }
52 
53 static void
54 star_doesnt_match(void **state) {
55  GList *list = NULL;
56 
57  list = g_list_prepend(list, (gpointer) "*");
58 
59  assert_false(pcmk__str_in_list("xxx", list, pcmk__str_none));
60  assert_false(pcmk__str_in_list("yyy", list, pcmk__str_none));
61  assert_false(pcmk__str_in_list("XXX", list, pcmk__str_casei));
62  assert_false(pcmk__str_in_list("", list, pcmk__str_none));
63  assert_false(pcmk__str_in_list(NULL, list, pcmk__str_star_matches));
64 
65  g_list_free(list);
66 }
67 
68 static void
69 in_list(void **state) {
70  GList *list = NULL;
71 
72  list = g_list_prepend(list, (gpointer) "xxx");
73  list = g_list_prepend(list, (gpointer) "yyy");
74  list = g_list_prepend(list, (gpointer) "zzz");
75 
76  assert_true(pcmk__str_in_list("xxx", list, pcmk__str_none));
77  assert_true(pcmk__str_in_list("XXX", list, pcmk__str_casei));
78  assert_true(pcmk__str_in_list("yyy", list, pcmk__str_none));
79  assert_true(pcmk__str_in_list("YYY", list, pcmk__str_casei));
80  assert_true(pcmk__str_in_list("zzz", list, pcmk__str_none));
81  assert_true(pcmk__str_in_list("ZZZ", list, pcmk__str_casei));
82 
83  g_list_free(list);
84 }
85 
86 static void
87 not_in_list(void **state) {
88  GList *list = NULL;
89 
90  list = g_list_prepend(list, (gpointer) "xxx");
91  list = g_list_prepend(list, (gpointer) "yyy");
92 
93  assert_false(pcmk__str_in_list("xx", list, pcmk__str_none));
94  assert_false(pcmk__str_in_list("XXX", list, pcmk__str_none));
95  assert_false(pcmk__str_in_list("zzz", list, pcmk__str_none));
96  assert_false(pcmk__str_in_list("zzz", list, pcmk__str_casei));
97 
98  g_list_free(list);
99 }
100 
101 PCMK__UNIT_TEST(NULL, NULL,
102  cmocka_unit_test(empty_input_list),
103  cmocka_unit_test(empty_string),
104  cmocka_unit_test(star_matches),
105  cmocka_unit_test(star_doesnt_match),
106  cmocka_unit_test(in_list),
107  cmocka_unit_test(not_in_list))
PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(bad_input), cmocka_unit_test(not_found), cmocka_unit_test(find_attrB), cmocka_unit_test(find_attrA_matching))
gboolean pcmk__str_in_list(const gchar *s, const GList *lst, uint32_t flags)
Definition: strings.c:888