pacemaker 3.0.1-16e74fc4da
Scalable High-Availability cluster resource manager
Loading...
Searching...
No Matches
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
14static void
15bad_input(void **state) {
16 assert_false(pcmk__starts_with(NULL, "x"));
17 assert_false(pcmk__starts_with("abc", NULL));
18}
19
20static void
21starts_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
33PCMK__UNIT_TEST(NULL, NULL,
34 cmocka_unit_test(bad_input),
35 cmocka_unit_test(starts_with))
bool pcmk__starts_with(const char *str, const char *prefix)
Check whether a string starts with a certain sequence.
Definition strings.c:558
#define PCMK__UNIT_TEST(group_setup, group_teardown,...)