This source file includes following definitions.
- empty_input
- leading_newline
- middle_newline
- trailing_newline
- other_whitespace
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <crm/common/unittest_internal.h>
13
14 #include <string.h>
15
16 static void
17 empty_input(void **state)
18 {
19 char *s = strdup("");
20
21 assert_null(pcmk__trim(NULL));
22 assert_string_equal(pcmk__trim(s), "");
23
24 free(s);
25 }
26
27 static void
28 leading_newline(void **state)
29 {
30 char *s = strdup("\nabcd");
31
32 assert_string_equal(pcmk__trim(s), "\nabcd");
33 free(s);
34 }
35
36 static void
37 middle_newline(void **state)
38 {
39 char *s = strdup("ab\ncd");
40
41 assert_string_equal(pcmk__trim(s), "ab\ncd");
42 free(s);
43 }
44
45 static void
46 trailing_newline(void **state)
47 {
48 char *s = strdup("abcd\n\n");
49
50 assert_string_equal(pcmk__trim(s), "abcd");
51 free(s);
52
53 s = strdup("abcd\n ");
54 assert_string_equal(pcmk__trim(s), "abcd\n ");
55 free(s);
56 }
57
58 static void
59 other_whitespace(void **state)
60 {
61 char *s = strdup(" ab\t\ncd \t");
62
63 assert_string_equal(pcmk__trim(s), " ab\t\ncd \t");
64 free(s);
65 }
66
67 PCMK__UNIT_TEST(NULL, NULL,
68 cmocka_unit_test(empty_input),
69 cmocka_unit_test(leading_newline),
70 cmocka_unit_test(middle_newline),
71 cmocka_unit_test(trailing_newline),
72 cmocka_unit_test(other_whitespace))