Mercurial > molko
comparison tests/test-action-script.c @ 441:31c1bbc33813
man: document mlk-action
author | David Demelier <markand@malikania.fr> |
---|---|
date | Mon, 24 Oct 2022 21:29:39 +0200 |
parents | 8f59201dc76b |
children | 773a082f0b91 |
comparison
equal
deleted
inserted
replaced
440:c9bd1ff1ebe1 | 441:31c1bbc33813 |
---|---|
38 .end = my_end, \ | 38 .end = my_end, \ |
39 .finish = my_finish \ | 39 .finish = my_finish \ |
40 } | 40 } |
41 | 41 |
42 static void | 42 static void |
43 my_handle(struct action *act, const union event *ev) | 43 my_handle(struct mlk_action *act, const union event *ev) |
44 { | 44 { |
45 (void)ev; | 45 (void)ev; |
46 | 46 |
47 ((struct invokes *)act->data)->handle++; | 47 ((struct invokes *)act->data)->handle++; |
48 } | 48 } |
49 | 49 |
50 static int | 50 static int |
51 my_update_false(struct action *act, unsigned int ticks) | 51 my_update_false(struct mlk_action *act, unsigned int ticks) |
52 { | 52 { |
53 (void)ticks; | 53 (void)ticks; |
54 | 54 |
55 ((struct invokes *)act->data)->update++; | 55 ((struct invokes *)act->data)->update++; |
56 | 56 |
57 return 0; | 57 return 0; |
58 } | 58 } |
59 | 59 |
60 static int | 60 static int |
61 my_update_true(struct action *act, unsigned int ticks) | 61 my_update_true(struct mlk_action *act, unsigned int ticks) |
62 { | 62 { |
63 (void)ticks; | 63 (void)ticks; |
64 | 64 |
65 ((struct invokes *)act->data)->update++; | 65 ((struct invokes *)act->data)->update++; |
66 | 66 |
67 return 1; | 67 return 1; |
68 } | 68 } |
69 | 69 |
70 static void | 70 static void |
71 my_draw(struct action *act) | 71 my_draw(struct mlk_action *act) |
72 { | 72 { |
73 ((struct invokes *)act->data)->draw++; | 73 ((struct invokes *)act->data)->draw++; |
74 } | 74 } |
75 | 75 |
76 static void | 76 static void |
77 my_end(struct action *act) | 77 my_end(struct mlk_action *act) |
78 { | 78 { |
79 ((struct invokes *)act->data)->end++; | 79 ((struct invokes *)act->data)->end++; |
80 } | 80 } |
81 | 81 |
82 static void | 82 static void |
83 my_finish(struct action *act) | 83 my_finish(struct mlk_action *act) |
84 { | 84 { |
85 ((struct invokes *)act->data)->finish++; | 85 ((struct invokes *)act->data)->finish++; |
86 } | 86 } |
87 | 87 |
88 static void | 88 static void |
97 } | 97 } |
98 | 98 |
99 static void | 99 static void |
100 test_basics_append(void) | 100 test_basics_append(void) |
101 { | 101 { |
102 struct action act[3] = {0}; | 102 struct mlk_action act[3] = {0}; |
103 struct script sc = {0}; | 103 struct script sc = {0}; |
104 | 104 |
105 DT_ASSERT(script_append(&sc, &act[0]) == 0); | 105 DT_ASSERT(script_append(&sc, &act[0]) == 0); |
106 DT_EQ_UINT(sc.cur, 0U); | 106 DT_EQ_UINT(sc.cur, 0U); |
107 DT_EQ_UINT(sc.actionsz, 1U); | 107 DT_EQ_UINT(sc.actionsz, 1U); |
126 static void | 126 static void |
127 test_basics_handle(void) | 127 test_basics_handle(void) |
128 { | 128 { |
129 struct { | 129 struct { |
130 struct invokes inv; | 130 struct invokes inv; |
131 struct action act; | 131 struct mlk_action act; |
132 } table[] = { | 132 } table[] = { |
133 { .act = INIT(&table[0].inv, my_update_true) }, | 133 { .act = INIT(&table[0].inv, my_update_true) }, |
134 { .act = INIT(&table[1].inv, my_update_true) }, | 134 { .act = INIT(&table[1].inv, my_update_true) }, |
135 { .act = INIT(&table[2].inv, my_update_false) } | 135 { .act = INIT(&table[2].inv, my_update_false) } |
136 }; | 136 }; |
203 static void | 203 static void |
204 test_basics_update(void) | 204 test_basics_update(void) |
205 { | 205 { |
206 struct { | 206 struct { |
207 struct invokes inv; | 207 struct invokes inv; |
208 struct action act; | 208 struct mlk_action act; |
209 } table[] = { | 209 } table[] = { |
210 { .act = INIT(&table[0].inv, my_update_true) }, | 210 { .act = INIT(&table[0].inv, my_update_true) }, |
211 { .act = INIT(&table[1].inv, my_update_true) }, | 211 { .act = INIT(&table[1].inv, my_update_true) }, |
212 { .act = INIT(&table[2].inv, my_update_false) } | 212 { .act = INIT(&table[2].inv, my_update_false) } |
213 }; | 213 }; |
297 static void | 297 static void |
298 test_basics_draw(void) | 298 test_basics_draw(void) |
299 { | 299 { |
300 struct { | 300 struct { |
301 struct invokes inv; | 301 struct invokes inv; |
302 struct action act; | 302 struct mlk_action act; |
303 } table[] = { | 303 } table[] = { |
304 { .act = INIT(&table[0].inv, my_update_true) }, | 304 { .act = INIT(&table[0].inv, my_update_true) }, |
305 { .act = INIT(&table[1].inv, my_update_true) }, | 305 { .act = INIT(&table[1].inv, my_update_true) }, |
306 { .act = INIT(&table[2].inv, my_update_false) } | 306 { .act = INIT(&table[2].inv, my_update_false) } |
307 }; | 307 }; |
374 static void | 374 static void |
375 test_basics_finish(void) | 375 test_basics_finish(void) |
376 { | 376 { |
377 struct { | 377 struct { |
378 struct invokes inv; | 378 struct invokes inv; |
379 struct action act; | 379 struct mlk_action act; |
380 } table[] = { | 380 } table[] = { |
381 { .act = INIT(&table[0].inv, my_update_true) }, | 381 { .act = INIT(&table[0].inv, my_update_true) }, |
382 { .act = INIT(&table[1].inv, my_update_true) }, | 382 { .act = INIT(&table[1].inv, my_update_true) }, |
383 { .act = INIT(&table[2].inv, my_update_false) } | 383 { .act = INIT(&table[2].inv, my_update_false) } |
384 }; | 384 }; |
414 static void | 414 static void |
415 test_action_simple(void) | 415 test_action_simple(void) |
416 { | 416 { |
417 struct { | 417 struct { |
418 struct invokes inv; | 418 struct invokes inv; |
419 struct action act; | 419 struct mlk_action act; |
420 } table[] = { | 420 } table[] = { |
421 { .act = INIT(&table[0].inv, my_update_true) }, | 421 { .act = INIT(&table[0].inv, my_update_true) }, |
422 { .act = INIT(&table[1].inv, my_update_true) }, | 422 { .act = INIT(&table[1].inv, my_update_true) }, |
423 { .act = INIT(&table[2].inv, my_update_false) } | 423 { .act = INIT(&table[2].inv, my_update_false) } |
424 }; | 424 }; |
425 | 425 |
426 struct script sc = {0}; | 426 struct script sc = {0}; |
427 struct action act; | 427 struct mlk_action act; |
428 | 428 |
429 DT_ASSERT(script_append(&sc, &table[0].act) == 0); | 429 DT_ASSERT(script_append(&sc, &table[0].act) == 0); |
430 DT_ASSERT(script_append(&sc, &table[1].act) == 0); | 430 DT_ASSERT(script_append(&sc, &table[1].act) == 0); |
431 DT_ASSERT(script_append(&sc, &table[2].act) == 0); | 431 DT_ASSERT(script_append(&sc, &table[2].act) == 0); |
432 | 432 |
433 /* Now convert this script into an action itself. */ | 433 /* Now convert this script into an action itself. */ |
434 script_action(&sc, &act); | 434 script_action(&sc, &act); |
435 | 435 |
436 /* Draw and input before updating. */ | 436 /* Draw and input before updating. */ |
437 action_handle(&act, &(union event){0}); | 437 mlk_action_handle(&act, &(union event){0}); |
438 action_draw(&act); | 438 mlk_action_draw(&act); |
439 | 439 |
440 /* [0] -> [1] */ | 440 /* [0] -> [1] */ |
441 DT_ASSERT(!action_update(&act, 0)); | 441 DT_ASSERT(!mlk_action_update(&act, 0)); |
442 DT_EQ_INT(table[0].inv.handle, 1); | 442 DT_EQ_INT(table[0].inv.handle, 1); |
443 DT_EQ_INT(table[0].inv.update, 1); | 443 DT_EQ_INT(table[0].inv.update, 1); |
444 DT_EQ_INT(table[0].inv.draw, 1); | 444 DT_EQ_INT(table[0].inv.draw, 1); |
445 DT_EQ_INT(table[0].inv.end, 1); | 445 DT_EQ_INT(table[0].inv.end, 1); |
446 DT_EQ_INT(table[0].inv.finish, 0); | 446 DT_EQ_INT(table[0].inv.finish, 0); |
447 DT_EQ_INT(table[1].inv.handle, 0); | 447 DT_EQ_INT(table[1].inv.handle, 0); |
448 DT_EQ_INT(table[1].inv.update, 0); | 448 DT_EQ_INT(table[1].inv.update, 0); |
449 DT_EQ_INT(table[1].inv.draw, 0); | 449 DT_EQ_INT(table[1].inv.draw, 0); |
450 DT_EQ_INT(table[1].inv.end, 0); | 450 DT_EQ_INT(table[1].inv.end, 0); |
451 DT_EQ_INT(table[1].inv.finish, 0); | 451 DT_EQ_INT(table[1].inv.finish, 0); |
452 DT_EQ_INT(table[2].inv.handle, 0); | 452 DT_EQ_INT(table[2].inv.handle, 0); |
453 DT_EQ_INT(table[2].inv.update, 0); | 453 DT_EQ_INT(table[2].inv.update, 0); |
454 DT_EQ_INT(table[2].inv.draw, 0); | 454 DT_EQ_INT(table[2].inv.draw, 0); |
455 DT_EQ_INT(table[2].inv.end, 0); | 455 DT_EQ_INT(table[2].inv.end, 0); |
456 DT_EQ_INT(table[2].inv.finish, 0); | 456 DT_EQ_INT(table[2].inv.finish, 0); |
457 | 457 |
458 action_handle(&act, &(union event){0}); | 458 mlk_action_handle(&act, &(union event){0}); |
459 action_draw(&act); | 459 mlk_action_draw(&act); |
460 | 460 |
461 /* [1] -> [2] */ | 461 /* [1] -> [2] */ |
462 DT_ASSERT(!action_update(&act, 0)); | 462 DT_ASSERT(!mlk_action_update(&act, 0)); |
463 DT_EQ_INT(table[0].inv.handle, 1); | 463 DT_EQ_INT(table[0].inv.handle, 1); |
464 DT_EQ_INT(table[0].inv.update, 1); | 464 DT_EQ_INT(table[0].inv.update, 1); |
465 DT_EQ_INT(table[0].inv.draw, 1); | 465 DT_EQ_INT(table[0].inv.draw, 1); |
466 DT_EQ_INT(table[0].inv.end, 1); | 466 DT_EQ_INT(table[0].inv.end, 1); |
467 DT_EQ_INT(table[0].inv.finish, 0); | 467 DT_EQ_INT(table[0].inv.finish, 0); |
474 DT_EQ_INT(table[2].inv.update, 0); | 474 DT_EQ_INT(table[2].inv.update, 0); |
475 DT_EQ_INT(table[2].inv.draw, 0); | 475 DT_EQ_INT(table[2].inv.draw, 0); |
476 DT_EQ_INT(table[2].inv.end, 0); | 476 DT_EQ_INT(table[2].inv.end, 0); |
477 DT_EQ_INT(table[2].inv.finish, 0); | 477 DT_EQ_INT(table[2].inv.finish, 0); |
478 | 478 |
479 action_handle(&act, &(union event){0}); | 479 mlk_action_handle(&act, &(union event){0}); |
480 action_draw(&act); | 480 mlk_action_draw(&act); |
481 | 481 |
482 /* 2 stays, it never ends. */ | 482 /* 2 stays, it never ends. */ |
483 DT_ASSERT(!action_update(&act, 0)); | 483 DT_ASSERT(!mlk_action_update(&act, 0)); |
484 DT_ASSERT(!action_update(&act, 0)); | 484 DT_ASSERT(!mlk_action_update(&act, 0)); |
485 DT_ASSERT(!action_update(&act, 0)); | 485 DT_ASSERT(!mlk_action_update(&act, 0)); |
486 DT_EQ_INT(table[0].inv.handle, 1); | 486 DT_EQ_INT(table[0].inv.handle, 1); |
487 DT_EQ_INT(table[0].inv.update, 1); | 487 DT_EQ_INT(table[0].inv.update, 1); |
488 DT_EQ_INT(table[0].inv.draw, 1); | 488 DT_EQ_INT(table[0].inv.draw, 1); |
489 DT_EQ_INT(table[0].inv.end, 1); | 489 DT_EQ_INT(table[0].inv.end, 1); |
490 DT_EQ_INT(table[0].inv.finish, 0); | 490 DT_EQ_INT(table[0].inv.finish, 0); |
498 DT_EQ_INT(table[2].inv.draw, 1); | 498 DT_EQ_INT(table[2].inv.draw, 1); |
499 DT_EQ_INT(table[2].inv.end, 0); | 499 DT_EQ_INT(table[2].inv.end, 0); |
500 DT_EQ_INT(table[2].inv.finish, 0); | 500 DT_EQ_INT(table[2].inv.finish, 0); |
501 | 501 |
502 table[2].act.update = my_update_true; | 502 table[2].act.update = my_update_true; |
503 DT_ASSERT(action_update(&act, 0)); | 503 DT_ASSERT(mlk_action_update(&act, 0)); |
504 DT_EQ_INT(table[0].inv.handle, 1); | 504 DT_EQ_INT(table[0].inv.handle, 1); |
505 DT_EQ_INT(table[0].inv.update, 1); | 505 DT_EQ_INT(table[0].inv.update, 1); |
506 DT_EQ_INT(table[0].inv.draw, 1); | 506 DT_EQ_INT(table[0].inv.draw, 1); |
507 DT_EQ_INT(table[0].inv.end, 1); | 507 DT_EQ_INT(table[0].inv.end, 1); |
508 DT_EQ_INT(table[0].inv.finish, 0); | 508 DT_EQ_INT(table[0].inv.finish, 0); |
516 DT_EQ_INT(table[2].inv.draw, 1); | 516 DT_EQ_INT(table[2].inv.draw, 1); |
517 DT_EQ_INT(table[2].inv.end, 1); | 517 DT_EQ_INT(table[2].inv.end, 1); |
518 DT_EQ_INT(table[2].inv.finish, 0); | 518 DT_EQ_INT(table[2].inv.finish, 0); |
519 | 519 |
520 /* Also dispose resources. */ | 520 /* Also dispose resources. */ |
521 action_finish(&act); | 521 mlk_action_finish(&act); |
522 DT_EQ_INT(table[0].inv.handle, 1); | 522 DT_EQ_INT(table[0].inv.handle, 1); |
523 DT_EQ_INT(table[0].inv.update, 1); | 523 DT_EQ_INT(table[0].inv.update, 1); |
524 DT_EQ_INT(table[0].inv.draw, 1); | 524 DT_EQ_INT(table[0].inv.draw, 1); |
525 DT_EQ_INT(table[0].inv.end, 1); | 525 DT_EQ_INT(table[0].inv.end, 1); |
526 DT_EQ_INT(table[0].inv.finish, 1); | 526 DT_EQ_INT(table[0].inv.finish, 1); |