comparison tests/test-action-script.c @ 407:e6f972e04519

tests: don't use automatic feature
author David Demelier <markand@malikania.fr>
date Wed, 06 Apr 2022 12:09:25 +0200
parents 460c78706989
children 0ea90751a62d
comparison
equal deleted inserted replaced
406:107fc5c77df2 407:e6f972e04519
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
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 <rexo.h>
20
21 #include <core/action.h> 19 #include <core/action.h>
22 #include <core/event.h> 20 #include <core/event.h>
23 #include <core/script.h> 21 #include <core/script.h>
22
23 #include "test.h"
24 24
25 struct invokes { 25 struct invokes {
26 int handle; 26 int handle;
27 int update; 27 int update;
28 int draw; 28 int draw;
83 my_finish(struct action *act) 83 my_finish(struct action *act)
84 { 84 {
85 ((struct invokes *)act->data)->finish++; 85 ((struct invokes *)act->data)->finish++;
86 } 86 }
87 87
88 RX_TEST_CASE(basics, init) 88 TEST_DECL(basics_init)
89 { 89 {
90 struct script sc; 90 struct script sc;
91 91
92 script_init(&sc); 92 script_init(&sc);
93 93
94 RX_UINT_REQUIRE_EQUAL(sc.actionsz, 0U); 94 RX_UINT_REQUIRE_EQUAL(sc.actionsz, 0U);
95 RX_UINT_REQUIRE_EQUAL(sc.cur, 0U); 95 RX_UINT_REQUIRE_EQUAL(sc.cur, 0U);
96 } 96 }
97 97
98 RX_TEST_CASE(basics, append) 98 TEST_DECL(basics_append)
99 { 99 {
100 struct action act[3] = {0}; 100 struct action act[3] = {0};
101 struct script sc = {0}; 101 struct script sc = {0};
102 102
103 RX_REQUIRE(script_append(&sc, &act[0]) == 0); 103 RX_REQUIRE(script_append(&sc, &act[0]) == 0);
119 RX_PTR_REQUIRE_EQUAL(sc.actions[2], &act[2]); 119 RX_PTR_REQUIRE_EQUAL(sc.actions[2], &act[2]);
120 120
121 script_finish(&sc); 121 script_finish(&sc);
122 } 122 }
123 123
124 RX_TEST_CASE(basics, handle) 124 TEST_DECL(basics_handle)
125 { 125 {
126 struct { 126 struct {
127 struct invokes inv; 127 struct invokes inv;
128 struct action act; 128 struct action act;
129 } table[] = { 129 } table[] = {
130 { .act = INIT(&table[0].inv, my_update_true) }, 130 { .act = INIT(&table[0].inv, my_update_true) },
131 { .act = INIT(&table[1].inv, my_update_true) }, 131 { .act = INIT(&table[1].inv, my_update_true) },
132 { .act = INIT(&table[2].inv, my_update_false) } 132 { .act = INIT(&table[2].inv, my_update_false) }
133 }; 133 };
134 134
135 struct script sc = {0}; 135 struct script sc = {0};
136 136
137 RX_REQUIRE(script_append(&sc, &table[0].act) == 0); 137 RX_REQUIRE(script_append(&sc, &table[0].act) == 0);
138 RX_REQUIRE(script_append(&sc, &table[1].act) == 0); 138 RX_REQUIRE(script_append(&sc, &table[1].act) == 0);
139 RX_REQUIRE(script_append(&sc, &table[2].act) == 0); 139 RX_REQUIRE(script_append(&sc, &table[2].act) == 0);
195 RX_INT_REQUIRE_EQUAL(table[2].inv.draw, 0); 195 RX_INT_REQUIRE_EQUAL(table[2].inv.draw, 0);
196 RX_INT_REQUIRE_EQUAL(table[2].inv.end, 0); 196 RX_INT_REQUIRE_EQUAL(table[2].inv.end, 0);
197 RX_INT_REQUIRE_EQUAL(table[2].inv.finish, 0); 197 RX_INT_REQUIRE_EQUAL(table[2].inv.finish, 0);
198 } 198 }
199 199
200 RX_TEST_CASE(basics, update) 200 TEST_DECL(basics_update)
201 { 201 {
202 struct { 202 struct {
203 struct invokes inv; 203 struct invokes inv;
204 struct action act; 204 struct action act;
205 } table[] = { 205 } table[] = {
206 { .act = INIT(&table[0].inv, my_update_true) }, 206 { .act = INIT(&table[0].inv, my_update_true) },
207 { .act = INIT(&table[1].inv, my_update_true) }, 207 { .act = INIT(&table[1].inv, my_update_true) },
208 { .act = INIT(&table[2].inv, my_update_false) } 208 { .act = INIT(&table[2].inv, my_update_false) }
209 }; 209 };
210 210
211 struct script sc = {0}; 211 struct script sc = {0};
212 212
213 RX_REQUIRE(script_append(&sc, &table[0].act) == 0); 213 RX_REQUIRE(script_append(&sc, &table[0].act) == 0);
214 RX_REQUIRE(script_append(&sc, &table[1].act) == 0); 214 RX_REQUIRE(script_append(&sc, &table[1].act) == 0);
215 RX_REQUIRE(script_append(&sc, &table[2].act) == 0); 215 RX_REQUIRE(script_append(&sc, &table[2].act) == 0);
288 RX_INT_REQUIRE_EQUAL(table[2].inv.draw, 0); 288 RX_INT_REQUIRE_EQUAL(table[2].inv.draw, 0);
289 RX_INT_REQUIRE_EQUAL(table[2].inv.end, 1); 289 RX_INT_REQUIRE_EQUAL(table[2].inv.end, 1);
290 RX_INT_REQUIRE_EQUAL(table[2].inv.finish, 0); 290 RX_INT_REQUIRE_EQUAL(table[2].inv.finish, 0);
291 } 291 }
292 292
293 RX_TEST_CASE(basics, draw) 293 TEST_DECL(basics_draw)
294 { 294 {
295 struct { 295 struct {
296 struct invokes inv; 296 struct invokes inv;
297 struct action act; 297 struct action act;
298 } table[] = { 298 } table[] = {
299 { .act = INIT(&table[0].inv, my_update_true) }, 299 { .act = INIT(&table[0].inv, my_update_true) },
300 { .act = INIT(&table[1].inv, my_update_true) }, 300 { .act = INIT(&table[1].inv, my_update_true) },
301 { .act = INIT(&table[2].inv, my_update_false) } 301 { .act = INIT(&table[2].inv, my_update_false) }
302 }; 302 };
303 303
304 struct script sc = {0}; 304 struct script sc = {0};
305 305
306 RX_REQUIRE(script_append(&sc, &table[0].act) == 0); 306 RX_REQUIRE(script_append(&sc, &table[0].act) == 0);
307 RX_REQUIRE(script_append(&sc, &table[1].act) == 0); 307 RX_REQUIRE(script_append(&sc, &table[1].act) == 0);
308 RX_REQUIRE(script_append(&sc, &table[2].act) == 0); 308 RX_REQUIRE(script_append(&sc, &table[2].act) == 0);
364 RX_INT_REQUIRE_EQUAL(table[2].inv.draw, 1); 364 RX_INT_REQUIRE_EQUAL(table[2].inv.draw, 1);
365 RX_INT_REQUIRE_EQUAL(table[2].inv.end, 0); 365 RX_INT_REQUIRE_EQUAL(table[2].inv.end, 0);
366 RX_INT_REQUIRE_EQUAL(table[2].inv.finish, 0); 366 RX_INT_REQUIRE_EQUAL(table[2].inv.finish, 0);
367 } 367 }
368 368
369 RX_TEST_CASE(basics, finish) 369 TEST_DECL(basics_finish)
370 { 370 {
371 struct { 371 struct {
372 struct invokes inv; 372 struct invokes inv;
373 struct action act; 373 struct action act;
374 } table[] = { 374 } table[] = {
375 { .act = INIT(&table[0].inv, my_update_true) }, 375 { .act = INIT(&table[0].inv, my_update_true) },
376 { .act = INIT(&table[1].inv, my_update_true) }, 376 { .act = INIT(&table[1].inv, my_update_true) },
377 { .act = INIT(&table[2].inv, my_update_false) } 377 { .act = INIT(&table[2].inv, my_update_false) }
378 }; 378 };
379 379
380 struct script sc = {0}; 380 struct script sc = {0};
381 381
382 RX_REQUIRE(script_append(&sc, &table[0].act) == 0); 382 RX_REQUIRE(script_append(&sc, &table[0].act) == 0);
383 RX_REQUIRE(script_append(&sc, &table[1].act) == 0); 383 RX_REQUIRE(script_append(&sc, &table[1].act) == 0);
384 RX_REQUIRE(script_append(&sc, &table[2].act) == 0); 384 RX_REQUIRE(script_append(&sc, &table[2].act) == 0);
403 RX_INT_REQUIRE_EQUAL(table[2].inv.draw, 0); 403 RX_INT_REQUIRE_EQUAL(table[2].inv.draw, 0);
404 RX_INT_REQUIRE_EQUAL(table[2].inv.end, 0); 404 RX_INT_REQUIRE_EQUAL(table[2].inv.end, 0);
405 RX_INT_REQUIRE_EQUAL(table[2].inv.finish, 1); 405 RX_INT_REQUIRE_EQUAL(table[2].inv.finish, 1);
406 } 406 }
407 407
408 RX_TEST_CASE(action, simple) 408 TEST_DECL(action_simple)
409 { 409 {
410 struct { 410 struct {
411 struct invokes inv; 411 struct invokes inv;
412 struct action act; 412 struct action act;
413 } table[] = { 413 } table[] = {
414 { .act = INIT(&table[0].inv, my_update_true) }, 414 { .act = INIT(&table[0].inv, my_update_true) },
415 { .act = INIT(&table[1].inv, my_update_true) }, 415 { .act = INIT(&table[1].inv, my_update_true) },
416 { .act = INIT(&table[2].inv, my_update_false) } 416 { .act = INIT(&table[2].inv, my_update_false) }
417 }; 417 };
418 418
419 struct script sc = {0}; 419 struct script sc = {0};
420 struct action act; 420 struct action act;
421 421
422 RX_REQUIRE(script_append(&sc, &table[0].act) == 0); 422 RX_REQUIRE(script_append(&sc, &table[0].act) == 0);
423 RX_REQUIRE(script_append(&sc, &table[1].act) == 0); 423 RX_REQUIRE(script_append(&sc, &table[1].act) == 0);
527 RX_INT_REQUIRE_EQUAL(table[2].inv.draw, 1); 527 RX_INT_REQUIRE_EQUAL(table[2].inv.draw, 1);
528 RX_INT_REQUIRE_EQUAL(table[2].inv.end, 1); 528 RX_INT_REQUIRE_EQUAL(table[2].inv.end, 1);
529 RX_INT_REQUIRE_EQUAL(table[2].inv.finish, 1); 529 RX_INT_REQUIRE_EQUAL(table[2].inv.finish, 1);
530 } 530 }
531 531
532 static const struct rx_test_case tests[] = {
533 TEST_DEF("basics", "init", basics_init),
534 TEST_DEF("basics", "append", basics_append),
535 TEST_DEF("basics", "handle", basics_handle),
536 TEST_DEF("basics", "update", basics_update),
537 TEST_DEF("basics", "draw", basics_draw),
538 TEST_DEF("basics", "finish", basics_finish),
539 TEST_DEF("action", "simple", action_simple)
540 };
541
532 int 542 int
533 main(int argc, char **argv) 543 main(int argc, char **argv)
534 { 544 {
535 return rx_main(0, NULL, argc, (const char **)argv) == RX_SUCCESS ? 0 : 1; 545 return TEST_RUN(tests, argc, argv);
536 } 546 }