This source file includes following definitions.
- fake_text_init
- fake_text_free_priv
- G_GNUC_PRINTF
- mk_fake_text_output
- setup
- teardown
- standard_usage
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 <glib.h>
16
17 static bool
18 fake_text_init(pcmk__output_t *out) {
19 return true;
20 }
21
22 static void
23 fake_text_free_priv(pcmk__output_t *out) {
24
25 }
26
27 G_GNUC_PRINTF(2, 3)
28 static void
29 fake_text_err(pcmk__output_t *out, const char *format, ...) {
30 function_called();
31 }
32
33 static pcmk__output_t *
34 mk_fake_text_output(char **argv) {
35 pcmk__output_t *retval = calloc(1, sizeof(pcmk__output_t));
36
37 if (retval == NULL) {
38 return NULL;
39 }
40
41 retval->fmt_name = "text";
42 retval->init = fake_text_init;
43 retval->free_priv = fake_text_free_priv;
44
45 retval->register_message = pcmk__register_message;
46 retval->message = pcmk__call_message;
47
48 retval->err = fake_text_err;
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 standard_usage(void **state) {
67 GError *error = NULL;
68 pcmk__output_t *out = NULL;
69
70 pcmk__output_new(&out, "text", NULL, NULL);
71 g_set_error(&error, PCMK__RC_ERROR, pcmk_rc_bad_nvpair,
72 "some error message");
73
74 expect_function_call(fake_text_err);
75 pcmk__output_and_clear_error(error, out);
76
77 pcmk__output_free(out);
78 assert_null(error->message);
79 }
80
81 PCMK__UNIT_TEST(NULL, NULL,
82 cmocka_unit_test_setup_teardown(standard_usage, setup, teardown))