pacemaker  2.1.9-49aab99839
Scalable High-Availability cluster resource manager
pcmk__output_and_clear_error_test.c
Go to the documentation of this file.
1 /*
2  * Copyright 2022-2023 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 #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  /* This function intentionally left blank */
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 
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) {
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);
79 }
80 
81 PCMK__UNIT_TEST(NULL, NULL,
82  cmocka_unit_test_setup_teardown(standard_usage, 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(*) int(*) void(* err)(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
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
void pcmk__output_and_clear_error(GError **error, pcmk__output_t *out)
Definition: output.c:215
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
#define PCMK__RC_ERROR