This source file includes following definitions.
- assert_op_expression
- null_invalid
- id_missing
- name_missing
- input_name_missing
- fail_name
- invalid_interval
- default_interval
- fail_interval
- match_both
- fail_both
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <stdio.h>
13 #include <glib.h>
14
15 #include <crm/common/xml.h>
16 #include <crm/common/rules_internal.h>
17 #include <crm/common/unittest_internal.h>
18 #include "crmcommon_private.h"
19
20
21
22
23
24 static pcmk_rule_input_t rule_input = {
25
26 .op_name = PCMK_ACTION_MONITOR,
27 .op_interval_ms = 10000,
28 };
29
30
31
32
33
34
35
36
37 static void
38 assert_op_expression(const char *xml_string, int reference_rc)
39 {
40 xmlNode *xml = pcmk__xml_parse(xml_string);
41
42 assert_int_equal(pcmk__evaluate_op_expression(xml, &rule_input),
43 reference_rc);
44 free_xml(xml);
45 }
46
47
48
49
50
51
52 #define EXPR_FAIL_BOTH \
53 "<" PCMK_XE_OP_EXPRESSION " " PCMK_XA_ID "='e' " \
54 PCMK_XA_NAME "='" PCMK_ACTION_START "' " \
55 PCMK_XA_INTERVAL "='0' />"
56
57 static void
58 null_invalid(void **state)
59 {
60 xmlNode *xml = NULL;
61
62 assert_int_equal(pcmk__evaluate_op_expression(NULL, NULL), EINVAL);
63
64 xml = pcmk__xml_parse(EXPR_FAIL_BOTH);
65 assert_int_equal(pcmk__evaluate_op_expression(xml, NULL), EINVAL);
66 free_xml(xml);
67
68 assert_op_expression(NULL, EINVAL);
69 }
70
71
72
73
74
75
76 #define EXPR_ID_MISSING \
77 "<" PCMK_XE_OP_EXPRESSION " " \
78 PCMK_XA_NAME "='" PCMK_ACTION_MONITOR "' " \
79 PCMK_XA_INTERVAL "='10s' />"
80
81 #define EXPR_ID_EMPTY \
82 "<" PCMK_XE_OP_EXPRESSION " " PCMK_XA_ID "='' " \
83 PCMK_XA_NAME "='" PCMK_ACTION_MONITOR "' " \
84 PCMK_XA_INTERVAL "='10s' />"
85
86 static void
87 id_missing(void **state)
88 {
89
90 assert_op_expression(EXPR_ID_MISSING, pcmk_rc_ok);
91 assert_op_expression(EXPR_ID_EMPTY, pcmk_rc_ok);
92 }
93
94
95
96
97
98
99 #define EXPR_NAME_MISSING \
100 "<" PCMK_XE_OP_EXPRESSION " " PCMK_XA_ID "='e' " \
101 PCMK_XA_INTERVAL "='10s' />"
102
103 static void
104 name_missing(void **state)
105 {
106 assert_op_expression(EXPR_NAME_MISSING, pcmk_rc_unpack_error);
107 }
108
109 #define EXPR_MATCH_BOTH \
110 "<" PCMK_XE_OP_EXPRESSION " " PCMK_XA_ID "='e' " \
111 PCMK_XA_NAME "='" PCMK_ACTION_MONITOR "' " \
112 PCMK_XA_INTERVAL "='10s' />"
113
114 #define EXPR_EMPTY_NAME \
115 "<" PCMK_XE_OP_EXPRESSION " " PCMK_XA_ID "='e' " \
116 PCMK_XA_NAME "='' " PCMK_XA_INTERVAL "='10s' />"
117
118 static void
119 input_name_missing(void **state)
120 {
121 rule_input.op_name = NULL;
122 assert_op_expression(EXPR_MATCH_BOTH, pcmk_rc_op_unsatisfied);
123 assert_op_expression(EXPR_EMPTY_NAME, pcmk_rc_op_unsatisfied);
124 rule_input.op_name = PCMK_ACTION_MONITOR;
125 }
126
127 #define EXPR_FAIL_NAME \
128 "<" PCMK_XE_OP_EXPRESSION " " PCMK_XA_ID "='e' " \
129 PCMK_XA_NAME "='" PCMK_ACTION_START "' " \
130 PCMK_XA_INTERVAL "='10s' />"
131
132 static void
133 fail_name(void **state)
134 {
135 assert_op_expression(EXPR_FAIL_NAME, pcmk_rc_op_unsatisfied);
136
137
138 assert_op_expression(EXPR_EMPTY_NAME, pcmk_rc_op_unsatisfied);
139 }
140
141
142
143
144
145
146 #define EXPR_EMPTY_INTERVAL \
147 "<" PCMK_XE_OP_EXPRESSION " " PCMK_XA_ID "='e' " \
148 PCMK_XA_NAME "='" PCMK_ACTION_MONITOR "' " \
149 PCMK_XA_INTERVAL "='' />"
150
151 #define EXPR_INVALID_INTERVAL \
152 "<" PCMK_XE_OP_EXPRESSION " " PCMK_XA_ID "='e' " \
153 PCMK_XA_NAME "='" PCMK_ACTION_MONITOR "' " \
154 PCMK_XA_INTERVAL "='not-an-interval' />"
155
156 static void
157 invalid_interval(void **state)
158 {
159 assert_op_expression(EXPR_EMPTY_INTERVAL, pcmk_rc_unpack_error);
160 assert_op_expression(EXPR_INVALID_INTERVAL, pcmk_rc_unpack_error);
161 }
162
163 #define EXPR_DEFAULT_INTERVAL \
164 "<" PCMK_XE_OP_EXPRESSION " " PCMK_XA_ID "='e' " \
165 PCMK_XA_NAME "='" PCMK_ACTION_MONITOR "' />"
166
167 static void
168 default_interval(void **state)
169 {
170 assert_op_expression(EXPR_DEFAULT_INTERVAL, pcmk_rc_ok);
171 }
172
173 #define EXPR_FAIL_INTERVAL \
174 "<" PCMK_XE_OP_EXPRESSION " " PCMK_XA_ID "='e' " \
175 PCMK_XA_NAME "='" PCMK_ACTION_MONITOR "' " \
176 PCMK_XA_INTERVAL "='9s' />"
177
178 static void
179 fail_interval(void **state)
180 {
181 assert_op_expression(EXPR_FAIL_INTERVAL, pcmk_rc_op_unsatisfied);
182 }
183
184
185 static void
186 match_both(void **state)
187 {
188 assert_op_expression(EXPR_MATCH_BOTH, pcmk_rc_ok);
189 }
190
191 static void
192 fail_both(void **state)
193 {
194 assert_op_expression(EXPR_FAIL_BOTH, pcmk_rc_op_unsatisfied);
195 }
196
197 PCMK__UNIT_TEST(pcmk__xml_test_setup_group, NULL,
198 cmocka_unit_test(null_invalid),
199 cmocka_unit_test(id_missing),
200 cmocka_unit_test(name_missing),
201 cmocka_unit_test(input_name_missing),
202 cmocka_unit_test(fail_name),
203 cmocka_unit_test(invalid_interval),
204 cmocka_unit_test(default_interval),
205 cmocka_unit_test(fail_interval),
206 cmocka_unit_test(match_both),
207 cmocka_unit_test(fail_both))