pacemaker  2.1.7-0f7f88312f
Scalable High-Availability cluster resource manager
pcmk__ends_with_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 static void
15 bad_input(void **state) {
16  assert_false(pcmk__ends_with(NULL, "xyz"));
17 
18  assert_true(pcmk__ends_with(NULL, NULL));
19  assert_true(pcmk__ends_with(NULL, ""));
20  assert_true(pcmk__ends_with("", NULL));
21  assert_true(pcmk__ends_with("", ""));
22  assert_true(pcmk__ends_with("abc", NULL));
23  assert_true(pcmk__ends_with("abc", ""));
24 }
25 
26 static void
27 ends_with(void **state) {
28  assert_true(pcmk__ends_with("abc", "abc"));
29  assert_true(pcmk__ends_with("abc", "bc"));
30  assert_true(pcmk__ends_with("abc", "c"));
31  assert_true(pcmk__ends_with("abcbc", "bc"));
32 
33  assert_false(pcmk__ends_with("abc", "def"));
34  assert_false(pcmk__ends_with("abc", "defg"));
35  assert_false(pcmk__ends_with("abc", "bcd"));
36  assert_false(pcmk__ends_with("abc", "ab"));
37 
38  assert_false(pcmk__ends_with("abc", "BC"));
39 }
40 
41 static void
42 ends_with_ext(void **state) {
43  assert_true(pcmk__ends_with_ext("ab.c", ".c"));
44  assert_true(pcmk__ends_with_ext("ab.cb.c", ".c"));
45 
46  assert_false(pcmk__ends_with_ext("ab.c", ".def"));
47  assert_false(pcmk__ends_with_ext("ab.c", ".defg"));
48  assert_false(pcmk__ends_with_ext("ab.c", ".cd"));
49  assert_false(pcmk__ends_with_ext("ab.c", "ab"));
50 
51  assert_false(pcmk__ends_with_ext("ab.c", ".C"));
52 }
53 
54 PCMK__UNIT_TEST(NULL, NULL,
55  cmocka_unit_test(bad_input),
56  cmocka_unit_test(ends_with),
57  cmocka_unit_test(ends_with_ext))
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))
bool pcmk__ends_with(const char *s, const char *match)
Definition: strings.c:533
bool pcmk__ends_with_ext(const char *s, const char *match)
Definition: strings.c:560