This source file includes following definitions.
- empty_input
- leading_newline
- middle_newline
- trailing_newline
- other_whitespace
- 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 #include <string.h>
19
20 static void
21 empty_input(void **state)
22 {
23 char *s = strdup("");
24
25 assert_null(pcmk__trim(NULL));
26 assert_string_equal(pcmk__trim(s), "");
27
28 free(s);
29 }
30
31 static void
32 leading_newline(void **state)
33 {
34 char *s = strdup("\nabcd");
35
36 assert_string_equal(pcmk__trim(s), "\nabcd");
37 free(s);
38 }
39
40 static void
41 middle_newline(void **state)
42 {
43 char *s = strdup("ab\ncd");
44
45 assert_string_equal(pcmk__trim(s), "ab\ncd");
46 free(s);
47 }
48
49 static void
50 trailing_newline(void **state)
51 {
52 char *s = strdup("abcd\n\n");
53
54 assert_string_equal(pcmk__trim(s), "abcd");
55 free(s);
56
57 s = strdup("abcd\n ");
58 assert_string_equal(pcmk__trim(s), "abcd\n ");
59 free(s);
60 }
61
62 static void
63 other_whitespace(void **state)
64 {
65 char *s = strdup(" ab\t\ncd \t");
66
67 assert_string_equal(pcmk__trim(s), " ab\t\ncd \t");
68 free(s);
69 }
70
71 int main(int argc, char **argv) {
72 const struct CMUnitTest tests[] = {
73 cmocka_unit_test(empty_input),
74 cmocka_unit_test(leading_newline),
75 cmocka_unit_test(middle_newline),
76 cmocka_unit_test(trailing_newline),
77 cmocka_unit_test(other_whitespace),
78 };
79
80 cmocka_set_message_output(CM_OUTPUT_TAP);
81 return cmocka_run_group_tests(tests, NULL, NULL);
82 }