1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
/*
* Copyright 2020-2021 the Pacemaker project contributors
*
* The version control history for this file may have further details.
*
* This source code is licensed under the GNU General Public License version 2
* or later (GPLv2+) WITHOUT ANY WARRANTY.
*/
#include <crm_internal.h>
#include <crm/common/unittest_internal.h>
static void
same_pointer(void **state) {
const char *s1 = "abcd";
const char *s2 = "wxyz";
assert_int_equal(pcmk__strcmp(s1, s1, pcmk__str_none), 0);
assert_true(pcmk__str_eq(s1, s1, pcmk__str_none));
assert_int_not_equal(pcmk__strcmp(s1, s2, pcmk__str_none), 0);
assert_false(pcmk__str_eq(s1, s2, pcmk__str_none));
assert_int_equal(pcmk__strcmp(NULL, NULL, pcmk__str_none), 0);
}
static void
one_is_null(void **state) {
const char *s1 = "abcd";
assert_int_equal(pcmk__strcmp(s1, NULL, pcmk__str_null_matches), 0);
assert_true(pcmk__str_eq(s1, NULL, pcmk__str_null_matches));
assert_int_equal(pcmk__strcmp(NULL, s1, pcmk__str_null_matches), 0);
assert_true(pcmk__strcmp(s1, NULL, pcmk__str_none) > 0);
assert_false(pcmk__str_eq(s1, NULL, pcmk__str_none));
assert_true(pcmk__strcmp(NULL, s1, pcmk__str_none) < 0);
}
static void
case_matters(void **state) {
const char *s1 = "abcd";
const char *s2 = "ABCD";
assert_true(pcmk__strcmp(s1, s2, pcmk__str_none) > 0);
assert_false(pcmk__str_eq(s1, s2, pcmk__str_none));
assert_true(pcmk__strcmp(s2, s1, pcmk__str_none) < 0);
}
static void
case_insensitive(void **state) {
const char *s1 = "abcd";
const char *s2 = "ABCD";
assert_int_equal(pcmk__strcmp(s1, s2, pcmk__str_casei), 0);
assert_true(pcmk__str_eq(s1, s2, pcmk__str_casei));
}
static void
regex(void **state) {
const char *s1 = "abcd";
const char *s2 = "ABCD";
assert_true(pcmk__strcmp(NULL, "a..d", pcmk__str_regex) > 0);
assert_true(pcmk__strcmp(s1, NULL, pcmk__str_regex) > 0);
assert_int_equal(pcmk__strcmp(s1, "a..d", pcmk__str_regex), 0);
assert_true(pcmk__str_eq(s1, "a..d", pcmk__str_regex));
assert_int_not_equal(pcmk__strcmp(s1, "xxyy", pcmk__str_regex), 0);
assert_false(pcmk__str_eq(s1, "xxyy", pcmk__str_regex));
assert_int_equal(pcmk__strcmp(s2, "a..d", pcmk__str_regex|pcmk__str_casei), 0);
assert_true(pcmk__str_eq(s2, "a..d", pcmk__str_regex|pcmk__str_casei));
assert_int_not_equal(pcmk__strcmp(s2, "a..d", pcmk__str_regex), 0);
assert_false(pcmk__str_eq(s2, "a..d", pcmk__str_regex));
assert_true(pcmk__strcmp(s2, "*ab", pcmk__str_regex) > 0);
}
PCMK__UNIT_TEST(NULL, NULL,
cmocka_unit_test(same_pointer),
cmocka_unit_test(one_is_null),
cmocka_unit_test(case_matters),
cmocka_unit_test(case_insensitive),
cmocka_unit_test(regex))
|