This source file includes following definitions.
- null_message_fn
- null_message_fn_2
- fake_text_init
- fake_text_free_priv
- mk_fake_text_output
- setup
- teardown
- null_params
- add_message
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <crm/common/unittest_internal.h>
13 #include <crm/common/output_internal.h>
14
15 static int
16 null_message_fn(pcmk__output_t *out, va_list args) {
17 return pcmk_rc_ok;
18 }
19
20 static int
21 null_message_fn_2(pcmk__output_t *out, va_list args) {
22 return pcmk_rc_ok;
23 }
24
25 static bool
26 fake_text_init(pcmk__output_t *out) {
27 return true;
28 }
29
30 static void
31 fake_text_free_priv(pcmk__output_t *out) {
32
33 }
34
35 static pcmk__output_t *
36 mk_fake_text_output(char **argv) {
37 pcmk__output_t *retval = calloc(1, sizeof(pcmk__output_t));
38
39 if (retval == NULL) {
40 return NULL;
41 }
42
43 retval->fmt_name = "text";
44 retval->init = fake_text_init;
45 retval->free_priv = fake_text_free_priv;
46
47 retval->register_message = pcmk__register_message;
48 retval->message = pcmk__call_message;
49
50 return retval;
51 }
52
53 static int
54 setup(void **state) {
55 pcmk__register_format(NULL, "text", mk_fake_text_output, NULL);
56 return 0;
57 }
58
59 static int
60 teardown(void **state) {
61 pcmk__unregister_formats();
62 return 0;
63 }
64
65 static void
66 null_params(void **state) {
67 pcmk__output_t *out = NULL;
68
69 pcmk__output_new(&out, "text", NULL, NULL);
70
71 pcmk__assert_asserts(pcmk__register_message(NULL, "fake", null_message_fn));
72 pcmk__assert_asserts(pcmk__register_message(out, NULL, null_message_fn));
73 pcmk__assert_asserts(pcmk__register_message(out, "", null_message_fn));
74 pcmk__assert_asserts(pcmk__register_message(out, "fake", NULL));
75
76 pcmk__output_free(out);
77 }
78
79 static void
80 add_message(void **state) {
81 pcmk__output_t *out = NULL;
82
83 pcmk__output_new(&out, "text", NULL, NULL);
84
85
86 assert_int_equal(g_hash_table_size(out->messages), 0);
87
88
89 pcmk__register_message(out, "fake", null_message_fn);
90 assert_int_equal(g_hash_table_size(out->messages), 1);
91 assert_ptr_equal(g_hash_table_lookup(out->messages, "fake"), null_message_fn);
92
93
94
95
96 pcmk__register_message(out, "fake", null_message_fn_2);
97 assert_int_equal(g_hash_table_size(out->messages), 1);
98 assert_ptr_equal(g_hash_table_lookup(out->messages, "fake"), null_message_fn_2);
99
100 pcmk__output_free(out);
101 }
102
103 PCMK__UNIT_TEST(NULL, NULL,
104 cmocka_unit_test_setup_teardown(null_params, setup, teardown),
105 cmocka_unit_test_setup_teardown(add_message, setup, teardown))