comparison tests/test-drawable.c @ 458:02c1481b7dbb

tests: fix
author David Demelier <markand@malikania.fr>
date Fri, 24 Feb 2023 22:14:42 +0100
parents 773a082f0b91
children 6af0524913b3
comparison
equal deleted inserted replaced
457:04797b35565c 458:02c1481b7dbb
37 .end = my_end, \ 37 .end = my_end, \
38 .finish = my_finish \ 38 .finish = my_finish \
39 } 39 }
40 40
41 static int 41 static int
42 my_update_false(struct drawable *dw, unsigned int ticks) 42 my_update_false(struct mlk_drawable *dw, unsigned int ticks)
43 { 43 {
44 (void)ticks; 44 (void)ticks;
45 45
46 ((struct invokes *)dw->data)->update = 1; 46 ((struct invokes *)dw->data)->update = 1;
47 47
48 return 0; 48 return 0;
49 } 49 }
50 50
51 static int 51 static int
52 my_update_true(struct drawable *dw, unsigned int ticks) 52 my_update_true(struct mlk_drawable *dw, unsigned int ticks)
53 { 53 {
54 (void)ticks; 54 (void)ticks;
55 55
56 ((struct invokes *)dw->data)->update = 1; 56 ((struct invokes *)dw->data)->update = 1;
57 57
58 return 1; 58 return 1;
59 } 59 }
60 60
61 static void 61 static void
62 my_draw(struct drawable *dw) 62 my_draw(struct mlk_drawable *dw)
63 { 63 {
64 ((struct invokes *)dw->data)->draw = 1; 64 ((struct invokes *)dw->data)->draw = 1;
65 } 65 }
66 66
67 static void 67 static void
68 my_end(struct drawable *dw) 68 my_end(struct mlk_drawable *dw)
69 { 69 {
70 ((struct invokes *)dw->data)->end = 1; 70 ((struct invokes *)dw->data)->end = 1;
71 } 71 }
72 72
73 static void 73 static void
74 my_finish(struct drawable *dw) 74 my_finish(struct mlk_drawable *dw)
75 { 75 {
76 ((struct invokes *)dw->data)->finish = 1; 76 ((struct invokes *)dw->data)->finish = 1;
77 } 77 }
78 78
79 static void 79 static void
80 test_basics_update(void) 80 test_basics_update(void)
81 { 81 {
82 struct { 82 struct {
83 struct invokes inv; 83 struct invokes inv;
84 struct drawable dw; 84 struct mlk_drawable dw;
85 } table[] = { 85 } table[] = {
86 { .dw = INIT(&table[0], my_update_true) }, 86 { .dw = INIT(&table[0], my_update_true) },
87 { .dw = INIT(&table[1], my_update_false) } 87 { .dw = INIT(&table[1], my_update_false) }
88 }; 88 };
89 89
90 /* True version. */ 90 /* True version. */
91 DT_ASSERT(drawable_update(&table[0].dw, 0)); 91 DT_ASSERT(mlk_drawable_update(&table[0].dw, 0));
92 DT_ASSERT(table[0].inv.update); 92 DT_ASSERT(table[0].inv.update);
93 DT_ASSERT(!table[0].inv.draw); 93 DT_ASSERT(!table[0].inv.draw);
94 DT_ASSERT(!table[0].inv.end); 94 DT_ASSERT(!table[0].inv.end);
95 DT_ASSERT(!table[0].inv.finish); 95 DT_ASSERT(!table[0].inv.finish);
96 96
97 /* False version. */ 97 /* False version. */
98 DT_ASSERT(!drawable_update(&table[1].dw, 0)); 98 DT_ASSERT(!mlk_drawable_update(&table[1].dw, 0));
99 DT_ASSERT(table[1].inv.update); 99 DT_ASSERT(table[1].inv.update);
100 DT_ASSERT(!table[1].inv.draw); 100 DT_ASSERT(!table[1].inv.draw);
101 DT_ASSERT(!table[1].inv.end); 101 DT_ASSERT(!table[1].inv.end);
102 DT_ASSERT(!table[1].inv.finish); 102 DT_ASSERT(!table[1].inv.finish);
103 } 103 }
104 104
105 static void 105 static void
106 test_basics_draw(void) 106 test_basics_draw(void)
107 { 107 {
108 struct invokes inv = {0}; 108 struct invokes inv = {0};
109 struct drawable dw = INIT(&inv, my_update_true); 109 struct mlk_drawable dw = INIT(&inv, my_update_true);
110 110
111 drawable_draw(&dw); 111 mlk_drawable_draw(&dw);
112 112
113 DT_ASSERT(!inv.update); 113 DT_ASSERT(!inv.update);
114 DT_ASSERT(inv.draw); 114 DT_ASSERT(inv.draw);
115 DT_ASSERT(!inv.end); 115 DT_ASSERT(!inv.end);
116 DT_ASSERT(!inv.finish); 116 DT_ASSERT(!inv.finish);
118 118
119 static void 119 static void
120 test_basics_end(void) 120 test_basics_end(void)
121 { 121 {
122 struct invokes inv = {0}; 122 struct invokes inv = {0};
123 struct drawable dw = INIT(&inv, my_update_true); 123 struct mlk_drawable dw = INIT(&inv, my_update_true);
124 124
125 drawable_end(&dw); 125 mlk_drawable_end(&dw);
126 126
127 DT_ASSERT(!inv.update); 127 DT_ASSERT(!inv.update);
128 DT_ASSERT(!inv.draw); 128 DT_ASSERT(!inv.draw);
129 DT_ASSERT(inv.end); 129 DT_ASSERT(inv.end);
130 DT_ASSERT(!inv.finish); 130 DT_ASSERT(!inv.finish);
132 132
133 static void 133 static void
134 test_basics_finish(void) 134 test_basics_finish(void)
135 { 135 {
136 struct invokes inv = {0}; 136 struct invokes inv = {0};
137 struct drawable dw = INIT(&inv, my_update_true); 137 struct mlk_drawable dw = INIT(&inv, my_update_true);
138 138
139 drawable_finish(&dw); 139 mlk_drawable_finish(&dw);
140 140
141 DT_ASSERT(!inv.update); 141 DT_ASSERT(!inv.update);
142 DT_ASSERT(!inv.draw); 142 DT_ASSERT(!inv.draw);
143 DT_ASSERT(!inv.end); 143 DT_ASSERT(!inv.end);
144 DT_ASSERT(inv.finish); 144 DT_ASSERT(inv.finish);
145 } 145 }
146 146
147 static void 147 static void
148 test_stack_add(void) 148 test_stack_add(void)
149 { 149 {
150 struct drawable *drawables[10]; 150 struct mlk_drawable *drawables[10];
151 struct drawable_stack st = {0}; 151 struct mlk_drawable_stack st = {0};
152 struct drawable dw = {0}; 152 struct mlk_drawable dw = {0};
153 153
154 drawable_stack_init(&st, drawables, 10); 154 mlk_drawable_stack_init(&st, drawables, 10);
155 155
156 DT_EQ_INT(drawable_stack_add(&st, &dw), 0); 156 DT_EQ_INT(mlk_drawable_stack_add(&st, &dw), 0);
157 157
158 /* Now fill up. */ 158 /* Now fill up. */
159 for (int i = 0; i < 9; ++i) 159 for (int i = 0; i < 9; ++i)
160 DT_EQ_INT(drawable_stack_add(&st, &dw), 0); 160 DT_EQ_INT(mlk_drawable_stack_add(&st, &dw), 0);
161 161
162 /* This one should not fit in. */ 162 /* This one should not fit in. */
163 DT_EQ_INT(drawable_stack_add(&st, &dw), MLK_ERR_NO_MEM); 163 DT_EQ_INT(mlk_drawable_stack_add(&st, &dw), MLK_ERR_NO_MEM);
164 } 164 }
165 165
166 static void 166 static void
167 test_stack_update(void) 167 test_stack_update(void)
168 { 168 {
169 struct { 169 struct {
170 struct invokes inv; 170 struct invokes inv;
171 struct drawable dw; 171 struct mlk_drawable dw;
172 } table[] = { 172 } table[] = {
173 { .dw = INIT(&table[0], my_update_false) }, 173 { .dw = INIT(&table[0], my_update_false) },
174 { .dw = INIT(&table[1], my_update_true) }, 174 { .dw = INIT(&table[1], my_update_true) },
175 { .dw = INIT(&table[2], my_update_false) }, 175 { .dw = INIT(&table[2], my_update_false) },
176 { .dw = INIT(&table[3], my_update_false) }, 176 { .dw = INIT(&table[3], my_update_false) },
177 { .dw = INIT(&table[4], my_update_true) }, 177 { .dw = INIT(&table[4], my_update_true) },
178 { .dw = INIT(&table[5], my_update_true) }, 178 { .dw = INIT(&table[5], my_update_true) },
179 { .dw = INIT(&table[6], my_update_false) }, 179 { .dw = INIT(&table[6], my_update_false) },
180 }; 180 };
181 181
182 struct drawable *drawables[10]; 182 struct mlk_drawable *drawables[10];
183 struct drawable_stack st = {0}; 183 struct mlk_drawable_stack st = {0};
184 184
185 drawable_stack_init(&st, drawables, 10); 185 mlk_drawable_stack_init(&st, drawables, 10);
186 drawable_stack_add(&st, &table[0].dw); 186 mlk_drawable_stack_add(&st, &table[0].dw);
187 drawable_stack_add(&st, &table[1].dw); 187 mlk_drawable_stack_add(&st, &table[1].dw);
188 drawable_stack_add(&st, &table[2].dw); 188 mlk_drawable_stack_add(&st, &table[2].dw);
189 drawable_stack_add(&st, &table[3].dw); 189 mlk_drawable_stack_add(&st, &table[3].dw);
190 drawable_stack_add(&st, &table[4].dw); 190 mlk_drawable_stack_add(&st, &table[4].dw);
191 drawable_stack_add(&st, &table[5].dw); 191 mlk_drawable_stack_add(&st, &table[5].dw);
192 drawable_stack_add(&st, &table[6].dw); 192 mlk_drawable_stack_add(&st, &table[6].dw);
193 193
194 DT_ASSERT(!drawable_stack_update(&st, 0)); 194 DT_ASSERT(!mlk_drawable_stack_update(&st, 0));
195 195
196 DT_ASSERT(table[0].inv.update); 196 DT_ASSERT(table[0].inv.update);
197 DT_ASSERT(table[1].inv.update); 197 DT_ASSERT(table[1].inv.update);
198 DT_ASSERT(table[2].inv.update); 198 DT_ASSERT(table[2].inv.update);
199 DT_ASSERT(table[3].inv.update); 199 DT_ASSERT(table[3].inv.update);
242 table[0].dw.update = 242 table[0].dw.update =
243 table[2].dw.update = 243 table[2].dw.update =
244 table[3].dw.update = 244 table[3].dw.update =
245 table[6].dw.update = my_update_true; 245 table[6].dw.update = my_update_true;
246 246
247 DT_ASSERT(drawable_stack_update(&st, 0)); 247 DT_ASSERT(mlk_drawable_stack_update(&st, 0));
248 DT_EQ_PTR(st.objects[0], NULL); 248 DT_EQ_PTR(st.objects[0], NULL);
249 DT_EQ_PTR(st.objects[1], NULL); 249 DT_EQ_PTR(st.objects[1], NULL);
250 DT_EQ_PTR(st.objects[2], NULL); 250 DT_EQ_PTR(st.objects[2], NULL);
251 DT_EQ_PTR(st.objects[3], NULL); 251 DT_EQ_PTR(st.objects[3], NULL);
252 DT_EQ_PTR(st.objects[4], NULL); 252 DT_EQ_PTR(st.objects[4], NULL);
257 static void 257 static void
258 test_stack_draw(void) 258 test_stack_draw(void)
259 { 259 {
260 struct { 260 struct {
261 struct invokes inv; 261 struct invokes inv;
262 struct drawable dw; 262 struct mlk_drawable dw;
263 } table[] = { 263 } table[] = {
264 { .dw = INIT(&table[0], my_update_false) }, 264 { .dw = INIT(&table[0], my_update_false) },
265 { .dw = INIT(&table[1], my_update_true) }, 265 { .dw = INIT(&table[1], my_update_true) },
266 { .dw = INIT(&table[2], my_update_false) }, 266 { .dw = INIT(&table[2], my_update_false) },
267 { .dw = INIT(&table[3], my_update_false) }, 267 { .dw = INIT(&table[3], my_update_false) },
268 { .dw = INIT(&table[4], my_update_true) }, 268 { .dw = INIT(&table[4], my_update_true) },
269 { .dw = INIT(&table[5], my_update_true) }, 269 { .dw = INIT(&table[5], my_update_true) },
270 { .dw = INIT(&table[6], my_update_false) }, 270 { .dw = INIT(&table[6], my_update_false) },
271 }; 271 };
272 272
273 struct drawable *drawables[10]; 273 struct mlk_drawable *drawables[10];
274 struct drawable_stack st = {0}; 274 struct mlk_drawable_stack st = {0};
275 275
276 drawable_stack_init(&st, drawables, 10); 276 mlk_drawable_stack_init(&st, drawables, 10);
277 drawable_stack_add(&st, &table[0].dw); 277 mlk_drawable_stack_add(&st, &table[0].dw);
278 drawable_stack_add(&st, &table[1].dw); 278 mlk_drawable_stack_add(&st, &table[1].dw);
279 drawable_stack_add(&st, &table[2].dw); 279 mlk_drawable_stack_add(&st, &table[2].dw);
280 drawable_stack_add(&st, &table[3].dw); 280 mlk_drawable_stack_add(&st, &table[3].dw);
281 drawable_stack_add(&st, &table[4].dw); 281 mlk_drawable_stack_add(&st, &table[4].dw);
282 drawable_stack_add(&st, &table[5].dw); 282 mlk_drawable_stack_add(&st, &table[5].dw);
283 drawable_stack_add(&st, &table[6].dw); 283 mlk_drawable_stack_add(&st, &table[6].dw);
284 drawable_stack_draw(&st); 284 mlk_drawable_stack_draw(&st);
285 285
286 DT_ASSERT(!table[0].inv.update); 286 DT_ASSERT(!table[0].inv.update);
287 DT_ASSERT(!table[1].inv.update); 287 DT_ASSERT(!table[1].inv.update);
288 DT_ASSERT(!table[2].inv.update); 288 DT_ASSERT(!table[2].inv.update);
289 DT_ASSERT(!table[3].inv.update); 289 DT_ASSERT(!table[3].inv.update);
319 static void 319 static void
320 test_stack_finish(void) 320 test_stack_finish(void)
321 { 321 {
322 struct { 322 struct {
323 struct invokes inv; 323 struct invokes inv;
324 struct drawable dw; 324 struct mlk_drawable dw;
325 } table[] = { 325 } table[] = {
326 { .dw = INIT(&table[0], my_update_true) }, 326 { .dw = INIT(&table[0], my_update_true) },
327 { .dw = INIT(&table[0], my_update_false) }, 327 { .dw = INIT(&table[0], my_update_false) },
328 }; 328 };
329 329
330 struct drawable *drawables[10]; 330 struct mlk_drawable *drawables[10];
331 struct drawable_stack st = {0}; 331 struct mlk_drawable_stack st = {0};
332 332
333 drawable_stack_init(&st, drawables, 10); 333 mlk_drawable_stack_init(&st, drawables, 10);
334 drawable_stack_add(&st, &table[0].dw); 334 mlk_drawable_stack_add(&st, &table[0].dw);
335 drawable_stack_add(&st, &table[1].dw); 335 mlk_drawable_stack_add(&st, &table[1].dw);
336 drawable_stack_finish(&st); 336 mlk_drawable_stack_finish(&st);
337 337
338 DT_ASSERT(!table[0].inv.update); 338 DT_ASSERT(!table[0].inv.update);
339 DT_ASSERT(!table[0].inv.draw); 339 DT_ASSERT(!table[0].inv.draw);
340 DT_ASSERT(table[0].inv.end); 340 DT_ASSERT(table[0].inv.end);
341 DT_ASSERT(table[0].inv.finish); 341 DT_ASSERT(table[0].inv.finish);