Mercurial > molko
comparison tests/test-action-script.c @ 480:c1f64d451230
core: mlk_action has a start callback
author | David Demelier <markand@malikania.fr> |
---|---|
date | Mon, 27 Feb 2023 17:26:00 +0100 |
parents | 39dd7c66ebfd |
children | d3ea59fce7dc |
comparison
equal
deleted
inserted
replaced
479:8e41ed5474cf | 480:c1f64d451230 |
---|---|
22 #include <mlk/core/action-script.h> | 22 #include <mlk/core/action-script.h> |
23 | 23 |
24 #include <dt.h> | 24 #include <dt.h> |
25 | 25 |
26 struct invokes { | 26 struct invokes { |
27 int start; | |
27 int handle; | 28 int handle; |
28 int update; | 29 int update; |
29 int draw; | 30 int draw; |
30 int end; | 31 int end; |
31 int finish; | 32 int finish; |
32 }; | 33 }; |
33 | 34 |
34 #define INIT(dat, up) { \ | 35 #define INIT(dat, up) { \ |
35 .data = (dat), \ | 36 .data = (dat), \ |
37 .start = my_start, \ | |
36 .handle = my_handle, \ | 38 .handle = my_handle, \ |
37 .update = (up), \ | 39 .update = (up), \ |
38 .draw = my_draw, \ | 40 .draw = my_draw, \ |
39 .end = my_end, \ | 41 .end = my_end, \ |
40 .finish = my_finish \ | 42 .finish = my_finish \ |
43 } | |
44 | |
45 static void | |
46 my_start(struct mlk_action *act) | |
47 { | |
48 ((struct invokes *)act->data)->start++; | |
41 } | 49 } |
42 | 50 |
43 static void | 51 static void |
44 my_handle(struct mlk_action *act, const union mlk_event *ev) | 52 my_handle(struct mlk_action *act, const union mlk_event *ev) |
45 { | 53 { |
236 | 244 |
237 DT_ASSERT(mlk_action_script_append(&sc, &table[0].act) == 0); | 245 DT_ASSERT(mlk_action_script_append(&sc, &table[0].act) == 0); |
238 DT_ASSERT(mlk_action_script_append(&sc, &table[1].act) == 0); | 246 DT_ASSERT(mlk_action_script_append(&sc, &table[1].act) == 0); |
239 DT_ASSERT(mlk_action_script_append(&sc, &table[2].act) == 0); | 247 DT_ASSERT(mlk_action_script_append(&sc, &table[2].act) == 0); |
240 | 248 |
249 mlk_action_script_start(&sc); | |
250 | |
241 /* 0 -> 1 */ | 251 /* 0 -> 1 */ |
242 DT_ASSERT(!mlk_action_script_update(&sc, 0)); | 252 DT_ASSERT(!mlk_action_script_update(&sc, 0)); |
243 DT_EQ_INT(table[0].inv.handle, 0); | 253 DT_EQ_INT(table[0].inv.start, 1); |
244 DT_EQ_INT(table[0].inv.update, 1); | 254 DT_EQ_INT(table[0].inv.handle, 0); |
245 DT_EQ_INT(table[0].inv.draw, 0); | 255 DT_EQ_INT(table[0].inv.update, 1); |
246 DT_EQ_INT(table[0].inv.end, 1); | 256 DT_EQ_INT(table[0].inv.draw, 0); |
247 DT_EQ_INT(table[0].inv.finish, 0); | 257 DT_EQ_INT(table[0].inv.end, 1); |
248 DT_EQ_INT(table[1].inv.handle, 0); | 258 DT_EQ_INT(table[0].inv.finish, 0); |
249 DT_EQ_INT(table[1].inv.update, 0); | 259 DT_EQ_INT(table[1].inv.start, 1); |
250 DT_EQ_INT(table[1].inv.draw, 0); | 260 DT_EQ_INT(table[1].inv.handle, 0); |
251 DT_EQ_INT(table[1].inv.end, 0); | 261 DT_EQ_INT(table[1].inv.update, 0); |
252 DT_EQ_INT(table[1].inv.finish, 0); | 262 DT_EQ_INT(table[1].inv.draw, 0); |
263 DT_EQ_INT(table[1].inv.end, 0); | |
264 DT_EQ_INT(table[1].inv.finish, 0); | |
265 DT_EQ_INT(table[2].inv.start, 0); | |
253 DT_EQ_INT(table[2].inv.handle, 0); | 266 DT_EQ_INT(table[2].inv.handle, 0); |
254 DT_EQ_INT(table[2].inv.update, 0); | 267 DT_EQ_INT(table[2].inv.update, 0); |
255 DT_EQ_INT(table[2].inv.draw, 0); | 268 DT_EQ_INT(table[2].inv.draw, 0); |
256 DT_EQ_INT(table[2].inv.end, 0); | 269 DT_EQ_INT(table[2].inv.end, 0); |
257 DT_EQ_INT(table[2].inv.finish, 0); | 270 DT_EQ_INT(table[2].inv.finish, 0); |
258 | 271 |
259 /* 1 -> 2 */ | 272 /* 1 -> 2 */ |
260 DT_ASSERT(!mlk_action_script_update(&sc, 0)); | 273 DT_ASSERT(!mlk_action_script_update(&sc, 0)); |
261 DT_EQ_INT(table[0].inv.handle, 0); | 274 DT_EQ_INT(table[0].inv.start, 1); |
262 DT_EQ_INT(table[0].inv.update, 1); | 275 DT_EQ_INT(table[0].inv.handle, 0); |
263 DT_EQ_INT(table[0].inv.draw, 0); | 276 DT_EQ_INT(table[0].inv.update, 1); |
264 DT_EQ_INT(table[0].inv.end, 1); | 277 DT_EQ_INT(table[0].inv.draw, 0); |
265 DT_EQ_INT(table[0].inv.finish, 0); | 278 DT_EQ_INT(table[0].inv.end, 1); |
279 DT_EQ_INT(table[0].inv.finish, 0); | |
280 DT_EQ_INT(table[1].inv.start, 1); | |
266 DT_EQ_INT(table[1].inv.handle, 0); | 281 DT_EQ_INT(table[1].inv.handle, 0); |
267 DT_EQ_INT(table[1].inv.update, 1); | 282 DT_EQ_INT(table[1].inv.update, 1); |
268 DT_EQ_INT(table[1].inv.draw, 0); | 283 DT_EQ_INT(table[1].inv.draw, 0); |
269 DT_EQ_INT(table[1].inv.end, 1); | 284 DT_EQ_INT(table[1].inv.end, 1); |
270 DT_EQ_INT(table[1].inv.finish, 0); | 285 DT_EQ_INT(table[1].inv.finish, 0); |
286 DT_EQ_INT(table[2].inv.start, 1); | |
271 DT_EQ_INT(table[2].inv.handle, 0); | 287 DT_EQ_INT(table[2].inv.handle, 0); |
272 DT_EQ_INT(table[2].inv.update, 0); | 288 DT_EQ_INT(table[2].inv.update, 0); |
273 DT_EQ_INT(table[2].inv.draw, 0); | 289 DT_EQ_INT(table[2].inv.draw, 0); |
274 DT_EQ_INT(table[2].inv.end, 0); | 290 DT_EQ_INT(table[2].inv.end, 0); |
275 DT_EQ_INT(table[2].inv.finish, 0); | 291 DT_EQ_INT(table[2].inv.finish, 0); |
276 | 292 |
277 /* 2 stays, it never ends. */ | 293 /* 2 stays, it never ends. */ |
278 DT_ASSERT(!mlk_action_script_update(&sc, 0)); | 294 DT_ASSERT(!mlk_action_script_update(&sc, 0)); |
279 DT_ASSERT(!mlk_action_script_update(&sc, 0)); | 295 DT_ASSERT(!mlk_action_script_update(&sc, 0)); |
280 DT_ASSERT(!mlk_action_script_update(&sc, 0)); | 296 DT_ASSERT(!mlk_action_script_update(&sc, 0)); |
281 DT_EQ_INT(table[0].inv.handle, 0); | 297 DT_EQ_INT(table[0].inv.start, 1); |
282 DT_EQ_INT(table[0].inv.update, 1); | 298 DT_EQ_INT(table[0].inv.handle, 0); |
283 DT_EQ_INT(table[0].inv.draw, 0); | 299 DT_EQ_INT(table[0].inv.update, 1); |
284 DT_EQ_INT(table[0].inv.end, 1); | 300 DT_EQ_INT(table[0].inv.draw, 0); |
285 DT_EQ_INT(table[0].inv.finish, 0); | 301 DT_EQ_INT(table[0].inv.end, 1); |
302 DT_EQ_INT(table[0].inv.finish, 0); | |
303 DT_EQ_INT(table[1].inv.start, 1); | |
286 DT_EQ_INT(table[1].inv.handle, 0); | 304 DT_EQ_INT(table[1].inv.handle, 0); |
287 DT_EQ_INT(table[1].inv.update, 1); | 305 DT_EQ_INT(table[1].inv.update, 1); |
288 DT_EQ_INT(table[1].inv.draw, 0); | 306 DT_EQ_INT(table[1].inv.draw, 0); |
289 DT_EQ_INT(table[1].inv.end, 1); | 307 DT_EQ_INT(table[1].inv.end, 1); |
290 DT_EQ_INT(table[1].inv.finish, 0); | 308 DT_EQ_INT(table[1].inv.finish, 0); |
309 DT_EQ_INT(table[2].inv.start, 1); | |
291 DT_EQ_INT(table[2].inv.handle, 0); | 310 DT_EQ_INT(table[2].inv.handle, 0); |
292 DT_EQ_INT(table[2].inv.update, 3); | 311 DT_EQ_INT(table[2].inv.update, 3); |
293 DT_EQ_INT(table[2].inv.draw, 0); | 312 DT_EQ_INT(table[2].inv.draw, 0); |
294 DT_EQ_INT(table[2].inv.end, 0); | 313 DT_EQ_INT(table[2].inv.end, 0); |
295 DT_EQ_INT(table[2].inv.finish, 0); | 314 DT_EQ_INT(table[2].inv.finish, 0); |
296 | 315 |
297 /* Now, change its update function to complete the script. */ | 316 /* Now, change its update function to complete the script. */ |
298 table[2].act.update = my_update_true; | 317 table[2].act.update = my_update_true; |
299 DT_ASSERT(mlk_action_script_update(&sc, 0)); | 318 DT_ASSERT(mlk_action_script_update(&sc, 0)); |
300 DT_EQ_INT(table[0].inv.handle, 0); | 319 DT_EQ_INT(table[0].inv.start, 1); |
301 DT_EQ_INT(table[0].inv.update, 1); | 320 DT_EQ_INT(table[0].inv.handle, 0); |
302 DT_EQ_INT(table[0].inv.draw, 0); | 321 DT_EQ_INT(table[0].inv.update, 1); |
303 DT_EQ_INT(table[0].inv.end, 1); | 322 DT_EQ_INT(table[0].inv.draw, 0); |
304 DT_EQ_INT(table[0].inv.finish, 0); | 323 DT_EQ_INT(table[0].inv.end, 1); |
324 DT_EQ_INT(table[0].inv.finish, 0); | |
325 DT_EQ_INT(table[1].inv.start, 1); | |
305 DT_EQ_INT(table[1].inv.handle, 0); | 326 DT_EQ_INT(table[1].inv.handle, 0); |
306 DT_EQ_INT(table[1].inv.update, 1); | 327 DT_EQ_INT(table[1].inv.update, 1); |
307 DT_EQ_INT(table[1].inv.draw, 0); | 328 DT_EQ_INT(table[1].inv.draw, 0); |
308 DT_EQ_INT(table[1].inv.end, 1); | 329 DT_EQ_INT(table[1].inv.end, 1); |
309 DT_EQ_INT(table[1].inv.finish, 0); | 330 DT_EQ_INT(table[1].inv.finish, 0); |
331 DT_EQ_INT(table[2].inv.start, 1); | |
310 DT_EQ_INT(table[2].inv.handle, 0); | 332 DT_EQ_INT(table[2].inv.handle, 0); |
311 DT_EQ_INT(table[2].inv.update, 4); | 333 DT_EQ_INT(table[2].inv.update, 4); |
312 DT_EQ_INT(table[2].inv.draw, 0); | 334 DT_EQ_INT(table[2].inv.draw, 0); |
313 DT_EQ_INT(table[2].inv.end, 1); | 335 DT_EQ_INT(table[2].inv.end, 1); |
314 DT_EQ_INT(table[2].inv.finish, 0); | 336 DT_EQ_INT(table[2].inv.finish, 0); |