pacemaker  2.1.8-3980678f03
Scalable High-Availability cluster resource manager
pcmk__starts_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__starts_with(NULL, "x"));
17  assert_false(pcmk__starts_with("abc", NULL));
18 }
19 
20 static void
21 starts_with(void **state) {
22  assert_true(pcmk__starts_with("abc", "a"));
23  assert_true(pcmk__starts_with("abc", "ab"));
24  assert_true(pcmk__starts_with("abc", "abc"));
25 
26  assert_false(pcmk__starts_with("abc", "A"));
27  assert_false(pcmk__starts_with("abc", "bc"));
28 
29  assert_false(pcmk__starts_with("", "x"));
30  assert_true(pcmk__starts_with("xyz", ""));
31 }
32 
33 PCMK__UNIT_TEST(NULL, NULL,
34  cmocka_unit_test(bad_input),
35  cmocka_unit_test(starts_with))
#define PCMK__UNIT_TEST(group_setup, group_teardown,...)
bool pcmk__starts_with(const char *str, const char *prefix)
Check whether a string starts with a certain sequence.
Definition: strings.c:556