This source file includes following definitions.
- basic
- colon_in_rsc
- dashes_in_rsc
- migrate_to_from
- pre_post
- skip_rsc
- skip_ty
- skip_ms
- empty_input
- malformed_input
- main
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <glib.h>
13 #include <stdarg.h>
14 #include <stddef.h>
15 #include <stdint.h>
16 #include <stdlib.h>
17 #include <setjmp.h>
18 #include <cmocka.h>
19
20 static void
21 basic(void **state)
22 {
23 char *rsc = NULL;
24 char *ty = NULL;
25 guint ms = 0;
26
27 assert_true(parse_op_key("Fencing_monitor_60000", &rsc, &ty, &ms));
28 assert_string_equal(rsc, "Fencing");
29 assert_string_equal(ty, "monitor");
30 assert_int_equal(ms, 60000);
31 free(rsc);
32 free(ty);
33 }
34
35 static void
36 colon_in_rsc(void **state)
37 {
38 char *rsc = NULL;
39 char *ty = NULL;
40 guint ms = 0;
41
42 assert_true(parse_op_key("ClusterIP:0_start_0", &rsc, &ty, &ms));
43 assert_string_equal(rsc, "ClusterIP:0");
44 assert_string_equal(ty, "start");
45 assert_int_equal(ms, 0);
46 free(rsc);
47 free(ty);
48
49 assert_true(parse_op_key("imagestoreclone:1_post_notify_stop_0", &rsc, &ty, &ms));
50 assert_string_equal(rsc, "imagestoreclone:1");
51 assert_string_equal(ty, "post_notify_stop");
52 assert_int_equal(ms, 0);
53 free(rsc);
54 free(ty);
55 }
56
57 static void
58 dashes_in_rsc(void **state)
59 {
60 char *rsc = NULL;
61 char *ty = NULL;
62 guint ms = 0;
63
64 assert_true(parse_op_key("httpd-bundle-0_monitor_30000", &rsc, &ty, &ms));
65 assert_string_equal(rsc, "httpd-bundle-0");
66 assert_string_equal(ty, "monitor");
67 assert_int_equal(ms, 30000);
68 free(rsc);
69 free(ty);
70
71 assert_true(parse_op_key("httpd-bundle-ip-192.168.122.132_start_0", &rsc, &ty, &ms));
72 assert_string_equal(rsc, "httpd-bundle-ip-192.168.122.132");
73 assert_string_equal(ty, "start");
74 assert_int_equal(ms, 0);
75 free(rsc);
76 free(ty);
77 }
78
79 static void
80 migrate_to_from(void **state)
81 {
82 char *rsc = NULL;
83 char *ty = NULL;
84 guint ms = 0;
85
86 assert_true(parse_op_key("vm_migrate_from_0", &rsc, &ty, &ms));
87 assert_string_equal(rsc, "vm");
88 assert_string_equal(ty, "migrate_from");
89 assert_int_equal(ms, 0);
90 free(rsc);
91 free(ty);
92
93 assert_true(parse_op_key("vm_migrate_to_0", &rsc, &ty, &ms));
94 assert_string_equal(rsc, "vm");
95 assert_string_equal(ty, "migrate_to");
96 assert_int_equal(ms, 0);
97 free(rsc);
98 free(ty);
99
100 assert_true(parse_op_key("vm_idcc_devel_migrate_to_0", &rsc, &ty, &ms));
101 assert_string_equal(rsc, "vm_idcc_devel");
102 assert_string_equal(ty, "migrate_to");
103 assert_int_equal(ms, 0);
104 free(rsc);
105 free(ty);
106 }
107
108 static void
109 pre_post(void **state)
110 {
111 char *rsc = NULL;
112 char *ty = NULL;
113 guint ms = 0;
114
115 assert_true(parse_op_key("rsc_drbd_7788:1_post_notify_start_0", &rsc, &ty, &ms));
116 assert_string_equal(rsc, "rsc_drbd_7788:1");
117 assert_string_equal(ty, "post_notify_start");
118 assert_int_equal(ms, 0);
119 free(rsc);
120 free(ty);
121
122 assert_true(parse_op_key("rabbitmq-bundle-clone_pre_notify_stop_0", &rsc, &ty, &ms));
123 assert_string_equal(rsc, "rabbitmq-bundle-clone");
124 assert_string_equal(ty, "pre_notify_stop");
125 assert_int_equal(ms, 0);
126 free(rsc);
127 free(ty);
128
129 assert_true(parse_op_key("post_notify_start_0", &rsc, &ty, &ms));
130 assert_string_equal(rsc, "post_notify");
131 assert_string_equal(ty, "start");
132 assert_int_equal(ms, 0);
133 free(rsc);
134 free(ty);
135 }
136
137 static void
138 skip_rsc(void **state)
139 {
140 char *ty = NULL;
141 guint ms = 0;
142
143 assert_true(parse_op_key("Fencing_monitor_60000", NULL, &ty, &ms));
144 assert_string_equal(ty, "monitor");
145 assert_int_equal(ms, 60000);
146 free(ty);
147 }
148
149 static void
150 skip_ty(void **state)
151 {
152 char *rsc = NULL;
153 guint ms = 0;
154
155 assert_true(parse_op_key("Fencing_monitor_60000", &rsc, NULL, &ms));
156 assert_string_equal(rsc, "Fencing");
157 assert_int_equal(ms, 60000);
158 free(rsc);
159 }
160
161 static void
162 skip_ms(void **state)
163 {
164 char *rsc = NULL;
165 char *ty = NULL;
166
167 assert_true(parse_op_key("Fencing_monitor_60000", &rsc, &ty, NULL));
168 assert_string_equal(rsc, "Fencing");
169 assert_string_equal(ty, "monitor");
170 free(rsc);
171 free(ty);
172 }
173
174 static void
175 empty_input(void **state)
176 {
177 char *rsc = NULL;
178 char *ty = NULL;
179 guint ms = 0;
180
181 assert_false(parse_op_key("", &rsc, &ty, &ms));
182 assert_null(rsc);
183 assert_null(ty);
184 assert_int_equal(ms, 0);
185
186 assert_false(parse_op_key(NULL, &rsc, &ty, &ms));
187 assert_null(rsc);
188 assert_null(ty);
189 assert_int_equal(ms, 0);
190 }
191
192 static void
193 malformed_input(void **state)
194 {
195 char *rsc = NULL;
196 char *ty = NULL;
197 guint ms = 0;
198
199 assert_false(parse_op_key("httpd-bundle-0", &rsc, &ty, &ms));
200 assert_null(rsc);
201 assert_null(ty);
202 assert_int_equal(ms, 0);
203
204 assert_false(parse_op_key("httpd-bundle-0_monitor", &rsc, &ty, &ms));
205 assert_null(rsc);
206 assert_null(ty);
207 assert_int_equal(ms, 0);
208
209 assert_false(parse_op_key("httpd-bundle-0_30000", &rsc, &ty, &ms));
210 assert_null(rsc);
211 assert_null(ty);
212 assert_int_equal(ms, 0);
213 }
214
215 int main(int argc, char **argv)
216 {
217 const struct CMUnitTest tests[] = {
218 cmocka_unit_test(basic),
219 cmocka_unit_test(colon_in_rsc),
220 cmocka_unit_test(dashes_in_rsc),
221 cmocka_unit_test(migrate_to_from),
222 cmocka_unit_test(pre_post),
223
224 cmocka_unit_test(skip_rsc),
225 cmocka_unit_test(skip_ty),
226 cmocka_unit_test(skip_ms),
227
228 cmocka_unit_test(empty_input),
229 cmocka_unit_test(malformed_input),
230 };
231
232 cmocka_set_message_output(CM_OUTPUT_TAP);
233 return cmocka_run_group_tests(tests, NULL, NULL);
234 }