This source file includes following definitions.
- null_create_fn
- null_create_fn_2
- no_formats
- invalid_entries
- valid_entries
- duplicate_keys
- duplicate_values
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 pcmk__output_t *
16 null_create_fn(char **argv) {
17 return NULL;
18 }
19
20 static pcmk__output_t *
21 null_create_fn_2(char **argv) {
22 return NULL;
23 }
24
25 static void
26 no_formats(void **state) {
27 pcmk__register_formats(NULL, NULL);
28 assert_null(pcmk__output_formatters());
29 }
30
31 static void
32 invalid_entries(void **state) {
33
34
35
36 pcmk__supported_format_t formats[] = {
37 { "", null_create_fn, NULL },
38 { NULL },
39 };
40
41 pcmk__assert_asserts(pcmk__register_formats(NULL, formats));
42 }
43
44 static void
45 valid_entries(void **state) {
46 GHashTable *formatters = NULL;
47
48 pcmk__supported_format_t formats[] = {
49 { "fmt1", null_create_fn, NULL },
50 { "fmt2", null_create_fn_2, NULL },
51 { NULL },
52 };
53
54 pcmk__register_formats(NULL, formats);
55
56 formatters = pcmk__output_formatters();
57 assert_int_equal(g_hash_table_size(formatters), 2);
58 assert_ptr_equal(g_hash_table_lookup(formatters, "fmt1"), null_create_fn);
59 assert_ptr_equal(g_hash_table_lookup(formatters, "fmt2"), null_create_fn_2);
60
61 pcmk__unregister_formats();
62 }
63
64 static void
65 duplicate_keys(void **state) {
66 GHashTable *formatters = NULL;
67
68 pcmk__supported_format_t formats[] = {
69 { "fmt1", null_create_fn, NULL },
70 { "fmt1", null_create_fn_2, NULL },
71 { NULL },
72 };
73
74 pcmk__register_formats(NULL, formats);
75
76 formatters = pcmk__output_formatters();
77 assert_int_equal(g_hash_table_size(formatters), 1);
78 assert_ptr_equal(g_hash_table_lookup(formatters, "fmt1"), null_create_fn_2);
79
80 pcmk__unregister_formats();
81 }
82
83 static void
84 duplicate_values(void **state) {
85 GHashTable *formatters = NULL;
86
87 pcmk__supported_format_t formats[] = {
88 { "fmt1", null_create_fn, NULL },
89 { "fmt2", null_create_fn, NULL },
90 { NULL },
91 };
92
93 pcmk__register_formats(NULL, formats);
94
95 formatters = pcmk__output_formatters();
96 assert_int_equal(g_hash_table_size(formatters), 2);
97 assert_ptr_equal(g_hash_table_lookup(formatters, "fmt1"), null_create_fn);
98 assert_ptr_equal(g_hash_table_lookup(formatters, "fmt2"), null_create_fn);
99
100 pcmk__unregister_formats();
101 }
102
103 PCMK__UNIT_TEST(NULL, NULL,
104 cmocka_unit_test(no_formats),
105 cmocka_unit_test(invalid_entries),
106 cmocka_unit_test(valid_entries),
107 cmocka_unit_test(duplicate_keys),
108 cmocka_unit_test(duplicate_values))