This source file includes following definitions.
- add_words
- add_with_no_len
- add_nothing
- add_with_null
- add_with_comma
- add_with_comma_and_space
- main
1
2
3
4
5
6
7
8
9
10 #include <stdio.h>
11 #include <string.h>
12 #include <sys/types.h>
13 #include <crm_internal.h>
14
15 static void
16 add_words(void)
17 {
18 char *list = NULL;
19 size_t list_len = 0;
20
21 pcmk__add_word(&list, &list_len, "hello");
22 pcmk__add_word(&list, &list_len, "world");
23 g_assert_cmpint(strcmp(list, "hello world"), ==, 0);
24 }
25
26 static void
27 add_with_no_len(void)
28 {
29 char *list = NULL;
30
31 pcmk__add_word(&list, NULL, "hello");
32 pcmk__add_word(&list, NULL, "world");
33 g_assert_cmpint(strcmp(list, "hello world"), ==, 0);
34 }
35
36 static void
37 add_nothing(void)
38 {
39 char *list = NULL;
40
41 pcmk__add_word(&list, NULL, "hello");
42 pcmk__add_word(&list, NULL, NULL);
43 pcmk__add_word(&list, NULL, "");
44 g_assert_cmpint(strcmp(list, "hello"), ==, 0);
45 }
46
47 static void
48 add_with_null(void)
49 {
50 char *list = NULL;
51 size_t list_len = 0;
52
53 pcmk__add_separated_word(&list, &list_len, "hello", NULL);
54 pcmk__add_separated_word(&list, &list_len, "world", NULL);
55 pcmk__add_separated_word(&list, &list_len, "I am a unit test", NULL);
56 g_assert_cmpint(strcmp(list, "hello world I am a unit test"), ==, 0);
57 }
58
59 static void
60 add_with_comma(void)
61 {
62 char *list = NULL;
63 size_t list_len = 0;
64
65 pcmk__add_separated_word(&list, &list_len, "hello", ",");
66 pcmk__add_separated_word(&list, &list_len, "world", ",");
67 pcmk__add_separated_word(&list, &list_len, "I am a unit test", ",");
68 g_assert_cmpint(strcmp(list, "hello,world,I am a unit test"), ==, 0);
69 }
70
71 static void
72 add_with_comma_and_space(void)
73 {
74 char *list = NULL;
75 size_t list_len = 0;
76
77 pcmk__add_separated_word(&list, &list_len, "hello", ", ");
78 pcmk__add_separated_word(&list, &list_len, "world", ", ");
79 pcmk__add_separated_word(&list, &list_len, "I am a unit test", ", ");
80 g_assert_cmpint(strcmp(list, "hello, world, I am a unit test"), ==, 0);
81 }
82
83 int
84 main(int argc, char **argv)
85 {
86 g_test_init(&argc, &argv, NULL);
87
88 g_test_add_func("/common/strings/add_word/add_words", add_words);
89 g_test_add_func("/common/strings/add_word/add_with_no_len",
90 add_with_no_len);
91 g_test_add_func("/common/strings/add_word/add_nothing", add_nothing);
92 g_test_add_func("/common/strings/add_word/add_with_null", add_with_null);
93 g_test_add_func("/common/strings/add_word/add_with_comma", add_with_comma);
94 g_test_add_func("/common/strings/add_word/add_with_comma_and_space",
95 add_with_comma_and_space);
96
97 return g_test_run();
98 }