pacemaker  2.1.9-49aab99839
Scalable High-Availability cluster resource manager
pcmk__trim_test.c
Go to the documentation of this file.
1 /*
2  * Copyright 2022 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 
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))
#define PCMK__UNIT_TEST(group_setup, group_teardown,...)
char * pcmk__trim(char *str)
Definition: strings.c:540