This source file includes following definitions.
- bad_input
- ends_with
- ends_with_ext
- main
1
2
3
4
5
6
7
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__ends_with(NULL, "xyz"));
21
22 assert_true(pcmk__ends_with(NULL, NULL));
23 assert_true(pcmk__ends_with(NULL, ""));
24 assert_true(pcmk__ends_with("", NULL));
25 assert_true(pcmk__ends_with("", ""));
26 assert_true(pcmk__ends_with("abc", NULL));
27 assert_true(pcmk__ends_with("abc", ""));
28 }
29
30 static void
31 ends_with(void **state) {
32 assert_true(pcmk__ends_with("abc", "abc"));
33 assert_true(pcmk__ends_with("abc", "bc"));
34 assert_true(pcmk__ends_with("abc", "c"));
35 assert_true(pcmk__ends_with("abcbc", "bc"));
36
37 assert_false(pcmk__ends_with("abc", "def"));
38 assert_false(pcmk__ends_with("abc", "defg"));
39 assert_false(pcmk__ends_with("abc", "bcd"));
40 assert_false(pcmk__ends_with("abc", "ab"));
41
42 assert_false(pcmk__ends_with("abc", "BC"));
43 }
44
45 static void
46 ends_with_ext(void **state) {
47 assert_true(pcmk__ends_with_ext("ab.c", ".c"));
48 assert_true(pcmk__ends_with_ext("ab.cb.c", ".c"));
49
50 assert_false(pcmk__ends_with_ext("ab.c", ".def"));
51 assert_false(pcmk__ends_with_ext("ab.c", ".defg"));
52 assert_false(pcmk__ends_with_ext("ab.c", ".cd"));
53 assert_false(pcmk__ends_with_ext("ab.c", "ab"));
54
55 assert_false(pcmk__ends_with_ext("ab.c", ".C"));
56 }
57
58 int
59 main(int argc, char **argv)
60 {
61 const struct CMUnitTest tests[] = {
62 cmocka_unit_test(bad_input),
63 cmocka_unit_test(ends_with),
64 cmocka_unit_test(ends_with_ext),
65 };
66
67 cmocka_set_message_output(CM_OUTPUT_TAP);
68 return cmocka_run_group_tests(tests, NULL, NULL);
69 }