Mercurial > molko
comparison tests/test-state.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 | ef4d4a51aeb7 |
children | 0ea90751a62d |
comparison
equal
deleted
inserted
replaced
406:107fc5c77df2 | 407:e6f972e04519 |
---|---|
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 <string.h> | 19 #include <string.h> |
20 | 20 |
21 #include <rexo.h> | |
22 | |
23 #include <core/event.h> | 21 #include <core/event.h> |
24 #include <core/game.h> | 22 #include <core/game.h> |
25 #include <core/state.h> | 23 #include <core/state.h> |
26 #include <core/util.h> | 24 #include <core/util.h> |
25 | |
26 #include "test.h" | |
27 | 27 |
28 struct invokes { | 28 struct invokes { |
29 unsigned int start; | 29 unsigned int start; |
30 unsigned int handle; | 30 unsigned int handle; |
31 unsigned int update; | 31 unsigned int update; |
36 unsigned int finish; | 36 unsigned int finish; |
37 }; | 37 }; |
38 | 38 |
39 static struct state *states[16]; | 39 static struct state *states[16]; |
40 | 40 |
41 RX_SET_UP(setup) | 41 RX_SET_UP(basics_setup) |
42 { | 42 { |
43 game_init(states, UTIL_SIZE(states)); | 43 game_init(states, UTIL_SIZE(states)); |
44 | 44 |
45 return RX_SUCCESS; | 45 return RX_SUCCESS; |
46 } | 46 } |
47 | 47 |
48 RX_TEAR_DOWN(teardown) | 48 RX_TEAR_DOWN(basics_teardown) |
49 { | 49 { |
50 game_quit(); | 50 game_quit(); |
51 } | 51 } |
52 | 52 |
53 static void | 53 static void |
112 .resume = my_resume, \ | 112 .resume = my_resume, \ |
113 .end = my_end, \ | 113 .end = my_end, \ |
114 .finish = my_finish \ | 114 .finish = my_finish \ |
115 } | 115 } |
116 | 116 |
117 RX_FIXTURE(basics_fixture, void *, .set_up = setup, .tear_down = teardown); | 117 TEST_DECL(basics_start) |
118 | |
119 RX_TEST_CASE(basics, start) | |
120 { | 118 { |
121 struct invokes inv = {0}; | 119 struct invokes inv = {0}; |
122 struct state state = INIT(&inv); | 120 struct state state = INIT(&inv); |
123 | 121 |
124 state_start(&state); | 122 state_start(&state); |
128 RX_UINT_REQUIRE_EQUAL(inv.draw, 0U); | 126 RX_UINT_REQUIRE_EQUAL(inv.draw, 0U); |
129 RX_UINT_REQUIRE_EQUAL(inv.end, 0U); | 127 RX_UINT_REQUIRE_EQUAL(inv.end, 0U); |
130 RX_UINT_REQUIRE_EQUAL(inv.finish, 0U); | 128 RX_UINT_REQUIRE_EQUAL(inv.finish, 0U); |
131 } | 129 } |
132 | 130 |
133 RX_TEST_CASE(basics, handle) | 131 TEST_DECL(basics_handle) |
134 { | 132 { |
135 struct invokes inv = {0}; | 133 struct invokes inv = {0}; |
136 struct state state = INIT(&inv); | 134 struct state state = INIT(&inv); |
137 | 135 |
138 state_handle(&state, &(const union event){0}); | 136 state_handle(&state, &(const union event){0}); |
142 RX_UINT_REQUIRE_EQUAL(inv.draw, 0U); | 140 RX_UINT_REQUIRE_EQUAL(inv.draw, 0U); |
143 RX_UINT_REQUIRE_EQUAL(inv.end, 0U); | 141 RX_UINT_REQUIRE_EQUAL(inv.end, 0U); |
144 RX_UINT_REQUIRE_EQUAL(inv.finish, 0U); | 142 RX_UINT_REQUIRE_EQUAL(inv.finish, 0U); |
145 } | 143 } |
146 | 144 |
147 RX_TEST_CASE(basics, update) | 145 TEST_DECL(basics_update) |
148 { | 146 { |
149 struct invokes inv = {0}; | 147 struct invokes inv = {0}; |
150 struct state state = INIT(&inv); | 148 struct state state = INIT(&inv); |
151 | 149 |
152 state_update(&state, 0); | 150 state_update(&state, 0); |
156 RX_UINT_REQUIRE_EQUAL(inv.draw, 0U); | 154 RX_UINT_REQUIRE_EQUAL(inv.draw, 0U); |
157 RX_UINT_REQUIRE_EQUAL(inv.end, 0U); | 155 RX_UINT_REQUIRE_EQUAL(inv.end, 0U); |
158 RX_UINT_REQUIRE_EQUAL(inv.finish, 0U); | 156 RX_UINT_REQUIRE_EQUAL(inv.finish, 0U); |
159 } | 157 } |
160 | 158 |
161 RX_TEST_CASE(basics, draw) | 159 TEST_DECL(basics_draw) |
162 { | 160 { |
163 struct invokes inv = {0}; | 161 struct invokes inv = {0}; |
164 struct state state = INIT(&inv); | 162 struct state state = INIT(&inv); |
165 | 163 |
166 state_draw(&state); | 164 state_draw(&state); |
170 RX_UINT_REQUIRE_EQUAL(inv.draw, 1U); | 168 RX_UINT_REQUIRE_EQUAL(inv.draw, 1U); |
171 RX_UINT_REQUIRE_EQUAL(inv.end, 0U); | 169 RX_UINT_REQUIRE_EQUAL(inv.end, 0U); |
172 RX_UINT_REQUIRE_EQUAL(inv.finish, 0U); | 170 RX_UINT_REQUIRE_EQUAL(inv.finish, 0U); |
173 } | 171 } |
174 | 172 |
175 RX_TEST_CASE(basics, end) | 173 TEST_DECL(basics_end) |
176 { | 174 { |
177 struct invokes inv = {0}; | 175 struct invokes inv = {0}; |
178 struct state state = INIT(&inv); | 176 struct state state = INIT(&inv); |
179 | 177 |
180 state_end(&state); | 178 state_end(&state); |
184 RX_UINT_REQUIRE_EQUAL(inv.draw, 0U); | 182 RX_UINT_REQUIRE_EQUAL(inv.draw, 0U); |
185 RX_UINT_REQUIRE_EQUAL(inv.end, 1U); | 183 RX_UINT_REQUIRE_EQUAL(inv.end, 1U); |
186 RX_UINT_REQUIRE_EQUAL(inv.finish, 0U); | 184 RX_UINT_REQUIRE_EQUAL(inv.finish, 0U); |
187 } | 185 } |
188 | 186 |
189 RX_TEST_CASE(basics, finish) | 187 TEST_DECL(basics_finish) |
190 { | 188 { |
191 struct invokes inv = {0}; | 189 struct invokes inv = {0}; |
192 struct state state = INIT(&inv); | 190 struct state state = INIT(&inv); |
193 | 191 |
194 state_finish(&state); | 192 state_finish(&state); |
198 RX_UINT_REQUIRE_EQUAL(inv.draw, 0U); | 196 RX_UINT_REQUIRE_EQUAL(inv.draw, 0U); |
199 RX_UINT_REQUIRE_EQUAL(inv.end, 0U); | 197 RX_UINT_REQUIRE_EQUAL(inv.end, 0U); |
200 RX_UINT_REQUIRE_EQUAL(inv.finish, 1U); | 198 RX_UINT_REQUIRE_EQUAL(inv.finish, 1U); |
201 } | 199 } |
202 | 200 |
203 RX_TEST_CASE(game, game_push, .fixture = basics_fixture) | 201 TEST_DECL(basics_game) |
204 { | 202 { |
205 static struct { | 203 static struct { |
206 struct invokes inv; | 204 struct invokes inv; |
207 struct state state; | 205 struct state state; |
208 } states[] = { | 206 } states[] = { |
321 RX_UINT_REQUIRE_EQUAL(states[1].inv.resume, 0U); | 319 RX_UINT_REQUIRE_EQUAL(states[1].inv.resume, 0U); |
322 RX_UINT_REQUIRE_EQUAL(states[1].inv.end, 1U); | 320 RX_UINT_REQUIRE_EQUAL(states[1].inv.end, 1U); |
323 RX_UINT_REQUIRE_EQUAL(states[1].inv.finish, 1U); | 321 RX_UINT_REQUIRE_EQUAL(states[1].inv.finish, 1U); |
324 } | 322 } |
325 | 323 |
324 static const struct rx_test_case tests[] = { | |
325 TEST_DEF("basics", "start", basics_start), | |
326 TEST_DEF("basics", "handle", basics_handle), | |
327 TEST_DEF("basics", "update", basics_update), | |
328 TEST_DEF("basics", "draw", basics_draw), | |
329 TEST_DEF("basics", "end", basics_end), | |
330 TEST_DEF("basics", "finish", basics_finish), | |
331 TEST_DEF_FIX("basics", "game", basics_game, void *, basics_setup, basics_teardown) | |
332 }; | |
333 | |
326 int | 334 int |
327 main(int argc, char **argv) | 335 main(int argc, char **argv) |
328 { | 336 { |
329 return rx_main(0, NULL, argc, (const char **)argv) == RX_SUCCESS ? 0 : 1; | 337 return TEST_RUN(tests, argc, argv); |
330 } | 338 } |