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