1 | /*
|
---|
2 | * Copyright (c) 2021 Jiri Svoboda
|
---|
3 | * All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | *
|
---|
9 | * - Redistributions of source code must retain the above copyright
|
---|
10 | * notice, this list of conditions and the following disclaimer.
|
---|
11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer in the
|
---|
13 | * documentation and/or other materials provided with the distribution.
|
---|
14 | * - The name of the author may not be used to endorse or promote products
|
---|
15 | * derived from this software without specific prior written permission.
|
---|
16 | *
|
---|
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
27 | */
|
---|
28 |
|
---|
29 | #include <gfx/context.h>
|
---|
30 | #include <gfx/coord.h>
|
---|
31 | #include <mem.h>
|
---|
32 | #include <pcut/pcut.h>
|
---|
33 | #include <stdbool.h>
|
---|
34 | #include <ui/pbutton.h>
|
---|
35 | #include <ui/resource.h>
|
---|
36 | #include <ui/wdecor.h>
|
---|
37 | #include "../private/wdecor.h"
|
---|
38 |
|
---|
39 | PCUT_INIT;
|
---|
40 |
|
---|
41 | PCUT_TEST_SUITE(wdecor);
|
---|
42 |
|
---|
43 | static errno_t testgc_set_color(void *, gfx_color_t *);
|
---|
44 | static errno_t testgc_fill_rect(void *, gfx_rect_t *);
|
---|
45 | static errno_t testgc_update(void *);
|
---|
46 | static errno_t testgc_bitmap_create(void *, gfx_bitmap_params_t *,
|
---|
47 | gfx_bitmap_alloc_t *, void **);
|
---|
48 | static errno_t testgc_bitmap_destroy(void *);
|
---|
49 | static errno_t testgc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *);
|
---|
50 | static errno_t testgc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *);
|
---|
51 |
|
---|
52 | static gfx_context_ops_t ops = {
|
---|
53 | .set_color = testgc_set_color,
|
---|
54 | .fill_rect = testgc_fill_rect,
|
---|
55 | .update = testgc_update,
|
---|
56 | .bitmap_create = testgc_bitmap_create,
|
---|
57 | .bitmap_destroy = testgc_bitmap_destroy,
|
---|
58 | .bitmap_render = testgc_bitmap_render,
|
---|
59 | .bitmap_get_alloc = testgc_bitmap_get_alloc
|
---|
60 | };
|
---|
61 |
|
---|
62 | static void test_wdecor_close(ui_wdecor_t *, void *);
|
---|
63 | static void test_wdecor_move(ui_wdecor_t *, void *, gfx_coord2_t *);
|
---|
64 | static void test_wdecor_resize(ui_wdecor_t *, void *, ui_wdecor_rsztype_t,
|
---|
65 | gfx_coord2_t *);
|
---|
66 | static void test_wdecor_set_cursor(ui_wdecor_t *, void *, ui_stock_cursor_t);
|
---|
67 |
|
---|
68 | static ui_wdecor_cb_t test_wdecor_cb = {
|
---|
69 | .close = test_wdecor_close,
|
---|
70 | .move = test_wdecor_move,
|
---|
71 | .resize = test_wdecor_resize,
|
---|
72 | .set_cursor = test_wdecor_set_cursor
|
---|
73 | };
|
---|
74 |
|
---|
75 | static ui_wdecor_cb_t dummy_wdecor_cb = {
|
---|
76 | };
|
---|
77 |
|
---|
78 | typedef struct {
|
---|
79 | bool bm_created;
|
---|
80 | bool bm_destroyed;
|
---|
81 | gfx_bitmap_params_t bm_params;
|
---|
82 | void *bm_pixels;
|
---|
83 | gfx_rect_t bm_srect;
|
---|
84 | gfx_coord2_t bm_offs;
|
---|
85 | bool bm_rendered;
|
---|
86 | bool bm_got_alloc;
|
---|
87 | } test_gc_t;
|
---|
88 |
|
---|
89 | typedef struct {
|
---|
90 | test_gc_t *tgc;
|
---|
91 | gfx_bitmap_alloc_t alloc;
|
---|
92 | bool myalloc;
|
---|
93 | } testgc_bitmap_t;
|
---|
94 |
|
---|
95 | typedef struct {
|
---|
96 | bool close;
|
---|
97 | bool move;
|
---|
98 | gfx_coord2_t pos;
|
---|
99 | bool resize;
|
---|
100 | ui_wdecor_rsztype_t rsztype;
|
---|
101 | bool set_cursor;
|
---|
102 | ui_stock_cursor_t cursor;
|
---|
103 | } test_cb_resp_t;
|
---|
104 |
|
---|
105 | /** Create and destroy button */
|
---|
106 | PCUT_TEST(create_destroy)
|
---|
107 | {
|
---|
108 | ui_wdecor_t *wdecor = NULL;
|
---|
109 | errno_t rc;
|
---|
110 |
|
---|
111 | rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
|
---|
112 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
113 | PCUT_ASSERT_NOT_NULL(wdecor);
|
---|
114 |
|
---|
115 | ui_wdecor_destroy(wdecor);
|
---|
116 | }
|
---|
117 |
|
---|
118 | /** ui_wdecor_destroy() can take NULL argument (no-op) */
|
---|
119 | PCUT_TEST(destroy_null)
|
---|
120 | {
|
---|
121 | ui_wdecor_destroy(NULL);
|
---|
122 | }
|
---|
123 |
|
---|
124 | /** Set window decoration rectangle sets internal field */
|
---|
125 | PCUT_TEST(set_rect)
|
---|
126 | {
|
---|
127 | ui_wdecor_t *wdecor;
|
---|
128 | gfx_rect_t rect;
|
---|
129 | errno_t rc;
|
---|
130 |
|
---|
131 | rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
|
---|
132 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
133 |
|
---|
134 | rect.p0.x = 1;
|
---|
135 | rect.p0.y = 2;
|
---|
136 | rect.p1.x = 3;
|
---|
137 | rect.p1.y = 4;
|
---|
138 |
|
---|
139 | ui_wdecor_set_rect(wdecor, &rect);
|
---|
140 | PCUT_ASSERT_INT_EQUALS(rect.p0.x, wdecor->rect.p0.x);
|
---|
141 | PCUT_ASSERT_INT_EQUALS(rect.p0.y, wdecor->rect.p0.y);
|
---|
142 | PCUT_ASSERT_INT_EQUALS(rect.p1.x, wdecor->rect.p1.x);
|
---|
143 | PCUT_ASSERT_INT_EQUALS(rect.p1.y, wdecor->rect.p1.y);
|
---|
144 |
|
---|
145 | ui_wdecor_destroy(wdecor);
|
---|
146 | }
|
---|
147 |
|
---|
148 | /** Set window decoration active sets internal field */
|
---|
149 | PCUT_TEST(set_active)
|
---|
150 | {
|
---|
151 | ui_wdecor_t *wdecor;
|
---|
152 | errno_t rc;
|
---|
153 |
|
---|
154 | rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
|
---|
155 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
156 |
|
---|
157 | PCUT_ASSERT_TRUE(wdecor->active);
|
---|
158 |
|
---|
159 | ui_wdecor_set_active(wdecor, false);
|
---|
160 | PCUT_ASSERT_FALSE(wdecor->active);
|
---|
161 |
|
---|
162 | ui_wdecor_set_active(wdecor, true);
|
---|
163 | PCUT_ASSERT_TRUE(wdecor->active);
|
---|
164 |
|
---|
165 | ui_wdecor_destroy(wdecor);
|
---|
166 | }
|
---|
167 |
|
---|
168 | /** Paint button */
|
---|
169 | PCUT_TEST(paint)
|
---|
170 | {
|
---|
171 | errno_t rc;
|
---|
172 | gfx_context_t *gc = NULL;
|
---|
173 | test_gc_t tgc;
|
---|
174 | ui_resource_t *resource = NULL;
|
---|
175 | ui_wdecor_t *wdecor;
|
---|
176 |
|
---|
177 | memset(&tgc, 0, sizeof(tgc));
|
---|
178 | rc = gfx_context_new(&ops, &tgc, &gc);
|
---|
179 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
180 |
|
---|
181 | rc = ui_resource_create(gc, false, &resource);
|
---|
182 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
183 | PCUT_ASSERT_NOT_NULL(resource);
|
---|
184 |
|
---|
185 | rc = ui_wdecor_create(resource, "Hello", ui_wds_none, &wdecor);
|
---|
186 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
187 |
|
---|
188 | rc = ui_wdecor_paint(wdecor);
|
---|
189 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
190 |
|
---|
191 | ui_wdecor_destroy(wdecor);
|
---|
192 | ui_resource_destroy(resource);
|
---|
193 |
|
---|
194 | rc = gfx_context_delete(gc);
|
---|
195 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
196 | }
|
---|
197 |
|
---|
198 | /** Test ui_wdecor_close() */
|
---|
199 | PCUT_TEST(close)
|
---|
200 | {
|
---|
201 | errno_t rc;
|
---|
202 | ui_wdecor_t *wdecor;
|
---|
203 | test_cb_resp_t resp;
|
---|
204 |
|
---|
205 | rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
|
---|
206 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
207 |
|
---|
208 | /* Close callback with no callbacks set */
|
---|
209 | ui_wdecor_close(wdecor);
|
---|
210 |
|
---|
211 | /* Close callback with close callback not implemented */
|
---|
212 | ui_wdecor_set_cb(wdecor, &dummy_wdecor_cb, NULL);
|
---|
213 | ui_wdecor_close(wdecor);
|
---|
214 |
|
---|
215 | /* Close callback with real callback set */
|
---|
216 | resp.close = false;
|
---|
217 | ui_wdecor_set_cb(wdecor, &test_wdecor_cb, &resp);
|
---|
218 | ui_wdecor_close(wdecor);
|
---|
219 | PCUT_ASSERT_TRUE(resp.close);
|
---|
220 |
|
---|
221 | ui_wdecor_destroy(wdecor);
|
---|
222 | }
|
---|
223 |
|
---|
224 | /** Test ui_wdecor_move() */
|
---|
225 | PCUT_TEST(move)
|
---|
226 | {
|
---|
227 | errno_t rc;
|
---|
228 | ui_wdecor_t *wdecor;
|
---|
229 | test_cb_resp_t resp;
|
---|
230 | gfx_coord2_t pos;
|
---|
231 |
|
---|
232 | rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
|
---|
233 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
234 |
|
---|
235 | pos.x = 3;
|
---|
236 | pos.y = 4;
|
---|
237 |
|
---|
238 | /* Move callback with no callbacks set */
|
---|
239 | ui_wdecor_move(wdecor, &pos);
|
---|
240 |
|
---|
241 | /* Move callback with move callback not implemented */
|
---|
242 | ui_wdecor_set_cb(wdecor, &dummy_wdecor_cb, NULL);
|
---|
243 | ui_wdecor_move(wdecor, &pos);
|
---|
244 |
|
---|
245 | /* Move callback with real callback set */
|
---|
246 | resp.move = false;
|
---|
247 | resp.pos.x = 0;
|
---|
248 | resp.pos.y = 0;
|
---|
249 | ui_wdecor_set_cb(wdecor, &test_wdecor_cb, &resp);
|
---|
250 | ui_wdecor_move(wdecor, &pos);
|
---|
251 | PCUT_ASSERT_TRUE(resp.move);
|
---|
252 | PCUT_ASSERT_INT_EQUALS(pos.x, resp.pos.x);
|
---|
253 | PCUT_ASSERT_INT_EQUALS(pos.y, resp.pos.y);
|
---|
254 |
|
---|
255 | ui_wdecor_destroy(wdecor);
|
---|
256 | }
|
---|
257 |
|
---|
258 | /** Test ui_wdecor_resize() */
|
---|
259 | PCUT_TEST(resize)
|
---|
260 | {
|
---|
261 | errno_t rc;
|
---|
262 | ui_wdecor_t *wdecor;
|
---|
263 | test_cb_resp_t resp;
|
---|
264 | ui_wdecor_rsztype_t rsztype;
|
---|
265 | gfx_coord2_t pos;
|
---|
266 |
|
---|
267 | rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
|
---|
268 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
269 |
|
---|
270 | rsztype = ui_wr_bottom;
|
---|
271 | pos.x = 3;
|
---|
272 | pos.y = 4;
|
---|
273 |
|
---|
274 | /* Resize callback with no callbacks set */
|
---|
275 | ui_wdecor_resize(wdecor, rsztype, &pos);
|
---|
276 |
|
---|
277 | /* Resize callback with move callback not implemented */
|
---|
278 | ui_wdecor_set_cb(wdecor, &dummy_wdecor_cb, NULL);
|
---|
279 | ui_wdecor_resize(wdecor, rsztype, &pos);
|
---|
280 |
|
---|
281 | /* Resize callback with real callback set */
|
---|
282 | resp.resize = false;
|
---|
283 | resp.rsztype = ui_wr_none;
|
---|
284 | resp.pos.x = 0;
|
---|
285 | resp.pos.y = 0;
|
---|
286 | ui_wdecor_set_cb(wdecor, &test_wdecor_cb, &resp);
|
---|
287 | ui_wdecor_resize(wdecor, rsztype, &pos);
|
---|
288 | PCUT_ASSERT_TRUE(resp.resize);
|
---|
289 | PCUT_ASSERT_INT_EQUALS(rsztype, resp.rsztype);
|
---|
290 | PCUT_ASSERT_INT_EQUALS(pos.x, resp.pos.x);
|
---|
291 | PCUT_ASSERT_INT_EQUALS(pos.y, resp.pos.y);
|
---|
292 |
|
---|
293 | ui_wdecor_destroy(wdecor);
|
---|
294 | }
|
---|
295 |
|
---|
296 | /** Test ui_wdecor_set_cursor() */
|
---|
297 | PCUT_TEST(set_cursor)
|
---|
298 | {
|
---|
299 | errno_t rc;
|
---|
300 | ui_wdecor_t *wdecor;
|
---|
301 | test_cb_resp_t resp;
|
---|
302 | ui_stock_cursor_t cursor;
|
---|
303 |
|
---|
304 | rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
|
---|
305 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
306 |
|
---|
307 | cursor = ui_curs_size_uldr;
|
---|
308 |
|
---|
309 | /* Set cursor callback with no callbacks set */
|
---|
310 | ui_wdecor_set_cursor(wdecor, cursor);
|
---|
311 |
|
---|
312 | /* Set cursor callback with move callback not implemented */
|
---|
313 | ui_wdecor_set_cb(wdecor, &dummy_wdecor_cb, NULL);
|
---|
314 | ui_wdecor_set_cursor(wdecor, cursor);
|
---|
315 |
|
---|
316 | /* Set cursor callback with real callback set */
|
---|
317 | resp.set_cursor = false;
|
---|
318 | resp.cursor = ui_curs_arrow;
|
---|
319 | ui_wdecor_set_cb(wdecor, &test_wdecor_cb, &resp);
|
---|
320 | ui_wdecor_set_cursor(wdecor, cursor);
|
---|
321 | PCUT_ASSERT_TRUE(resp.set_cursor);
|
---|
322 | PCUT_ASSERT_INT_EQUALS(cursor, resp.cursor);
|
---|
323 |
|
---|
324 | ui_wdecor_destroy(wdecor);
|
---|
325 | }
|
---|
326 |
|
---|
327 | /** Clicking the close button generates close callback */
|
---|
328 | PCUT_TEST(close_btn_clicked)
|
---|
329 | {
|
---|
330 | ui_wdecor_t *wdecor;
|
---|
331 | gfx_rect_t rect;
|
---|
332 | test_cb_resp_t resp;
|
---|
333 | errno_t rc;
|
---|
334 |
|
---|
335 | rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
|
---|
336 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
337 |
|
---|
338 | rect.p0.x = 10;
|
---|
339 | rect.p0.y = 20;
|
---|
340 | rect.p1.x = 100;
|
---|
341 | rect.p1.y = 200;
|
---|
342 |
|
---|
343 | ui_wdecor_set_rect(wdecor, &rect);
|
---|
344 |
|
---|
345 | ui_wdecor_set_cb(wdecor, &test_wdecor_cb, (void *) &resp);
|
---|
346 |
|
---|
347 | resp.close = false;
|
---|
348 |
|
---|
349 | ui_pbutton_clicked(wdecor->btn_close);
|
---|
350 | PCUT_ASSERT_TRUE(resp.close);
|
---|
351 |
|
---|
352 | ui_wdecor_destroy(wdecor);
|
---|
353 | }
|
---|
354 |
|
---|
355 | /** Button press on title bar generates move callback */
|
---|
356 | PCUT_TEST(pos_event_move)
|
---|
357 | {
|
---|
358 | errno_t rc;
|
---|
359 | gfx_rect_t rect;
|
---|
360 | pos_event_t event;
|
---|
361 | gfx_context_t *gc = NULL;
|
---|
362 | test_gc_t tgc;
|
---|
363 | test_cb_resp_t resp;
|
---|
364 | ui_resource_t *resource = NULL;
|
---|
365 | ui_wdecor_t *wdecor;
|
---|
366 |
|
---|
367 | memset(&tgc, 0, sizeof(tgc));
|
---|
368 | rc = gfx_context_new(&ops, &tgc, &gc);
|
---|
369 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
370 |
|
---|
371 | rc = ui_resource_create(gc, false, &resource);
|
---|
372 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
373 | PCUT_ASSERT_NOT_NULL(resource);
|
---|
374 |
|
---|
375 | rc = ui_wdecor_create(resource, "Hello", ui_wds_decorated, &wdecor);
|
---|
376 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
377 |
|
---|
378 | rect.p0.x = 10;
|
---|
379 | rect.p0.y = 20;
|
---|
380 | rect.p1.x = 100;
|
---|
381 | rect.p1.y = 200;
|
---|
382 |
|
---|
383 | ui_wdecor_set_rect(wdecor, &rect);
|
---|
384 |
|
---|
385 | ui_wdecor_set_cb(wdecor, &test_wdecor_cb, (void *) &resp);
|
---|
386 |
|
---|
387 | resp.move = false;
|
---|
388 | resp.pos.x = 0;
|
---|
389 | resp.pos.y = 0;
|
---|
390 |
|
---|
391 | event.type = POS_PRESS;
|
---|
392 | event.hpos = 50;
|
---|
393 | event.vpos = 25;
|
---|
394 | ui_wdecor_pos_event(wdecor, &event);
|
---|
395 |
|
---|
396 | PCUT_ASSERT_TRUE(resp.move);
|
---|
397 | PCUT_ASSERT_INT_EQUALS(event.hpos, resp.pos.x);
|
---|
398 | PCUT_ASSERT_INT_EQUALS(event.vpos, resp.pos.y);
|
---|
399 |
|
---|
400 | ui_wdecor_destroy(wdecor);
|
---|
401 | ui_resource_destroy(resource);
|
---|
402 |
|
---|
403 | rc = gfx_context_delete(gc);
|
---|
404 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
405 | }
|
---|
406 |
|
---|
407 | /** ui_wdecor_get_geom() with ui_wds_none produces the correct geometry */
|
---|
408 | PCUT_TEST(get_geom_none)
|
---|
409 | {
|
---|
410 | gfx_context_t *gc = NULL;
|
---|
411 | test_gc_t tgc;
|
---|
412 | ui_resource_t *resource = NULL;
|
---|
413 | ui_wdecor_t *wdecor;
|
---|
414 | gfx_rect_t rect;
|
---|
415 | ui_wdecor_geom_t geom;
|
---|
416 | errno_t rc;
|
---|
417 |
|
---|
418 | memset(&tgc, 0, sizeof(tgc));
|
---|
419 | rc = gfx_context_new(&ops, &tgc, &gc);
|
---|
420 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
421 |
|
---|
422 | rc = ui_resource_create(gc, false, &resource);
|
---|
423 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
424 | PCUT_ASSERT_NOT_NULL(resource);
|
---|
425 |
|
---|
426 | rc = ui_wdecor_create(resource, "Hello", ui_wds_none, &wdecor);
|
---|
427 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
428 |
|
---|
429 | rect.p0.x = 10;
|
---|
430 | rect.p0.y = 20;
|
---|
431 | rect.p1.x = 100;
|
---|
432 | rect.p1.y = 200;
|
---|
433 |
|
---|
434 | ui_wdecor_set_rect(wdecor, &rect);
|
---|
435 | ui_wdecor_get_geom(wdecor, &geom);
|
---|
436 |
|
---|
437 | PCUT_ASSERT_INT_EQUALS(10, geom.interior_rect.p0.x);
|
---|
438 | PCUT_ASSERT_INT_EQUALS(20, geom.interior_rect.p0.y);
|
---|
439 | PCUT_ASSERT_INT_EQUALS(100, geom.interior_rect.p1.x);
|
---|
440 | PCUT_ASSERT_INT_EQUALS(200, geom.interior_rect.p1.y);
|
---|
441 |
|
---|
442 | PCUT_ASSERT_INT_EQUALS(0, geom.title_bar_rect.p0.x);
|
---|
443 | PCUT_ASSERT_INT_EQUALS(0, geom.title_bar_rect.p0.y);
|
---|
444 | PCUT_ASSERT_INT_EQUALS(0, geom.title_bar_rect.p1.x);
|
---|
445 | PCUT_ASSERT_INT_EQUALS(0, geom.title_bar_rect.p1.y);
|
---|
446 |
|
---|
447 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_close_rect.p0.x);
|
---|
448 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_close_rect.p0.y);
|
---|
449 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_close_rect.p1.x);
|
---|
450 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_close_rect.p1.y);
|
---|
451 |
|
---|
452 | PCUT_ASSERT_INT_EQUALS(10, geom.app_area_rect.p0.x);
|
---|
453 | PCUT_ASSERT_INT_EQUALS(20, geom.app_area_rect.p0.y);
|
---|
454 | PCUT_ASSERT_INT_EQUALS(100, geom.app_area_rect.p1.x);
|
---|
455 | PCUT_ASSERT_INT_EQUALS(200, geom.app_area_rect.p1.y);
|
---|
456 |
|
---|
457 | ui_wdecor_destroy(wdecor);
|
---|
458 | ui_resource_destroy(resource);
|
---|
459 |
|
---|
460 | rc = gfx_context_delete(gc);
|
---|
461 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
462 | }
|
---|
463 |
|
---|
464 | /** ui_wdecor_get_geom() with ui_wds_frame produces the correct geometry */
|
---|
465 | PCUT_TEST(get_geom_frame)
|
---|
466 | {
|
---|
467 | gfx_context_t *gc = NULL;
|
---|
468 | test_gc_t tgc;
|
---|
469 | ui_resource_t *resource = NULL;
|
---|
470 | ui_wdecor_t *wdecor;
|
---|
471 | gfx_rect_t rect;
|
---|
472 | ui_wdecor_geom_t geom;
|
---|
473 | errno_t rc;
|
---|
474 |
|
---|
475 | memset(&tgc, 0, sizeof(tgc));
|
---|
476 | rc = gfx_context_new(&ops, &tgc, &gc);
|
---|
477 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
478 |
|
---|
479 | rc = ui_resource_create(gc, false, &resource);
|
---|
480 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
481 | PCUT_ASSERT_NOT_NULL(resource);
|
---|
482 |
|
---|
483 | rc = ui_wdecor_create(resource, "Hello", ui_wds_frame, &wdecor);
|
---|
484 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
485 |
|
---|
486 | rect.p0.x = 10;
|
---|
487 | rect.p0.y = 20;
|
---|
488 | rect.p1.x = 100;
|
---|
489 | rect.p1.y = 200;
|
---|
490 |
|
---|
491 | ui_wdecor_set_rect(wdecor, &rect);
|
---|
492 | ui_wdecor_get_geom(wdecor, &geom);
|
---|
493 |
|
---|
494 | PCUT_ASSERT_INT_EQUALS(14, geom.interior_rect.p0.x);
|
---|
495 | PCUT_ASSERT_INT_EQUALS(24, geom.interior_rect.p0.y);
|
---|
496 | PCUT_ASSERT_INT_EQUALS(96, geom.interior_rect.p1.x);
|
---|
497 | PCUT_ASSERT_INT_EQUALS(196, geom.interior_rect.p1.y);
|
---|
498 |
|
---|
499 | PCUT_ASSERT_INT_EQUALS(0, geom.title_bar_rect.p0.x);
|
---|
500 | PCUT_ASSERT_INT_EQUALS(0, geom.title_bar_rect.p0.y);
|
---|
501 | PCUT_ASSERT_INT_EQUALS(0, geom.title_bar_rect.p1.x);
|
---|
502 | PCUT_ASSERT_INT_EQUALS(0, geom.title_bar_rect.p1.y);
|
---|
503 |
|
---|
504 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_close_rect.p0.x);
|
---|
505 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_close_rect.p0.y);
|
---|
506 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_close_rect.p1.x);
|
---|
507 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_close_rect.p1.y);
|
---|
508 |
|
---|
509 | PCUT_ASSERT_INT_EQUALS(14, geom.app_area_rect.p0.x);
|
---|
510 | PCUT_ASSERT_INT_EQUALS(24, geom.app_area_rect.p0.y);
|
---|
511 | PCUT_ASSERT_INT_EQUALS(96, geom.app_area_rect.p1.x);
|
---|
512 | PCUT_ASSERT_INT_EQUALS(196, geom.app_area_rect.p1.y);
|
---|
513 |
|
---|
514 | ui_wdecor_destroy(wdecor);
|
---|
515 | ui_resource_destroy(resource);
|
---|
516 |
|
---|
517 | rc = gfx_context_delete(gc);
|
---|
518 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
519 | }
|
---|
520 |
|
---|
521 | /** ui_wdecor_get_geom() with ui_wds_frame | ui_wds_titlebar */
|
---|
522 | PCUT_TEST(get_geom_frame_titlebar)
|
---|
523 | {
|
---|
524 | gfx_context_t *gc = NULL;
|
---|
525 | test_gc_t tgc;
|
---|
526 | ui_resource_t *resource = NULL;
|
---|
527 | ui_wdecor_t *wdecor;
|
---|
528 | gfx_rect_t rect;
|
---|
529 | ui_wdecor_geom_t geom;
|
---|
530 | errno_t rc;
|
---|
531 |
|
---|
532 | memset(&tgc, 0, sizeof(tgc));
|
---|
533 | rc = gfx_context_new(&ops, &tgc, &gc);
|
---|
534 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
535 |
|
---|
536 | rc = ui_resource_create(gc, false, &resource);
|
---|
537 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
538 | PCUT_ASSERT_NOT_NULL(resource);
|
---|
539 |
|
---|
540 | rc = ui_wdecor_create(resource, "Hello", ui_wds_frame | ui_wds_titlebar,
|
---|
541 | &wdecor);
|
---|
542 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
543 |
|
---|
544 | rect.p0.x = 10;
|
---|
545 | rect.p0.y = 20;
|
---|
546 | rect.p1.x = 100;
|
---|
547 | rect.p1.y = 200;
|
---|
548 |
|
---|
549 | ui_wdecor_set_rect(wdecor, &rect);
|
---|
550 | ui_wdecor_get_geom(wdecor, &geom);
|
---|
551 |
|
---|
552 | PCUT_ASSERT_INT_EQUALS(14, geom.interior_rect.p0.x);
|
---|
553 | PCUT_ASSERT_INT_EQUALS(24, geom.interior_rect.p0.y);
|
---|
554 | PCUT_ASSERT_INT_EQUALS(96, geom.interior_rect.p1.x);
|
---|
555 | PCUT_ASSERT_INT_EQUALS(196, geom.interior_rect.p1.y);
|
---|
556 |
|
---|
557 | PCUT_ASSERT_INT_EQUALS(14, geom.title_bar_rect.p0.x);
|
---|
558 | PCUT_ASSERT_INT_EQUALS(24, geom.title_bar_rect.p0.y);
|
---|
559 | PCUT_ASSERT_INT_EQUALS(96, geom.title_bar_rect.p1.x);
|
---|
560 | PCUT_ASSERT_INT_EQUALS(46, geom.title_bar_rect.p1.y);
|
---|
561 |
|
---|
562 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_close_rect.p0.x);
|
---|
563 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_close_rect.p0.y);
|
---|
564 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_close_rect.p1.x);
|
---|
565 | PCUT_ASSERT_INT_EQUALS(0, geom.btn_close_rect.p1.y);
|
---|
566 |
|
---|
567 | PCUT_ASSERT_INT_EQUALS(14, geom.app_area_rect.p0.x);
|
---|
568 | PCUT_ASSERT_INT_EQUALS(46, geom.app_area_rect.p0.y);
|
---|
569 | PCUT_ASSERT_INT_EQUALS(96, geom.app_area_rect.p1.x);
|
---|
570 | PCUT_ASSERT_INT_EQUALS(196, geom.app_area_rect.p1.y);
|
---|
571 |
|
---|
572 | ui_wdecor_destroy(wdecor);
|
---|
573 | ui_resource_destroy(resource);
|
---|
574 |
|
---|
575 | rc = gfx_context_delete(gc);
|
---|
576 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
577 | }
|
---|
578 |
|
---|
579 | /** ui_wdecor_get_geom() with ui_wds_decorated produces the correct geometry */
|
---|
580 | PCUT_TEST(get_geom_decorated)
|
---|
581 | {
|
---|
582 | gfx_context_t *gc = NULL;
|
---|
583 | test_gc_t tgc;
|
---|
584 | ui_resource_t *resource = NULL;
|
---|
585 | ui_wdecor_t *wdecor;
|
---|
586 | gfx_rect_t rect;
|
---|
587 | ui_wdecor_geom_t geom;
|
---|
588 | errno_t rc;
|
---|
589 |
|
---|
590 | memset(&tgc, 0, sizeof(tgc));
|
---|
591 | rc = gfx_context_new(&ops, &tgc, &gc);
|
---|
592 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
593 |
|
---|
594 | rc = ui_resource_create(gc, false, &resource);
|
---|
595 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
596 | PCUT_ASSERT_NOT_NULL(resource);
|
---|
597 |
|
---|
598 | rc = ui_wdecor_create(resource, "Hello", ui_wds_decorated, &wdecor);
|
---|
599 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
600 |
|
---|
601 | rect.p0.x = 10;
|
---|
602 | rect.p0.y = 20;
|
---|
603 | rect.p1.x = 100;
|
---|
604 | rect.p1.y = 200;
|
---|
605 |
|
---|
606 | ui_wdecor_set_rect(wdecor, &rect);
|
---|
607 | ui_wdecor_get_geom(wdecor, &geom);
|
---|
608 |
|
---|
609 | PCUT_ASSERT_INT_EQUALS(14, geom.interior_rect.p0.x);
|
---|
610 | PCUT_ASSERT_INT_EQUALS(24, geom.interior_rect.p0.y);
|
---|
611 | PCUT_ASSERT_INT_EQUALS(96, geom.interior_rect.p1.x);
|
---|
612 | PCUT_ASSERT_INT_EQUALS(196, geom.interior_rect.p1.y);
|
---|
613 |
|
---|
614 | PCUT_ASSERT_INT_EQUALS(14, geom.title_bar_rect.p0.x);
|
---|
615 | PCUT_ASSERT_INT_EQUALS(24, geom.title_bar_rect.p0.y);
|
---|
616 | PCUT_ASSERT_INT_EQUALS(96, geom.title_bar_rect.p1.x);
|
---|
617 | PCUT_ASSERT_INT_EQUALS(46, geom.title_bar_rect.p1.y);
|
---|
618 |
|
---|
619 | PCUT_ASSERT_INT_EQUALS(75, geom.btn_close_rect.p0.x);
|
---|
620 | PCUT_ASSERT_INT_EQUALS(25, geom.btn_close_rect.p0.y);
|
---|
621 | PCUT_ASSERT_INT_EQUALS(95, geom.btn_close_rect.p1.x);
|
---|
622 | PCUT_ASSERT_INT_EQUALS(45, geom.btn_close_rect.p1.y);
|
---|
623 |
|
---|
624 | PCUT_ASSERT_INT_EQUALS(14, geom.app_area_rect.p0.x);
|
---|
625 | PCUT_ASSERT_INT_EQUALS(46, geom.app_area_rect.p0.y);
|
---|
626 | PCUT_ASSERT_INT_EQUALS(96, geom.app_area_rect.p1.x);
|
---|
627 | PCUT_ASSERT_INT_EQUALS(196, geom.app_area_rect.p1.y);
|
---|
628 |
|
---|
629 | ui_wdecor_destroy(wdecor);
|
---|
630 | ui_resource_destroy(resource);
|
---|
631 |
|
---|
632 | rc = gfx_context_delete(gc);
|
---|
633 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
634 | }
|
---|
635 |
|
---|
636 | /** ui_wdecor_rect_from_app() correctly converts application to window rect */
|
---|
637 | PCUT_TEST(rect_from_app)
|
---|
638 | {
|
---|
639 | gfx_rect_t arect;
|
---|
640 | gfx_rect_t rect;
|
---|
641 |
|
---|
642 | arect.p0.x = 14;
|
---|
643 | arect.p0.y = 46;
|
---|
644 | arect.p1.x = 96;
|
---|
645 | arect.p1.y = 196;
|
---|
646 |
|
---|
647 | ui_wdecor_rect_from_app(ui_wds_none, &arect, &rect);
|
---|
648 |
|
---|
649 | PCUT_ASSERT_INT_EQUALS(14, rect.p0.x);
|
---|
650 | PCUT_ASSERT_INT_EQUALS(46, rect.p0.y);
|
---|
651 | PCUT_ASSERT_INT_EQUALS(96, rect.p1.x);
|
---|
652 | PCUT_ASSERT_INT_EQUALS(196, rect.p1.y);
|
---|
653 |
|
---|
654 | ui_wdecor_rect_from_app(ui_wds_frame, &arect, &rect);
|
---|
655 |
|
---|
656 | PCUT_ASSERT_INT_EQUALS(10, rect.p0.x);
|
---|
657 | PCUT_ASSERT_INT_EQUALS(42, rect.p0.y);
|
---|
658 | PCUT_ASSERT_INT_EQUALS(100, rect.p1.x);
|
---|
659 | PCUT_ASSERT_INT_EQUALS(200, rect.p1.y);
|
---|
660 |
|
---|
661 | ui_wdecor_rect_from_app(ui_wds_decorated, &arect, &rect);
|
---|
662 |
|
---|
663 | PCUT_ASSERT_INT_EQUALS(10, rect.p0.x);
|
---|
664 | PCUT_ASSERT_INT_EQUALS(20, rect.p0.y);
|
---|
665 | PCUT_ASSERT_INT_EQUALS(100, rect.p1.x);
|
---|
666 | PCUT_ASSERT_INT_EQUALS(200, rect.p1.y);
|
---|
667 |
|
---|
668 | }
|
---|
669 |
|
---|
670 | /** Test ui_wdecor_get_rsztype() */
|
---|
671 | PCUT_TEST(get_rsztype)
|
---|
672 | {
|
---|
673 | ui_wdecor_t *wdecor;
|
---|
674 | gfx_rect_t rect;
|
---|
675 | ui_wdecor_rsztype_t rsztype;
|
---|
676 | gfx_coord2_t pos;
|
---|
677 | errno_t rc;
|
---|
678 |
|
---|
679 | rc = ui_wdecor_create(NULL, "Hello", ui_wds_resizable, &wdecor);
|
---|
680 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
681 |
|
---|
682 | rect.p0.x = 10;
|
---|
683 | rect.p0.y = 20;
|
---|
684 | rect.p1.x = 100;
|
---|
685 | rect.p1.y = 200;
|
---|
686 |
|
---|
687 | ui_wdecor_set_rect(wdecor, &rect);
|
---|
688 |
|
---|
689 | /* Outside of the window */
|
---|
690 | pos.x = 0;
|
---|
691 | pos.y = -1;
|
---|
692 | rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
|
---|
693 | PCUT_ASSERT_EQUALS(ui_wr_none, rsztype);
|
---|
694 |
|
---|
695 | /* Middle of the window */
|
---|
696 | pos.x = 50;
|
---|
697 | pos.y = 100;
|
---|
698 | rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
|
---|
699 | PCUT_ASSERT_EQUALS(ui_wr_none, rsztype);
|
---|
700 |
|
---|
701 | /* Top-left corner, but not on edge */
|
---|
702 | pos.x = 20;
|
---|
703 | pos.y = 30;
|
---|
704 | rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
|
---|
705 | PCUT_ASSERT_EQUALS(ui_wr_none, rsztype);
|
---|
706 |
|
---|
707 | /* Top-left corner on top edge */
|
---|
708 | pos.x = 20;
|
---|
709 | pos.y = 20;
|
---|
710 | rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
|
---|
711 | PCUT_ASSERT_EQUALS(ui_wr_top_left, rsztype);
|
---|
712 |
|
---|
713 | /* Top-left corner on left edge */
|
---|
714 | pos.x = 10;
|
---|
715 | pos.y = 30;
|
---|
716 | rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
|
---|
717 | PCUT_ASSERT_EQUALS(ui_wr_top_left, rsztype);
|
---|
718 |
|
---|
719 | /* Top-right corner on top edge */
|
---|
720 | pos.x = 90;
|
---|
721 | pos.y = 20;
|
---|
722 | rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
|
---|
723 | PCUT_ASSERT_EQUALS(ui_wr_top_right, rsztype);
|
---|
724 |
|
---|
725 | /* Top-right corner on right edge */
|
---|
726 | pos.x = 99;
|
---|
727 | pos.y = 30;
|
---|
728 | rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
|
---|
729 | PCUT_ASSERT_EQUALS(ui_wr_top_right, rsztype);
|
---|
730 |
|
---|
731 | /* Top edge */
|
---|
732 | pos.x = 50;
|
---|
733 | pos.y = 20;
|
---|
734 | rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
|
---|
735 | PCUT_ASSERT_EQUALS(ui_wr_top, rsztype);
|
---|
736 |
|
---|
737 | /* Bottom edge */
|
---|
738 | pos.x = 50;
|
---|
739 | pos.y = 199;
|
---|
740 | rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
|
---|
741 | PCUT_ASSERT_EQUALS(ui_wr_bottom, rsztype);
|
---|
742 |
|
---|
743 | /* Left edge */
|
---|
744 | pos.x = 10;
|
---|
745 | pos.y = 100;
|
---|
746 | rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
|
---|
747 | PCUT_ASSERT_EQUALS(ui_wr_left, rsztype);
|
---|
748 |
|
---|
749 | /* Right edge */
|
---|
750 | pos.x = 99;
|
---|
751 | pos.y = 100;
|
---|
752 | rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
|
---|
753 | PCUT_ASSERT_EQUALS(ui_wr_right, rsztype);
|
---|
754 |
|
---|
755 | ui_wdecor_destroy(wdecor);
|
---|
756 |
|
---|
757 | /* Non-resizable window */
|
---|
758 |
|
---|
759 | rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
|
---|
760 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
761 |
|
---|
762 | rect.p0.x = 10;
|
---|
763 | rect.p0.y = 20;
|
---|
764 | rect.p1.x = 100;
|
---|
765 | rect.p1.y = 200;
|
---|
766 |
|
---|
767 | ui_wdecor_set_rect(wdecor, &rect);
|
---|
768 |
|
---|
769 | pos.x = 10;
|
---|
770 | pos.y = 20;
|
---|
771 | rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
|
---|
772 | PCUT_ASSERT_EQUALS(ui_wr_none, rsztype);
|
---|
773 |
|
---|
774 | ui_wdecor_destroy(wdecor);
|
---|
775 | }
|
---|
776 |
|
---|
777 | /** Test ui_wdecor_cursor_from_rsztype() */
|
---|
778 | PCUT_TEST(cursor_from_rsztype)
|
---|
779 | {
|
---|
780 | PCUT_ASSERT_EQUALS(ui_curs_arrow,
|
---|
781 | ui_wdecor_cursor_from_rsztype(ui_wr_none));
|
---|
782 | PCUT_ASSERT_EQUALS(ui_curs_size_ud,
|
---|
783 | ui_wdecor_cursor_from_rsztype(ui_wr_top));
|
---|
784 | PCUT_ASSERT_EQUALS(ui_curs_size_ud,
|
---|
785 | ui_wdecor_cursor_from_rsztype(ui_wr_bottom));
|
---|
786 | PCUT_ASSERT_EQUALS(ui_curs_size_lr,
|
---|
787 | ui_wdecor_cursor_from_rsztype(ui_wr_left));
|
---|
788 | PCUT_ASSERT_EQUALS(ui_curs_size_lr,
|
---|
789 | ui_wdecor_cursor_from_rsztype(ui_wr_right));
|
---|
790 | PCUT_ASSERT_EQUALS(ui_curs_size_uldr,
|
---|
791 | ui_wdecor_cursor_from_rsztype(ui_wr_top_left));
|
---|
792 | PCUT_ASSERT_EQUALS(ui_curs_size_uldr,
|
---|
793 | ui_wdecor_cursor_from_rsztype(ui_wr_bottom_right));
|
---|
794 | PCUT_ASSERT_EQUALS(ui_curs_size_urdl,
|
---|
795 | ui_wdecor_cursor_from_rsztype(ui_wr_top_right));
|
---|
796 | PCUT_ASSERT_EQUALS(ui_curs_size_urdl,
|
---|
797 | ui_wdecor_cursor_from_rsztype(ui_wr_bottom_left));
|
---|
798 | }
|
---|
799 |
|
---|
800 | /** Test ui_wdecor_frame_pos_event() */
|
---|
801 | PCUT_TEST(frame_pos_event)
|
---|
802 | {
|
---|
803 | ui_wdecor_t *wdecor;
|
---|
804 | gfx_rect_t rect;
|
---|
805 | test_cb_resp_t resp;
|
---|
806 | pos_event_t event;
|
---|
807 | errno_t rc;
|
---|
808 |
|
---|
809 | rc = ui_wdecor_create(NULL, "Hello", ui_wds_resizable, &wdecor);
|
---|
810 | PCUT_ASSERT_ERRNO_VAL(EOK, rc);
|
---|
811 |
|
---|
812 | rect.p0.x = 10;
|
---|
813 | rect.p0.y = 20;
|
---|
814 | rect.p1.x = 100;
|
---|
815 | rect.p1.y = 200;
|
---|
816 |
|
---|
817 | ui_wdecor_set_rect(wdecor, &rect);
|
---|
818 | ui_wdecor_set_cb(wdecor, &test_wdecor_cb, &resp);
|
---|
819 |
|
---|
820 | /* Release on window border should do nothing */
|
---|
821 | resp.resize = false;
|
---|
822 | event.type = POS_RELEASE;
|
---|
823 | event.hpos = 10;
|
---|
824 | event.vpos = 10;
|
---|
825 | ui_wdecor_frame_pos_event(wdecor, &event);
|
---|
826 | PCUT_ASSERT_FALSE(resp.resize);
|
---|
827 |
|
---|
828 | /* Press in the middle of the window should do nothing */
|
---|
829 | resp.resize = false;
|
---|
830 | event.type = POS_PRESS;
|
---|
831 | event.hpos = 50;
|
---|
832 | event.vpos = 100;
|
---|
833 | ui_wdecor_frame_pos_event(wdecor, &event);
|
---|
834 | PCUT_ASSERT_FALSE(resp.resize);
|
---|
835 |
|
---|
836 | /* Press on window border should cause resize to be called */
|
---|
837 | resp.resize = false;
|
---|
838 | event.type = POS_PRESS;
|
---|
839 | event.hpos = 10;
|
---|
840 | event.vpos = 20;
|
---|
841 | ui_wdecor_frame_pos_event(wdecor, &event);
|
---|
842 | PCUT_ASSERT_TRUE(resp.resize);
|
---|
843 |
|
---|
844 | ui_wdecor_destroy(wdecor);
|
---|
845 | }
|
---|
846 |
|
---|
847 | static errno_t testgc_set_color(void *arg, gfx_color_t *color)
|
---|
848 | {
|
---|
849 | (void) arg;
|
---|
850 | (void) color;
|
---|
851 | return EOK;
|
---|
852 | }
|
---|
853 |
|
---|
854 | static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect)
|
---|
855 | {
|
---|
856 | (void) arg;
|
---|
857 | (void) rect;
|
---|
858 | return EOK;
|
---|
859 | }
|
---|
860 |
|
---|
861 | static errno_t testgc_update(void *arg)
|
---|
862 | {
|
---|
863 | (void) arg;
|
---|
864 | return EOK;
|
---|
865 | }
|
---|
866 |
|
---|
867 | static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params,
|
---|
868 | gfx_bitmap_alloc_t *alloc, void **rbm)
|
---|
869 | {
|
---|
870 | test_gc_t *tgc = (test_gc_t *) arg;
|
---|
871 | testgc_bitmap_t *tbm;
|
---|
872 |
|
---|
873 | tbm = calloc(1, sizeof(testgc_bitmap_t));
|
---|
874 | if (tbm == NULL)
|
---|
875 | return ENOMEM;
|
---|
876 |
|
---|
877 | if (alloc == NULL) {
|
---|
878 | tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) *
|
---|
879 | sizeof(uint32_t);
|
---|
880 | tbm->alloc.off0 = 0;
|
---|
881 | tbm->alloc.pixels = calloc(sizeof(uint32_t),
|
---|
882 | (params->rect.p1.x - params->rect.p0.x) *
|
---|
883 | (params->rect.p1.y - params->rect.p0.y));
|
---|
884 | tbm->myalloc = true;
|
---|
885 | if (tbm->alloc.pixels == NULL) {
|
---|
886 | free(tbm);
|
---|
887 | return ENOMEM;
|
---|
888 | }
|
---|
889 | } else {
|
---|
890 | tbm->alloc = *alloc;
|
---|
891 | }
|
---|
892 |
|
---|
893 | tbm->tgc = tgc;
|
---|
894 | tgc->bm_created = true;
|
---|
895 | tgc->bm_params = *params;
|
---|
896 | tgc->bm_pixels = tbm->alloc.pixels;
|
---|
897 | *rbm = (void *)tbm;
|
---|
898 | return EOK;
|
---|
899 | }
|
---|
900 |
|
---|
901 | static errno_t testgc_bitmap_destroy(void *bm)
|
---|
902 | {
|
---|
903 | testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
|
---|
904 | if (tbm->myalloc)
|
---|
905 | free(tbm->alloc.pixels);
|
---|
906 | tbm->tgc->bm_destroyed = true;
|
---|
907 | free(tbm);
|
---|
908 | return EOK;
|
---|
909 | }
|
---|
910 |
|
---|
911 | static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect,
|
---|
912 | gfx_coord2_t *offs)
|
---|
913 | {
|
---|
914 | testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
|
---|
915 | tbm->tgc->bm_rendered = true;
|
---|
916 | tbm->tgc->bm_srect = *srect;
|
---|
917 | tbm->tgc->bm_offs = *offs;
|
---|
918 | return EOK;
|
---|
919 | }
|
---|
920 |
|
---|
921 | static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)
|
---|
922 | {
|
---|
923 | testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
|
---|
924 | *alloc = tbm->alloc;
|
---|
925 | tbm->tgc->bm_got_alloc = true;
|
---|
926 | return EOK;
|
---|
927 | }
|
---|
928 |
|
---|
929 | static void test_wdecor_close(ui_wdecor_t *wdecor, void *arg)
|
---|
930 | {
|
---|
931 | test_cb_resp_t *resp = (test_cb_resp_t *) arg;
|
---|
932 |
|
---|
933 | resp->close = true;
|
---|
934 | }
|
---|
935 |
|
---|
936 | static void test_wdecor_move(ui_wdecor_t *wdecor, void *arg, gfx_coord2_t *pos)
|
---|
937 | {
|
---|
938 | test_cb_resp_t *resp = (test_cb_resp_t *) arg;
|
---|
939 |
|
---|
940 | resp->move = true;
|
---|
941 | resp->pos = *pos;
|
---|
942 | }
|
---|
943 |
|
---|
944 | static void test_wdecor_resize(ui_wdecor_t *wdecor, void *arg,
|
---|
945 | ui_wdecor_rsztype_t rsztype, gfx_coord2_t *pos)
|
---|
946 | {
|
---|
947 | test_cb_resp_t *resp = (test_cb_resp_t *) arg;
|
---|
948 |
|
---|
949 | resp->resize = true;
|
---|
950 | resp->rsztype = rsztype;
|
---|
951 | resp->pos = *pos;
|
---|
952 | }
|
---|
953 |
|
---|
954 | static void test_wdecor_set_cursor(ui_wdecor_t *wdecor, void *arg,
|
---|
955 | ui_stock_cursor_t cursor)
|
---|
956 | {
|
---|
957 | test_cb_resp_t *resp = (test_cb_resp_t *) arg;
|
---|
958 |
|
---|
959 | resp->set_cursor = true;
|
---|
960 | resp->cursor = cursor;
|
---|
961 | }
|
---|
962 |
|
---|
963 | PCUT_EXPORT(wdecor);
|
---|