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
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <crm/common/unittest_internal.h>
13
14 static void
15 add_words(void **state)
16 {
17 GString *list = NULL;
18
19 pcmk__add_word(&list, 16, "hello");
20 pcmk__add_word(&list, 16, "world");
21 assert_int_equal(strcmp((const char *) list->str, "hello world"), 0);
22 g_string_free(list, TRUE);
23 }
24
25 static void
26 add_with_no_len(void **state)
27 {
28 GString *list = NULL;
29
30 pcmk__add_word(&list, 0, "hello");
31 pcmk__add_word(&list, 0, "world");
32 assert_int_equal(strcmp((const char *) list->str, "hello world"), 0);
33 g_string_free(list, TRUE);
34 }
35
36 static void
37 add_nothing(void **state)
38 {
39 GString *list = NULL;
40
41 pcmk__add_word(&list, 0, "hello");
42 pcmk__add_word(&list, 0, NULL);
43 pcmk__add_word(&list, 0, "");
44 assert_int_equal(strcmp((const char *) list->str, "hello"), 0);
45 g_string_free(list, TRUE);
46 }
47
48 static void
49 add_with_null(void **state)
50 {
51 GString *list = NULL;
52
53 pcmk__add_separated_word(&list, 32, "hello", NULL);
54 pcmk__add_separated_word(&list, 32, "world", NULL);
55 pcmk__add_separated_word(&list, 32, "I am a unit test", NULL);
56 assert_int_equal(strcmp((const char *) list->str,
57 "hello world I am a unit test"), 0);
58 g_string_free(list, TRUE);
59 }
60
61 static void
62 add_with_comma(void **state)
63 {
64 GString *list = NULL;
65
66 pcmk__add_separated_word(&list, 32, "hello", ",");
67 pcmk__add_separated_word(&list, 32, "world", ",");
68 pcmk__add_separated_word(&list, 32, "I am a unit test", ",");
69 assert_int_equal(strcmp((const char *) list->str,
70 "hello,world,I am a unit test"), 0);
71 g_string_free(list, TRUE);
72 }
73
74 static void
75 add_with_comma_and_space(void **state)
76 {
77 GString *list = NULL;
78
79 pcmk__add_separated_word(&list, 32, "hello", ", ");
80 pcmk__add_separated_word(&list, 32, "world", ", ");
81 pcmk__add_separated_word(&list, 32, "I am a unit test", ", ");
82 assert_int_equal(strcmp((const char *) list->str,
83 "hello, world, I am a unit test"), 0);
84 g_string_free(list, TRUE);
85 }
86
87 PCMK__UNIT_TEST(NULL, NULL,
88 cmocka_unit_test(add_words),
89 cmocka_unit_test(add_with_no_len),
90 cmocka_unit_test(add_nothing),
91 cmocka_unit_test(add_with_null),
92 cmocka_unit_test(add_with_comma),
93 cmocka_unit_test(add_with_comma_and_space))