comparison tests/test-action-script.c @ 509:a11cd7ea3a37

core: doxygenize action
author David Demelier <markand@malikania.fr>
date Sat, 04 Mar 2023 08:52:57 +0100
parents d7855791a2b8
children c7664b679a95
comparison
equal deleted inserted replaced
508:7f7602bae0bd 509:a11cd7ea3a37
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 <mlk/core/action-script.h>
19 #include <mlk/core/action.h> 20 #include <mlk/core/action.h>
20 #include <mlk/core/err.h> 21 #include <mlk/core/err.h>
21 #include <mlk/core/event.h> 22 #include <mlk/core/event.h>
22 #include <mlk/core/action-script.h> 23 #include <mlk/core/util.h>
23 24
24 #include <dt.h> 25 #include <dt.h>
25 26
26 struct invokes { 27 struct invokes {
27 int start; 28 int start;
95 } 96 }
96 97
97 static void 98 static void
98 test_basics_init(void) 99 test_basics_init(void)
99 { 100 {
100 struct mlk_action_script sc;
101 struct mlk_action *actions[10]; 101 struct mlk_action *actions[10];
102 102 struct mlk_action_script sc = {
103 mlk_action_script_init(&sc, actions, 10); 103 .actions = actions,
104 104 .actionsz = MLK_UTIL_SIZE(actions)
105 DT_EQ_SIZE(sc.len, 0U); 105 };
106 DT_EQ_SIZE(sc.cap, 10U); 106
107 DT_EQ_SIZE(sc.cur, 0U); 107 mlk_action_script_init(&sc);
108
109 DT_EQ_SIZE(sc.actionsz, 10U);
110 DT_EQ_SIZE(sc.length, 0U);
111 DT_EQ_SIZE(sc.current, 0U);
112
113 mlk_action_script_finish(&sc);
114
115 DT_EQ_PTR(sc.actions, actions);
116 DT_EQ_SIZE(sc.actionsz, 10U);
117 DT_EQ_SIZE(sc.length, 0U);
118 DT_EQ_SIZE(sc.current, 0U);
108 } 119 }
109 120
110 static void 121 static void
111 test_basics_append(void) 122 test_basics_append(void)
112 { 123 {
113 struct mlk_action actions[4] = {0}; 124 struct mlk_action actions[4] = {0};
114 struct mlk_action *array[3] = {0}; 125 struct mlk_action *array[3] = {0};
115 struct mlk_action_script sc = {0}; 126 struct mlk_action_script sc = {
116 127 .actions = array,
117 mlk_action_script_init(&sc, array, 3); 128 .actionsz = MLK_UTIL_SIZE(array)
129 };
130
131 mlk_action_script_init(&sc);
118 132
119 DT_ASSERT(mlk_action_script_append(&sc, &actions[0]) == 0); 133 DT_ASSERT(mlk_action_script_append(&sc, &actions[0]) == 0);
120 DT_EQ_SIZE(sc.len, 1U); 134 DT_EQ_SIZE(sc.actionsz, 3U);
121 DT_EQ_SIZE(sc.cap, 3U); 135 DT_EQ_SIZE(sc.length, 1U);
122 DT_EQ_SIZE(sc.cur, 0U); 136 DT_EQ_SIZE(sc.current, 0U);
123 DT_EQ_PTR(sc.actions[0], &actions[0]); 137 DT_EQ_PTR(sc.actions[0], &actions[0]);
124 138
125 DT_ASSERT(mlk_action_script_append(&sc, &actions[1]) == 0); 139 DT_ASSERT(mlk_action_script_append(&sc, &actions[1]) == 0);
126 DT_EQ_SIZE(sc.len, 2U); 140 DT_EQ_SIZE(sc.actionsz, 3U);
127 DT_EQ_SIZE(sc.cap, 3U); 141 DT_EQ_SIZE(sc.length, 2U);
128 DT_EQ_SIZE(sc.cur, 0U); 142 DT_EQ_SIZE(sc.current, 0U);
129 DT_EQ_PTR(sc.actions[0], &actions[0]); 143 DT_EQ_PTR(sc.actions[0], &actions[0]);
130 DT_EQ_PTR(sc.actions[1], &actions[1]); 144 DT_EQ_PTR(sc.actions[1], &actions[1]);
131 145
132 DT_ASSERT(mlk_action_script_append(&sc, &actions[2]) == 0); 146 DT_ASSERT(mlk_action_script_append(&sc, &actions[2]) == 0);
133 DT_EQ_SIZE(sc.len, 3U); 147 DT_EQ_SIZE(sc.actionsz, 3U);
134 DT_EQ_SIZE(sc.cap, 3U); 148 DT_EQ_SIZE(sc.length, 3U);
135 DT_EQ_SIZE(sc.cur, 0U); 149 DT_EQ_SIZE(sc.current, 0U);
136 DT_EQ_PTR(sc.actions[0], &actions[0]); 150 DT_EQ_PTR(sc.actions[0], &actions[0]);
137 DT_EQ_PTR(sc.actions[1], &actions[1]); 151 DT_EQ_PTR(sc.actions[1], &actions[1]);
138 DT_EQ_PTR(sc.actions[2], &actions[2]); 152 DT_EQ_PTR(sc.actions[2], &actions[2]);
139 153
140 /* This can not fit. */ 154 /* This can not fit. */
141 DT_ASSERT(mlk_action_script_append(&sc, &actions[3]) == MLK_ERR_NO_MEM); 155 DT_ASSERT(mlk_action_script_append(&sc, &actions[3]) == MLK_ERR_NO_MEM);
142 156
143 mlk_action_script_finish(&sc); 157 mlk_action_script_finish(&sc);
158
159 DT_EQ_PTR(sc.actions, array);
160 DT_EQ_SIZE(sc.actionsz, 3U);
161 DT_EQ_SIZE(sc.length, 0U);
162 DT_EQ_SIZE(sc.current, 0U);
144 } 163 }
145 164
146 static void 165 static void
147 test_basics_handle(void) 166 test_basics_handle(void)
148 { 167 {
154 { .act = INIT(&table[1].inv, my_update_true) }, 173 { .act = INIT(&table[1].inv, my_update_true) },
155 { .act = INIT(&table[2].inv, my_update_false) } 174 { .act = INIT(&table[2].inv, my_update_false) }
156 }; 175 };
157 176
158 struct mlk_action *array[3] = {0}; 177 struct mlk_action *array[3] = {0};
159 struct mlk_action_script sc = {0}; 178 struct mlk_action_script sc = {
160 179 .actions = array,
161 mlk_action_script_init(&sc, array, 3); 180 .actionsz = MLK_UTIL_SIZE(array)
181 };
182
183 mlk_action_script_init(&sc);
162 184
163 DT_ASSERT(mlk_action_script_append(&sc, &table[0].act) == 0); 185 DT_ASSERT(mlk_action_script_append(&sc, &table[0].act) == 0);
164 DT_ASSERT(mlk_action_script_append(&sc, &table[1].act) == 0); 186 DT_ASSERT(mlk_action_script_append(&sc, &table[1].act) == 0);
165 DT_ASSERT(mlk_action_script_append(&sc, &table[2].act) == 0); 187 DT_ASSERT(mlk_action_script_append(&sc, &table[2].act) == 0);
166 188
167 /* [0] */ 189 /* [0] */
168 mlk_action_script_handle(&sc, &(union mlk_event){0}); 190 mlk_action_script_handle(&sc, &(const union mlk_event){0});
169 DT_EQ_INT(table[0].inv.handle, 1); 191 DT_EQ_INT(table[0].inv.handle, 1);
170 DT_EQ_INT(table[0].inv.update, 0); 192 DT_EQ_INT(table[0].inv.update, 0);
171 DT_EQ_INT(table[0].inv.draw, 0); 193 DT_EQ_INT(table[0].inv.draw, 0);
172 DT_EQ_INT(table[0].inv.end, 0); 194 DT_EQ_INT(table[0].inv.end, 0);
173 DT_EQ_INT(table[0].inv.finish, 0); 195 DT_EQ_INT(table[0].inv.finish, 0);
236 { .act = INIT(&table[1].inv, my_update_true) }, 258 { .act = INIT(&table[1].inv, my_update_true) },
237 { .act = INIT(&table[2].inv, my_update_false) } 259 { .act = INIT(&table[2].inv, my_update_false) }
238 }; 260 };
239 261
240 struct mlk_action *array[3]; 262 struct mlk_action *array[3];
241 struct mlk_action_script sc = {0}; 263 struct mlk_action_script sc = {
242 264 .actions = array,
243 mlk_action_script_init(&sc, array, 3); 265 .actionsz = MLK_UTIL_SIZE(array)
266 };
267
268 mlk_action_script_init(&sc);
244 269
245 DT_ASSERT(mlk_action_script_append(&sc, &table[0].act) == 0); 270 DT_ASSERT(mlk_action_script_append(&sc, &table[0].act) == 0);
246 DT_ASSERT(mlk_action_script_append(&sc, &table[1].act) == 0); 271 DT_ASSERT(mlk_action_script_append(&sc, &table[1].act) == 0);
247 DT_ASSERT(mlk_action_script_append(&sc, &table[2].act) == 0); 272 DT_ASSERT(mlk_action_script_append(&sc, &table[2].act) == 0);
248 273
349 { .act = INIT(&table[1].inv, my_update_true) }, 374 { .act = INIT(&table[1].inv, my_update_true) },
350 { .act = INIT(&table[2].inv, my_update_false) } 375 { .act = INIT(&table[2].inv, my_update_false) }
351 }; 376 };
352 377
353 struct mlk_action *array[3]; 378 struct mlk_action *array[3];
354 struct mlk_action_script sc = {0}; 379 struct mlk_action_script sc = {
355 380 .actions = array,
356 mlk_action_script_init(&sc, array, 3); 381 .actionsz = MLK_UTIL_SIZE(array)
382 };
383
384 mlk_action_script_init(&sc);
357 385
358 DT_ASSERT(mlk_action_script_append(&sc, &table[0].act) == 0); 386 DT_ASSERT(mlk_action_script_append(&sc, &table[0].act) == 0);
359 DT_ASSERT(mlk_action_script_append(&sc, &table[1].act) == 0); 387 DT_ASSERT(mlk_action_script_append(&sc, &table[1].act) == 0);
360 DT_ASSERT(mlk_action_script_append(&sc, &table[2].act) == 0); 388 DT_ASSERT(mlk_action_script_append(&sc, &table[2].act) == 0);
361 389
429 { .act = INIT(&table[1].inv, my_update_true) }, 457 { .act = INIT(&table[1].inv, my_update_true) },
430 { .act = INIT(&table[2].inv, my_update_false) } 458 { .act = INIT(&table[2].inv, my_update_false) }
431 }; 459 };
432 460
433 struct mlk_action *array[3]; 461 struct mlk_action *array[3];
434 struct mlk_action_script sc = {0}; 462 struct mlk_action_script sc = {
435 463 .actions = array,
436 mlk_action_script_init(&sc, array, 3); 464 .actionsz = MLK_UTIL_SIZE(array)
465 };
466
467 mlk_action_script_init(&sc);
437 468
438 DT_ASSERT(mlk_action_script_append(&sc, &table[0].act) == 0); 469 DT_ASSERT(mlk_action_script_append(&sc, &table[0].act) == 0);
439 DT_ASSERT(mlk_action_script_append(&sc, &table[1].act) == 0); 470 DT_ASSERT(mlk_action_script_append(&sc, &table[1].act) == 0);
440 DT_ASSERT(mlk_action_script_append(&sc, &table[2].act) == 0); 471 DT_ASSERT(mlk_action_script_append(&sc, &table[2].act) == 0);
441 472