pacemaker 2.1.1-77db578727
Scalable High-Availability cluster resource manager
Loading...
Searching...
No Matches
pcmk__str_any_of_test.c
Go to the documentation of this file.
1/*
2 * Copyright 2020-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 <stdio.h>
13#include <stdbool.h>
14#include <glib.h>
15
16static void
17empty_input_list(void) {
18 g_assert_false(pcmk__strcase_any_of("xxx", NULL));
19 g_assert_false(pcmk__str_any_of("xxx", NULL));
20 g_assert_false(pcmk__strcase_any_of("", NULL));
21 g_assert_false(pcmk__str_any_of("", NULL));
22}
23
24static void
25empty_string(void) {
26 g_assert_false(pcmk__strcase_any_of("", "xxx", "yyy", NULL));
27 g_assert_false(pcmk__str_any_of("", "xxx", "yyy", NULL));
28 g_assert_false(pcmk__strcase_any_of(NULL, "xxx", "yyy", NULL));
29 g_assert_false(pcmk__str_any_of(NULL, "xxx", "yyy", NULL));
30}
31
32static void
33in_list(void) {
34 g_assert_true(pcmk__strcase_any_of("xxx", "aaa", "bbb", "xxx", NULL));
35 g_assert_true(pcmk__str_any_of("xxx", "aaa", "bbb", "xxx", NULL));
36 g_assert_true(pcmk__strcase_any_of("XXX", "aaa", "bbb", "xxx", NULL));
37}
38
39static void
40not_in_list(void) {
41 g_assert_false(pcmk__strcase_any_of("xxx", "aaa", "bbb", NULL));
42 g_assert_false(pcmk__str_any_of("xxx", "aaa", "bbb", NULL));
43 g_assert_false(pcmk__str_any_of("AAA", "aaa", "bbb", NULL));
44}
45
46int main(int argc, char **argv)
47{
48 g_test_init(&argc, &argv, NULL);
49
50 g_test_add_func("/common/strings/any_of/empty_list", empty_input_list);
51 g_test_add_func("/common/strings/any_of/empty_string", empty_string);
52 g_test_add_func("/common/strings/any_of/in", in_list);
53 g_test_add_func("/common/strings/any_of/not_in", not_in_list);
54
55 return g_test_run();
56}
int main(int argc, char **argv)
bool pcmk__strcase_any_of(const char *s,...) G_GNUC_NULL_TERMINATED
Definition strings.c:955
bool pcmk__str_any_of(const char *s,...) G_GNUC_NULL_TERMINATED
Definition strings.c:979