This source file includes following definitions.
- null_message_fn
- fake_text_init
- fake_text_free_priv
- mk_fake_text_output
- setup
- teardown
- no_messages
- messages
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 bool
21 fake_text_init(pcmk__output_t *out) {
22 return true;
23 }
24
25 static void
26 fake_text_free_priv(pcmk__output_t *out) {
27 function_called();
28
29 }
30
31 static pcmk__output_t *
32 mk_fake_text_output(char **argv) {
33 pcmk__output_t *retval = calloc(1, sizeof(pcmk__output_t));
34
35 if (retval == NULL) {
36 return NULL;
37 }
38
39 retval->fmt_name = "text";
40 retval->init = fake_text_init;
41 retval->free_priv = fake_text_free_priv;
42
43 retval->register_message = pcmk__register_message;
44 retval->message = pcmk__call_message;
45
46 return retval;
47 }
48
49 static int
50 setup(void **state) {
51 pcmk__register_format(NULL, "text", mk_fake_text_output, NULL);
52 return 0;
53 }
54
55 static int
56 teardown(void **state) {
57 pcmk__unregister_formats();
58 return 0;
59 }
60
61 static void
62 no_messages(void **state) {
63 pcmk__output_t *out = NULL;
64
65 pcmk__output_new(&out, "text", NULL, NULL);
66
67 expect_function_call(fake_text_free_priv);
68 pcmk__output_free(out);
69 }
70
71 static void
72 messages(void **state) {
73 pcmk__output_t *out = NULL;
74
75 pcmk__output_new(&out, "text", NULL, NULL);
76 pcmk__register_message(out, "fake", null_message_fn);
77
78 expect_function_call(fake_text_free_priv);
79 pcmk__output_free(out);
80 }
81
82 PCMK__UNIT_TEST(NULL, NULL,
83 cmocka_unit_test_setup_teardown(no_messages, setup, teardown),
84 cmocka_unit_test_setup_teardown(messages, setup, teardown))