pacemaker  2.1.9-49aab99839
Scalable High-Availability cluster resource manager
pcmk__output_free_test.c
Go to the documentation of this file.
1 /*
2  * Copyright 2022 the Pacemaker project contributors
3  *
4  * The version control history for this file may have further details.
5  *
6  * This source code is licensed under the GNU General Public License version 2
7  * or later (GPLv2+) WITHOUT ANY WARRANTY.
8  */
9 
10 #include <crm_internal.h>
11 
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  /* This function intentionally left blank */
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 
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) {
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))
int(* message)(pcmk__output_t *out, const char *message_id,...)
const char * fmt_name
The name of this output formatter.
void pcmk__register_message(pcmk__output_t *out, const char *message_id, pcmk__message_fn_t fn)
Definition: output.c:196
#define PCMK__UNIT_TEST(group_setup, group_teardown,...)
int pcmk__call_message(pcmk__output_t *out, const char *message_id,...)
Definition: output.c:174
Formatted output for pacemaker tools.
void(* register_message)(pcmk__output_t *out, const char *message_id, pcmk__message_fn_t fn)
void(* free_priv)(pcmk__output_t *out)
bool(* init)(pcmk__output_t *out)
int pcmk__register_format(GOptionGroup *group, const char *name, pcmk__output_factory_t create, const GOptionEntry *options)
Definition: output.c:127
void pcmk__output_free(pcmk__output_t *out)
Definition: output.c:30
void pcmk__unregister_formats(void)
Definition: output.c:166
This structure contains everything that makes up a single output formatter.
int pcmk__output_new(pcmk__output_t **out, const char *fmt_name, const char *filename, char **argv)
Definition: output.c:113