pacemaker  2.1.2-ada5c3b36
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 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 <stdarg.h>
13 #include <stddef.h>
14 #include <stdint.h>
15 #include <setjmp.h>
16 #include <cmocka.h>
17 
18 static void
19 bad_input(void **state) {
20  assert_false(pcmk__starts_with(NULL, "x"));
21  assert_false(pcmk__starts_with("abc", NULL));
22 }
23 
24 static void
25 starts_with(void **state) {
26  assert_true(pcmk__starts_with("abc", "a"));
27  assert_true(pcmk__starts_with("abc", "ab"));
28  assert_true(pcmk__starts_with("abc", "abc"));
29 
30  assert_false(pcmk__starts_with("abc", "A"));
31  assert_false(pcmk__starts_with("abc", "bc"));
32 
33  assert_false(pcmk__starts_with("", "x"));
34  assert_true(pcmk__starts_with("xyz", ""));
35 }
36 
37 int
38 main(int argc, char **argv)
39 {
40  const struct CMUnitTest tests[] = {
41  cmocka_unit_test(bad_input),
42  cmocka_unit_test(starts_with),
43  };
44 
45  cmocka_set_message_output(CM_OUTPUT_TAP);
46  return cmocka_run_group_tests(tests, NULL, NULL);
47 }
int main(int argc, char **argv)
bool pcmk__starts_with(const char *str, const char *prefix)
Check whether a string starts with a certain sequence.
Definition: strings.c:484