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