pacemaker 3.0.1-16e74fc4da
Scalable High-Availability cluster resource manager
Loading...
Searching...
No Matches
pcmk__register_format_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
15static pcmk__output_t *
16null_create_fn(char **argv) {
17 return NULL;
18}
19
20static pcmk__output_t *
21null_create_fn_2(char **argv) {
22 return NULL;
23}
24
25static void
26invalid_params(void **state) {
27 pcmk__assert_asserts(pcmk__register_format(NULL, "fake", NULL, NULL));
28 pcmk__assert_asserts(pcmk__register_format(NULL, "", null_create_fn, NULL));
29 pcmk__assert_asserts(pcmk__register_format(NULL, NULL, null_create_fn, NULL));
30}
31
32static void
33add_format(void **state) {
34 GHashTable *formatters = NULL;
35 gpointer value;
36
37 /* For starters, there should be no formatters defined. */
38 assert_null(pcmk__output_formatters());
39
40 /* Add a fake formatter and check that it's the only item in the hash table. */
41 assert_int_equal(pcmk__register_format(NULL, "fake", null_create_fn, NULL), pcmk_rc_ok);
42 formatters = pcmk__output_formatters();
43 assert_int_equal(g_hash_table_size(formatters), 1);
44
45 value = g_hash_table_lookup(formatters, "fake");
46 assert_ptr_equal(value, null_create_fn);
47
48 /* Add a second fake formatter which should overwrite the first one, leaving
49 * only one item in the hash table but pointing at the new function.
50 */
51 assert_int_equal(pcmk__register_format(NULL, "fake", null_create_fn_2, NULL), pcmk_rc_ok);
52 formatters = pcmk__output_formatters();
53 assert_int_equal(g_hash_table_size(formatters), 1);
54
55 value = g_hash_table_lookup(formatters, "fake");
56 assert_ptr_equal(value, null_create_fn_2);
57
59}
60
61PCMK__UNIT_TEST(NULL, NULL,
62 cmocka_unit_test(invalid_params),
63 cmocka_unit_test(add_format))
Formatted output for pacemaker tools.
int pcmk__register_format(GOptionGroup *group, const char *name, pcmk__output_factory_t create, const GOptionEntry *options)
Definition output.c:127
void pcmk__unregister_formats(void)
Definition output.c:168
@ pcmk_rc_ok
Definition results.h:159
This structure contains everything that makes up a single output formatter.
#define pcmk__assert_asserts(stmt)
#define PCMK__UNIT_TEST(group_setup, group_teardown,...)