pacemaker 3.0.1-16e74fc4da
Scalable High-Availability cluster resource manager
Loading...
Searching...
No Matches
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
14static void
15bad_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
26static void
27ends_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
41static void
42ends_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
54PCMK__UNIT_TEST(NULL, NULL,
55 cmocka_unit_test(bad_input),
56 cmocka_unit_test(ends_with),
57 cmocka_unit_test(ends_with_ext))
bool pcmk__ends_with_ext(const char *s, const char *match)
Definition strings.c:637
bool pcmk__ends_with(const char *s, const char *match)
Definition strings.c:610
#define PCMK__UNIT_TEST(group_setup, group_teardown,...)