comparison tests/test-action-script.c @ 466:39dd7c66ebfd

core: script -> mlk_action_script While here, don't create a static array and let the user specify the storage area where actions will be put (similar to mlk_action_stack). Remove example-action for now which requires a major rewrite.
author David Demelier <markand@malikania.fr>
date Mon, 27 Feb 2023 11:03:13 +0100
parents 02c1481b7dbb
children c1f64d451230
comparison
equal deleted inserted replaced
465:01f5580e43d1 466:39dd7c66ebfd
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */ 17 */
18 18
19 #include <mlk/core/action.h> 19 #include <mlk/core/action.h>
20 #include <mlk/core/err.h>
20 #include <mlk/core/event.h> 21 #include <mlk/core/event.h>
21 #include <mlk/core/script.h> 22 #include <mlk/core/action-script.h>
22 23
23 #include <dt.h> 24 #include <dt.h>
24 25
25 struct invokes { 26 struct invokes {
26 int handle; 27 int handle;
86 } 87 }
87 88
88 static void 89 static void
89 test_basics_init(void) 90 test_basics_init(void)
90 { 91 {
91 struct script sc; 92 struct mlk_action_script sc;
92 93 struct mlk_action *actions[10];
93 script_init(&sc); 94
94 95 mlk_action_script_init(&sc, actions, 10);
95 DT_EQ_UINT(sc.actionsz, 0U); 96
96 DT_EQ_UINT(sc.cur, 0U); 97 DT_EQ_SIZE(sc.size, 0U);
98 DT_EQ_SIZE(sc.max, 10U);
99 DT_EQ_SIZE(sc.cur, 0U);
97 } 100 }
98 101
99 static void 102 static void
100 test_basics_append(void) 103 test_basics_append(void)
101 { 104 {
102 struct mlk_action act[3] = {0}; 105 struct mlk_action actions[4] = {0};
103 struct script sc = {0}; 106 struct mlk_action *array[3] = {0};
104 107 struct mlk_action_script sc = {0};
105 DT_ASSERT(script_append(&sc, &act[0]) == 0); 108
106 DT_EQ_UINT(sc.cur, 0U); 109 mlk_action_script_init(&sc, array, 3);
107 DT_EQ_UINT(sc.actionsz, 1U); 110
108 DT_EQ_PTR(sc.actions[0], &act[0]); 111 DT_ASSERT(mlk_action_script_append(&sc, &actions[0]) == 0);
109 112 DT_EQ_SIZE(sc.size, 1U);
110 DT_ASSERT(script_append(&sc, &act[1]) == 0); 113 DT_EQ_SIZE(sc.max, 3U);
111 DT_EQ_UINT(sc.cur, 0U); 114 DT_EQ_SIZE(sc.cur, 0U);
112 DT_EQ_UINT(sc.actionsz, 2U); 115 DT_EQ_PTR(sc.actions[0], &actions[0]);
113 DT_EQ_PTR(sc.actions[0], &act[0]); 116
114 DT_EQ_PTR(sc.actions[1], &act[1]); 117 DT_ASSERT(mlk_action_script_append(&sc, &actions[1]) == 0);
115 118 DT_EQ_SIZE(sc.size, 2U);
116 DT_ASSERT(script_append(&sc, &act[2]) == 0); 119 DT_EQ_SIZE(sc.max, 3U);
117 DT_EQ_UINT(sc.cur, 0U); 120 DT_EQ_SIZE(sc.cur, 0U);
118 DT_EQ_UINT(sc.actionsz, 3U); 121 DT_EQ_PTR(sc.actions[0], &actions[0]);
119 DT_EQ_PTR(sc.actions[0], &act[0]); 122 DT_EQ_PTR(sc.actions[1], &actions[1]);
120 DT_EQ_PTR(sc.actions[1], &act[1]); 123
121 DT_EQ_PTR(sc.actions[2], &act[2]); 124 DT_ASSERT(mlk_action_script_append(&sc, &actions[2]) == 0);
122 125 DT_EQ_SIZE(sc.size, 3U);
123 script_finish(&sc); 126 DT_EQ_SIZE(sc.max, 3U);
127 DT_EQ_SIZE(sc.cur, 0U);
128 DT_EQ_PTR(sc.actions[0], &actions[0]);
129 DT_EQ_PTR(sc.actions[1], &actions[1]);
130 DT_EQ_PTR(sc.actions[2], &actions[2]);
131
132 /* This can not fit. */
133 DT_ASSERT(mlk_action_script_append(&sc, &actions[3]) == MLK_ERR_NO_MEM);
134
135 mlk_action_script_finish(&sc);
124 } 136 }
125 137
126 static void 138 static void
127 test_basics_handle(void) 139 test_basics_handle(void)
128 { 140 {
133 { .act = INIT(&table[0].inv, my_update_true) }, 145 { .act = INIT(&table[0].inv, my_update_true) },
134 { .act = INIT(&table[1].inv, my_update_true) }, 146 { .act = INIT(&table[1].inv, my_update_true) },
135 { .act = INIT(&table[2].inv, my_update_false) } 147 { .act = INIT(&table[2].inv, my_update_false) }
136 }; 148 };
137 149
138 struct script sc = {0}; 150 struct mlk_action array[3] = {0};
139 151 struct mlk_action_script sc = {0};
140 DT_ASSERT(script_append(&sc, &table[0].act) == 0); 152
141 DT_ASSERT(script_append(&sc, &table[1].act) == 0); 153 mlk_action_script_init(&sc, array, 3);
142 DT_ASSERT(script_append(&sc, &table[2].act) == 0); 154
155 DT_ASSERT(mlk_action_script_append(&sc, &table[0].act) == 0);
156 DT_ASSERT(mlk_action_script_append(&sc, &table[1].act) == 0);
157 DT_ASSERT(mlk_action_script_append(&sc, &table[2].act) == 0);
143 158
144 /* [0] */ 159 /* [0] */
145 script_handle(&sc, &(union mlk_event){0}); 160 mlk_action_script_handle(&sc, &(union mlk_event){0});
146 DT_EQ_INT(table[0].inv.handle, 1); 161 DT_EQ_INT(table[0].inv.handle, 1);
147 DT_EQ_INT(table[0].inv.update, 0); 162 DT_EQ_INT(table[0].inv.update, 0);
148 DT_EQ_INT(table[0].inv.draw, 0); 163 DT_EQ_INT(table[0].inv.draw, 0);
149 DT_EQ_INT(table[0].inv.end, 0); 164 DT_EQ_INT(table[0].inv.end, 0);
150 DT_EQ_INT(table[0].inv.finish, 0); 165 DT_EQ_INT(table[0].inv.finish, 0);
158 DT_EQ_INT(table[2].inv.draw, 0); 173 DT_EQ_INT(table[2].inv.draw, 0);
159 DT_EQ_INT(table[2].inv.end, 0); 174 DT_EQ_INT(table[2].inv.end, 0);
160 DT_EQ_INT(table[2].inv.finish, 0); 175 DT_EQ_INT(table[2].inv.finish, 0);
161 176
162 /* [0] -> [1] */ 177 /* [0] -> [1] */
163 DT_ASSERT(!script_update(&sc, 0)); 178 DT_ASSERT(!mlk_action_script_update(&sc, 0));
164 script_handle(&sc, &(union mlk_event){0}); 179 mlk_action_script_handle(&sc, &(union mlk_event){0});
165 180
166 DT_EQ_INT(table[0].inv.handle, 1); 181 DT_EQ_INT(table[0].inv.handle, 1);
167 DT_EQ_INT(table[0].inv.update, 1); 182 DT_EQ_INT(table[0].inv.update, 1);
168 DT_EQ_INT(table[0].inv.draw, 0); 183 DT_EQ_INT(table[0].inv.draw, 0);
169 DT_EQ_INT(table[0].inv.end, 1); 184 DT_EQ_INT(table[0].inv.end, 1);
178 DT_EQ_INT(table[2].inv.draw, 0); 193 DT_EQ_INT(table[2].inv.draw, 0);
179 DT_EQ_INT(table[2].inv.end, 0); 194 DT_EQ_INT(table[2].inv.end, 0);
180 DT_EQ_INT(table[2].inv.finish, 0); 195 DT_EQ_INT(table[2].inv.finish, 0);
181 196
182 /* [2] */ 197 /* [2] */
183 DT_ASSERT(!script_update(&sc, 0)); 198 DT_ASSERT(!mlk_action_script_update(&sc, 0));
184 script_handle(&sc, &(union mlk_event){0}); 199 mlk_action_script_handle(&sc, &(union mlk_event){0});
185 200
186 DT_EQ_INT(table[0].inv.handle, 1); 201 DT_EQ_INT(table[0].inv.handle, 1);
187 DT_EQ_INT(table[0].inv.update, 1); 202 DT_EQ_INT(table[0].inv.update, 1);
188 DT_EQ_INT(table[0].inv.draw, 0); 203 DT_EQ_INT(table[0].inv.draw, 0);
189 DT_EQ_INT(table[0].inv.end, 1); 204 DT_EQ_INT(table[0].inv.end, 1);
196 DT_EQ_INT(table[2].inv.handle, 1); 211 DT_EQ_INT(table[2].inv.handle, 1);
197 DT_EQ_INT(table[2].inv.update, 0); 212 DT_EQ_INT(table[2].inv.update, 0);
198 DT_EQ_INT(table[2].inv.draw, 0); 213 DT_EQ_INT(table[2].inv.draw, 0);
199 DT_EQ_INT(table[2].inv.end, 0); 214 DT_EQ_INT(table[2].inv.end, 0);
200 DT_EQ_INT(table[2].inv.finish, 0); 215 DT_EQ_INT(table[2].inv.finish, 0);
216
217 mlk_action_script_finish(&sc);
201 } 218 }
202 219
203 static void 220 static void
204 test_basics_update(void) 221 test_basics_update(void)
205 { 222 {
210 { .act = INIT(&table[0].inv, my_update_true) }, 227 { .act = INIT(&table[0].inv, my_update_true) },
211 { .act = INIT(&table[1].inv, my_update_true) }, 228 { .act = INIT(&table[1].inv, my_update_true) },
212 { .act = INIT(&table[2].inv, my_update_false) } 229 { .act = INIT(&table[2].inv, my_update_false) }
213 }; 230 };
214 231
215 struct script sc = {0}; 232 struct mlk_action array[3];
216 233 struct mlk_action_script sc = {0};
217 DT_ASSERT(script_append(&sc, &table[0].act) == 0); 234
218 DT_ASSERT(script_append(&sc, &table[1].act) == 0); 235 mlk_action_script_init(&sc, array, 3);
219 DT_ASSERT(script_append(&sc, &table[2].act) == 0); 236
237 DT_ASSERT(mlk_action_script_append(&sc, &table[0].act) == 0);
238 DT_ASSERT(mlk_action_script_append(&sc, &table[1].act) == 0);
239 DT_ASSERT(mlk_action_script_append(&sc, &table[2].act) == 0);
220 240
221 /* 0 -> 1 */ 241 /* 0 -> 1 */
222 DT_ASSERT(!script_update(&sc, 0)); 242 DT_ASSERT(!mlk_action_script_update(&sc, 0));
223 DT_EQ_INT(table[0].inv.handle, 0); 243 DT_EQ_INT(table[0].inv.handle, 0);
224 DT_EQ_INT(table[0].inv.update, 1); 244 DT_EQ_INT(table[0].inv.update, 1);
225 DT_EQ_INT(table[0].inv.draw, 0); 245 DT_EQ_INT(table[0].inv.draw, 0);
226 DT_EQ_INT(table[0].inv.end, 1); 246 DT_EQ_INT(table[0].inv.end, 1);
227 DT_EQ_INT(table[0].inv.finish, 0); 247 DT_EQ_INT(table[0].inv.finish, 0);
235 DT_EQ_INT(table[2].inv.draw, 0); 255 DT_EQ_INT(table[2].inv.draw, 0);
236 DT_EQ_INT(table[2].inv.end, 0); 256 DT_EQ_INT(table[2].inv.end, 0);
237 DT_EQ_INT(table[2].inv.finish, 0); 257 DT_EQ_INT(table[2].inv.finish, 0);
238 258
239 /* 1 -> 2 */ 259 /* 1 -> 2 */
240 DT_ASSERT(!script_update(&sc, 0)); 260 DT_ASSERT(!mlk_action_script_update(&sc, 0));
241 DT_EQ_INT(table[0].inv.handle, 0); 261 DT_EQ_INT(table[0].inv.handle, 0);
242 DT_EQ_INT(table[0].inv.update, 1); 262 DT_EQ_INT(table[0].inv.update, 1);
243 DT_EQ_INT(table[0].inv.draw, 0); 263 DT_EQ_INT(table[0].inv.draw, 0);
244 DT_EQ_INT(table[0].inv.end, 1); 264 DT_EQ_INT(table[0].inv.end, 1);
245 DT_EQ_INT(table[0].inv.finish, 0); 265 DT_EQ_INT(table[0].inv.finish, 0);
253 DT_EQ_INT(table[2].inv.draw, 0); 273 DT_EQ_INT(table[2].inv.draw, 0);
254 DT_EQ_INT(table[2].inv.end, 0); 274 DT_EQ_INT(table[2].inv.end, 0);
255 DT_EQ_INT(table[2].inv.finish, 0); 275 DT_EQ_INT(table[2].inv.finish, 0);
256 276
257 /* 2 stays, it never ends. */ 277 /* 2 stays, it never ends. */
258 DT_ASSERT(!script_update(&sc, 0)); 278 DT_ASSERT(!mlk_action_script_update(&sc, 0));
259 DT_ASSERT(!script_update(&sc, 0)); 279 DT_ASSERT(!mlk_action_script_update(&sc, 0));
260 DT_ASSERT(!script_update(&sc, 0)); 280 DT_ASSERT(!mlk_action_script_update(&sc, 0));
261 DT_EQ_INT(table[0].inv.handle, 0); 281 DT_EQ_INT(table[0].inv.handle, 0);
262 DT_EQ_INT(table[0].inv.update, 1); 282 DT_EQ_INT(table[0].inv.update, 1);
263 DT_EQ_INT(table[0].inv.draw, 0); 283 DT_EQ_INT(table[0].inv.draw, 0);
264 DT_EQ_INT(table[0].inv.end, 1); 284 DT_EQ_INT(table[0].inv.end, 1);
265 DT_EQ_INT(table[0].inv.finish, 0); 285 DT_EQ_INT(table[0].inv.finish, 0);
274 DT_EQ_INT(table[2].inv.end, 0); 294 DT_EQ_INT(table[2].inv.end, 0);
275 DT_EQ_INT(table[2].inv.finish, 0); 295 DT_EQ_INT(table[2].inv.finish, 0);
276 296
277 /* Now, change its update function to complete the script. */ 297 /* Now, change its update function to complete the script. */
278 table[2].act.update = my_update_true; 298 table[2].act.update = my_update_true;
279 DT_ASSERT(script_update(&sc, 0)); 299 DT_ASSERT(mlk_action_script_update(&sc, 0));
280 DT_EQ_INT(table[0].inv.handle, 0); 300 DT_EQ_INT(table[0].inv.handle, 0);
281 DT_EQ_INT(table[0].inv.update, 1); 301 DT_EQ_INT(table[0].inv.update, 1);
282 DT_EQ_INT(table[0].inv.draw, 0); 302 DT_EQ_INT(table[0].inv.draw, 0);
283 DT_EQ_INT(table[0].inv.end, 1); 303 DT_EQ_INT(table[0].inv.end, 1);
284 DT_EQ_INT(table[0].inv.finish, 0); 304 DT_EQ_INT(table[0].inv.finish, 0);
290 DT_EQ_INT(table[2].inv.handle, 0); 310 DT_EQ_INT(table[2].inv.handle, 0);
291 DT_EQ_INT(table[2].inv.update, 4); 311 DT_EQ_INT(table[2].inv.update, 4);
292 DT_EQ_INT(table[2].inv.draw, 0); 312 DT_EQ_INT(table[2].inv.draw, 0);
293 DT_EQ_INT(table[2].inv.end, 1); 313 DT_EQ_INT(table[2].inv.end, 1);
294 DT_EQ_INT(table[2].inv.finish, 0); 314 DT_EQ_INT(table[2].inv.finish, 0);
315
316 mlk_action_script_finish(&sc);
295 } 317 }
296 318
297 static void 319 static void
298 test_basics_draw(void) 320 test_basics_draw(void)
299 { 321 {
304 { .act = INIT(&table[0].inv, my_update_true) }, 326 { .act = INIT(&table[0].inv, my_update_true) },
305 { .act = INIT(&table[1].inv, my_update_true) }, 327 { .act = INIT(&table[1].inv, my_update_true) },
306 { .act = INIT(&table[2].inv, my_update_false) } 328 { .act = INIT(&table[2].inv, my_update_false) }
307 }; 329 };
308 330
309 struct script sc = {0}; 331 struct mlk_action array[3];
310 332 struct mlk_action_script sc = {0};
311 DT_ASSERT(script_append(&sc, &table[0].act) == 0); 333
312 DT_ASSERT(script_append(&sc, &table[1].act) == 0); 334 mlk_action_script_init(&sc, array, 3);
313 DT_ASSERT(script_append(&sc, &table[2].act) == 0); 335
336 DT_ASSERT(mlk_action_script_append(&sc, &table[0].act) == 0);
337 DT_ASSERT(mlk_action_script_append(&sc, &table[1].act) == 0);
338 DT_ASSERT(mlk_action_script_append(&sc, &table[2].act) == 0);
314 339
315 /* [0] */ 340 /* [0] */
316 script_draw(&sc); 341 mlk_action_script_draw(&sc);
317 DT_EQ_INT(table[0].inv.handle, 0); 342 DT_EQ_INT(table[0].inv.handle, 0);
318 DT_EQ_INT(table[0].inv.update, 0); 343 DT_EQ_INT(table[0].inv.update, 0);
319 DT_EQ_INT(table[0].inv.draw, 1); 344 DT_EQ_INT(table[0].inv.draw, 1);
320 DT_EQ_INT(table[0].inv.end, 0); 345 DT_EQ_INT(table[0].inv.end, 0);
321 DT_EQ_INT(table[0].inv.finish, 0); 346 DT_EQ_INT(table[0].inv.finish, 0);
329 DT_EQ_INT(table[2].inv.draw, 0); 354 DT_EQ_INT(table[2].inv.draw, 0);
330 DT_EQ_INT(table[2].inv.end, 0); 355 DT_EQ_INT(table[2].inv.end, 0);
331 DT_EQ_INT(table[2].inv.finish, 0); 356 DT_EQ_INT(table[2].inv.finish, 0);
332 357
333 /* [0] -> [1] */ 358 /* [0] -> [1] */
334 DT_ASSERT(!script_update(&sc, 0)); 359 DT_ASSERT(!mlk_action_script_update(&sc, 0));
335 script_draw(&sc); 360 mlk_action_script_draw(&sc);
336 361
337 DT_EQ_INT(table[0].inv.handle, 0); 362 DT_EQ_INT(table[0].inv.handle, 0);
338 DT_EQ_INT(table[0].inv.update, 1); 363 DT_EQ_INT(table[0].inv.update, 1);
339 DT_EQ_INT(table[0].inv.draw, 1); 364 DT_EQ_INT(table[0].inv.draw, 1);
340 DT_EQ_INT(table[0].inv.end, 1); 365 DT_EQ_INT(table[0].inv.end, 1);
349 DT_EQ_INT(table[2].inv.draw, 0); 374 DT_EQ_INT(table[2].inv.draw, 0);
350 DT_EQ_INT(table[2].inv.end, 0); 375 DT_EQ_INT(table[2].inv.end, 0);
351 DT_EQ_INT(table[2].inv.finish, 0); 376 DT_EQ_INT(table[2].inv.finish, 0);
352 377
353 /* [2] */ 378 /* [2] */
354 DT_ASSERT(!script_update(&sc, 0)); 379 DT_ASSERT(!mlk_action_script_update(&sc, 0));
355 script_draw(&sc); 380 mlk_action_script_draw(&sc);
356 381
357 DT_EQ_INT(table[0].inv.handle, 0); 382 DT_EQ_INT(table[0].inv.handle, 0);
358 DT_EQ_INT(table[0].inv.update, 1); 383 DT_EQ_INT(table[0].inv.update, 1);
359 DT_EQ_INT(table[0].inv.draw, 1); 384 DT_EQ_INT(table[0].inv.draw, 1);
360 DT_EQ_INT(table[0].inv.end, 1); 385 DT_EQ_INT(table[0].inv.end, 1);
381 { .act = INIT(&table[0].inv, my_update_true) }, 406 { .act = INIT(&table[0].inv, my_update_true) },
382 { .act = INIT(&table[1].inv, my_update_true) }, 407 { .act = INIT(&table[1].inv, my_update_true) },
383 { .act = INIT(&table[2].inv, my_update_false) } 408 { .act = INIT(&table[2].inv, my_update_false) }
384 }; 409 };
385 410
386 struct script sc = {0}; 411 struct mlk_action array[3];
387 412 struct mlk_action_script sc = {0};
388 DT_ASSERT(script_append(&sc, &table[0].act) == 0); 413
389 DT_ASSERT(script_append(&sc, &table[1].act) == 0); 414 mlk_action_script_init(&sc, array, 3);
390 DT_ASSERT(script_append(&sc, &table[2].act) == 0); 415
416 DT_ASSERT(mlk_action_script_append(&sc, &table[0].act) == 0);
417 DT_ASSERT(mlk_action_script_append(&sc, &table[1].act) == 0);
418 DT_ASSERT(mlk_action_script_append(&sc, &table[2].act) == 0);
391 419
392 /* Update once so that the current action goes to 1. */ 420 /* Update once so that the current action goes to 1. */
393 DT_ASSERT(!script_update(&sc, 0)); 421 DT_ASSERT(!mlk_action_script_update(&sc, 0));
394 422
395 script_finish(&sc); 423 mlk_action_script_finish(&sc);
396 424
397 DT_EQ_INT(table[0].inv.handle, 0); 425 DT_EQ_INT(table[0].inv.handle, 0);
398 DT_EQ_INT(table[0].inv.update, 1); 426 DT_EQ_INT(table[0].inv.update, 1);
399 DT_EQ_INT(table[0].inv.draw, 0); 427 DT_EQ_INT(table[0].inv.draw, 0);
400 DT_EQ_INT(table[0].inv.end, 1); 428 DT_EQ_INT(table[0].inv.end, 1);
406 DT_EQ_INT(table[1].inv.finish, 1); 434 DT_EQ_INT(table[1].inv.finish, 1);
407 DT_EQ_INT(table[2].inv.handle, 0); 435 DT_EQ_INT(table[2].inv.handle, 0);
408 DT_EQ_INT(table[2].inv.update, 0); 436 DT_EQ_INT(table[2].inv.update, 0);
409 DT_EQ_INT(table[2].inv.draw, 0); 437 DT_EQ_INT(table[2].inv.draw, 0);
410 DT_EQ_INT(table[2].inv.end, 0); 438 DT_EQ_INT(table[2].inv.end, 0);
411 DT_EQ_INT(table[2].inv.finish, 1);
412 }
413
414 static void
415 test_action_simple(void)
416 {
417 struct {
418 struct invokes inv;
419 struct mlk_action act;
420 } table[] = {
421 { .act = INIT(&table[0].inv, my_update_true) },
422 { .act = INIT(&table[1].inv, my_update_true) },
423 { .act = INIT(&table[2].inv, my_update_false) }
424 };
425
426 struct script sc = {0};
427 struct mlk_action act;
428
429 DT_ASSERT(script_append(&sc, &table[0].act) == 0);
430 DT_ASSERT(script_append(&sc, &table[1].act) == 0);
431 DT_ASSERT(script_append(&sc, &table[2].act) == 0);
432
433 /* Now convert this script into an action itself. */
434 script_action(&sc, &act);
435
436 /* Draw and input before updating. */
437 mlk_action_handle(&act, &(union mlk_event){0});
438 mlk_action_draw(&act);
439
440 /* [0] -> [1] */
441 DT_ASSERT(!mlk_action_update(&act, 0));
442 DT_EQ_INT(table[0].inv.handle, 1);
443 DT_EQ_INT(table[0].inv.update, 1);
444 DT_EQ_INT(table[0].inv.draw, 1);
445 DT_EQ_INT(table[0].inv.end, 1);
446 DT_EQ_INT(table[0].inv.finish, 0);
447 DT_EQ_INT(table[1].inv.handle, 0);
448 DT_EQ_INT(table[1].inv.update, 0);
449 DT_EQ_INT(table[1].inv.draw, 0);
450 DT_EQ_INT(table[1].inv.end, 0);
451 DT_EQ_INT(table[1].inv.finish, 0);
452 DT_EQ_INT(table[2].inv.handle, 0);
453 DT_EQ_INT(table[2].inv.update, 0);
454 DT_EQ_INT(table[2].inv.draw, 0);
455 DT_EQ_INT(table[2].inv.end, 0);
456 DT_EQ_INT(table[2].inv.finish, 0);
457
458 mlk_action_handle(&act, &(union mlk_event){0});
459 mlk_action_draw(&act);
460
461 /* [1] -> [2] */
462 DT_ASSERT(!mlk_action_update(&act, 0));
463 DT_EQ_INT(table[0].inv.handle, 1);
464 DT_EQ_INT(table[0].inv.update, 1);
465 DT_EQ_INT(table[0].inv.draw, 1);
466 DT_EQ_INT(table[0].inv.end, 1);
467 DT_EQ_INT(table[0].inv.finish, 0);
468 DT_EQ_INT(table[1].inv.handle, 1);
469 DT_EQ_INT(table[1].inv.update, 1);
470 DT_EQ_INT(table[1].inv.draw, 1);
471 DT_EQ_INT(table[1].inv.end, 1);
472 DT_EQ_INT(table[1].inv.finish, 0);
473 DT_EQ_INT(table[2].inv.handle, 0);
474 DT_EQ_INT(table[2].inv.update, 0);
475 DT_EQ_INT(table[2].inv.draw, 0);
476 DT_EQ_INT(table[2].inv.end, 0);
477 DT_EQ_INT(table[2].inv.finish, 0);
478
479 mlk_action_handle(&act, &(union mlk_event){0});
480 mlk_action_draw(&act);
481
482 /* 2 stays, it never ends. */
483 DT_ASSERT(!mlk_action_update(&act, 0));
484 DT_ASSERT(!mlk_action_update(&act, 0));
485 DT_ASSERT(!mlk_action_update(&act, 0));
486 DT_EQ_INT(table[0].inv.handle, 1);
487 DT_EQ_INT(table[0].inv.update, 1);
488 DT_EQ_INT(table[0].inv.draw, 1);
489 DT_EQ_INT(table[0].inv.end, 1);
490 DT_EQ_INT(table[0].inv.finish, 0);
491 DT_EQ_INT(table[1].inv.handle, 1);
492 DT_EQ_INT(table[1].inv.update, 1);
493 DT_EQ_INT(table[1].inv.draw, 1);
494 DT_EQ_INT(table[1].inv.end, 1);
495 DT_EQ_INT(table[1].inv.finish, 0);
496 DT_EQ_INT(table[2].inv.handle, 1);
497 DT_EQ_INT(table[2].inv.update, 3);
498 DT_EQ_INT(table[2].inv.draw, 1);
499 DT_EQ_INT(table[2].inv.end, 0);
500 DT_EQ_INT(table[2].inv.finish, 0);
501
502 table[2].act.update = my_update_true;
503 DT_ASSERT(mlk_action_update(&act, 0));
504 DT_EQ_INT(table[0].inv.handle, 1);
505 DT_EQ_INT(table[0].inv.update, 1);
506 DT_EQ_INT(table[0].inv.draw, 1);
507 DT_EQ_INT(table[0].inv.end, 1);
508 DT_EQ_INT(table[0].inv.finish, 0);
509 DT_EQ_INT(table[1].inv.handle, 1);
510 DT_EQ_INT(table[1].inv.update, 1);
511 DT_EQ_INT(table[1].inv.draw, 1);
512 DT_EQ_INT(table[1].inv.end, 1);
513 DT_EQ_INT(table[1].inv.finish, 0);
514 DT_EQ_INT(table[2].inv.handle, 1);
515 DT_EQ_INT(table[2].inv.update, 4);
516 DT_EQ_INT(table[2].inv.draw, 1);
517 DT_EQ_INT(table[2].inv.end, 1);
518 DT_EQ_INT(table[2].inv.finish, 0);
519
520 /* Also dispose resources. */
521 mlk_action_finish(&act);
522 DT_EQ_INT(table[0].inv.handle, 1);
523 DT_EQ_INT(table[0].inv.update, 1);
524 DT_EQ_INT(table[0].inv.draw, 1);
525 DT_EQ_INT(table[0].inv.end, 1);
526 DT_EQ_INT(table[0].inv.finish, 1);
527 DT_EQ_INT(table[1].inv.handle, 1);
528 DT_EQ_INT(table[1].inv.update, 1);
529 DT_EQ_INT(table[1].inv.draw, 1);
530 DT_EQ_INT(table[1].inv.end, 1);
531 DT_EQ_INT(table[1].inv.finish, 1);
532 DT_EQ_INT(table[2].inv.handle, 1);
533 DT_EQ_INT(table[2].inv.update, 4);
534 DT_EQ_INT(table[2].inv.draw, 1);
535 DT_EQ_INT(table[2].inv.end, 1);
536 DT_EQ_INT(table[2].inv.finish, 1); 439 DT_EQ_INT(table[2].inv.finish, 1);
537 } 440 }
538 441
539 int 442 int
540 main(void) 443 main(void)
543 DT_RUN(test_basics_append); 446 DT_RUN(test_basics_append);
544 DT_RUN(test_basics_handle); 447 DT_RUN(test_basics_handle);
545 DT_RUN(test_basics_update); 448 DT_RUN(test_basics_update);
546 DT_RUN(test_basics_draw); 449 DT_RUN(test_basics_draw);
547 DT_RUN(test_basics_finish); 450 DT_RUN(test_basics_finish);
548 DT_RUN(test_action_simple);
549 DT_SUMMARY(); 451 DT_SUMMARY();
550 } 452 }