This source file includes following definitions.
- add_to_null
- add_nothing
- add_words
- stop_early
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_to_null(void **state)
16 {
17 pcmk__assert_asserts(pcmk__g_strcat(NULL, NULL));
18 pcmk__assert_asserts(pcmk__g_strcat(NULL, "hello", NULL));
19 }
20
21 static void
22 add_nothing(void **state)
23 {
24 GString *buf = g_string_new(NULL);
25
26
27 pcmk__g_strcat(buf, NULL);
28 assert_string_equal((const char *) buf->str, "");
29
30 pcmk__g_strcat(buf, "", NULL);
31 assert_string_equal((const char *) buf->str, "");
32
33
34 g_string_append(buf, "hello");
35 pcmk__g_strcat(buf, NULL);
36 assert_string_equal((const char *) buf->str, "hello");
37
38 pcmk__g_strcat(buf, "", NULL);
39 assert_string_equal((const char *) buf->str, "hello");
40 g_string_free(buf, TRUE);
41 }
42
43 static void
44 add_words(void **state)
45 {
46 GString *buf = g_string_new(NULL);
47
48
49 pcmk__g_strcat(buf, "hello", " ", NULL);
50 assert_string_equal((const char *) buf->str, "hello ");
51
52
53 pcmk__g_strcat(buf, "world", NULL);
54 assert_string_equal((const char *) buf->str, "hello world");
55 g_string_free(buf, TRUE);
56 }
57
58 static void
59 stop_early(void **state)
60 {
61 GString *buf = g_string_new(NULL);
62
63
64 pcmk__g_strcat(buf, "hello", NULL, " world", NULL);
65 assert_string_equal((const char *) buf->str, "hello");
66 g_string_free(buf, TRUE);
67 }
68
69 PCMK__UNIT_TEST(NULL, NULL,
70 cmocka_unit_test(add_to_null),
71 cmocka_unit_test(add_nothing),
72 cmocka_unit_test(add_words),
73 cmocka_unit_test(stop_early))