pacemaker 3.0.1-16e74fc4da
Scalable High-Availability cluster resource manager
Loading...
Searching...
No Matches
pcmk__strcmp_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 General Public License version 2
7 * or later (GPLv2+) WITHOUT ANY WARRANTY.
8 */
9
10#include <crm_internal.h>
11
13
14static void
15same_pointer(void **state) {
16 const char *s1 = "abcd";
17 const char *s2 = "wxyz";
18
19 assert_int_equal(pcmk__strcmp(s1, s1, pcmk__str_none), 0);
20 assert_true(pcmk__str_eq(s1, s1, pcmk__str_none));
21 assert_int_not_equal(pcmk__strcmp(s1, s2, pcmk__str_none), 0);
22 assert_false(pcmk__str_eq(s1, s2, pcmk__str_none));
23 assert_int_equal(pcmk__strcmp(NULL, NULL, pcmk__str_none), 0);
24}
25
26static void
27one_is_null(void **state) {
28 const char *s1 = "abcd";
29
30 assert_int_equal(pcmk__strcmp(s1, NULL, pcmk__str_null_matches), 0);
31 assert_true(pcmk__str_eq(s1, NULL, pcmk__str_null_matches));
32 assert_int_equal(pcmk__strcmp(NULL, s1, pcmk__str_null_matches), 0);
33 assert_true(pcmk__strcmp(s1, NULL, pcmk__str_none) > 0);
34 assert_false(pcmk__str_eq(s1, NULL, pcmk__str_none));
35 assert_true(pcmk__strcmp(NULL, s1, pcmk__str_none) < 0);
36}
37
38static void
39case_matters(void **state) {
40 const char *s1 = "abcd";
41 const char *s2 = "ABCD";
42
43 assert_true(pcmk__strcmp(s1, s2, pcmk__str_none) > 0);
44 assert_false(pcmk__str_eq(s1, s2, pcmk__str_none));
45 assert_true(pcmk__strcmp(s2, s1, pcmk__str_none) < 0);
46}
47
48static void
49case_insensitive(void **state) {
50 const char *s1 = "abcd";
51 const char *s2 = "ABCD";
52
53 assert_int_equal(pcmk__strcmp(s1, s2, pcmk__str_casei), 0);
54 assert_true(pcmk__str_eq(s1, s2, pcmk__str_casei));
55}
56
57static void
58regex(void **state) {
59 const char *s1 = "abcd";
60 const char *s2 = "ABCD";
61
62 assert_true(pcmk__strcmp(NULL, "a..d", pcmk__str_regex) > 0);
63 assert_true(pcmk__strcmp(s1, NULL, pcmk__str_regex) > 0);
64 assert_int_equal(pcmk__strcmp(s1, "a..d", pcmk__str_regex), 0);
65 assert_true(pcmk__str_eq(s1, "a..d", pcmk__str_regex));
66 assert_int_not_equal(pcmk__strcmp(s1, "xxyy", pcmk__str_regex), 0);
67 assert_false(pcmk__str_eq(s1, "xxyy", pcmk__str_regex));
68 assert_int_equal(pcmk__strcmp(s2, "a..d", pcmk__str_regex|pcmk__str_casei), 0);
69 assert_true(pcmk__str_eq(s2, "a..d", pcmk__str_regex|pcmk__str_casei));
70 assert_int_not_equal(pcmk__strcmp(s2, "a..d", pcmk__str_regex), 0);
71 assert_false(pcmk__str_eq(s2, "a..d", pcmk__str_regex));
72 assert_true(pcmk__strcmp(s2, "*ab", pcmk__str_regex) > 0);
73}
74
75PCMK__UNIT_TEST(NULL, NULL,
76 cmocka_unit_test(same_pointer),
77 cmocka_unit_test(one_is_null),
78 cmocka_unit_test(case_matters),
79 cmocka_unit_test(case_insensitive),
80 cmocka_unit_test(regex))
@ pcmk__str_regex
@ pcmk__str_none
@ pcmk__str_null_matches
@ pcmk__str_casei
int pcmk__strcmp(const char *s1, const char *s2, uint32_t flags)
Definition strings.c:1166
#define PCMK__UNIT_TEST(group_setup, group_teardown,...)