source: mainline/uspace/lib/ui/test/wdecor.c@ 2d879f7

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 2d879f7 was 2d879f7, checked in by Jiri Svoboda <jiri@…>, 5 years ago

Basic support for window resizing

  • Property mode set to 100644
File size: 18.0 KB
Line 
1/*
2 * Copyright (c) 2020 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
39PCUT_INIT;
40
41PCUT_TEST_SUITE(wdecor);
42
43static errno_t testgc_set_color(void *, gfx_color_t *);
44static errno_t testgc_fill_rect(void *, gfx_rect_t *);
45static errno_t testgc_bitmap_create(void *, gfx_bitmap_params_t *,
46 gfx_bitmap_alloc_t *, void **);
47static errno_t testgc_bitmap_destroy(void *);
48static errno_t testgc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *);
49static errno_t testgc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *);
50
51static gfx_context_ops_t ops = {
52 .set_color = testgc_set_color,
53 .fill_rect = testgc_fill_rect,
54 .bitmap_create = testgc_bitmap_create,
55 .bitmap_destroy = testgc_bitmap_destroy,
56 .bitmap_render = testgc_bitmap_render,
57 .bitmap_get_alloc = testgc_bitmap_get_alloc
58};
59
60static void test_wdecor_close(ui_wdecor_t *, void *);
61static void test_wdecor_move(ui_wdecor_t *, void *, gfx_coord2_t *);
62static void test_wdecor_resize(ui_wdecor_t *, void *, ui_wdecor_rsztype_t,
63 gfx_coord2_t *);
64static void test_wdecor_set_cursor(ui_wdecor_t *, void *, ui_stock_cursor_t);
65
66static ui_wdecor_cb_t test_wdecor_cb = {
67 .close = test_wdecor_close,
68 .move = test_wdecor_move,
69 .resize = test_wdecor_resize,
70 .set_cursor = test_wdecor_set_cursor
71};
72
73static ui_wdecor_cb_t dummy_wdecor_cb = {
74};
75
76typedef struct {
77 bool bm_created;
78 bool bm_destroyed;
79 gfx_bitmap_params_t bm_params;
80 void *bm_pixels;
81 gfx_rect_t bm_srect;
82 gfx_coord2_t bm_offs;
83 bool bm_rendered;
84 bool bm_got_alloc;
85} test_gc_t;
86
87typedef struct {
88 test_gc_t *tgc;
89 gfx_bitmap_alloc_t alloc;
90 bool myalloc;
91} testgc_bitmap_t;
92
93typedef struct {
94 bool close;
95 bool move;
96 gfx_coord2_t pos;
97 bool resize;
98 ui_wdecor_rsztype_t rsztype;
99 bool set_cursor;
100 ui_stock_cursor_t cursor;
101} test_cb_resp_t;
102
103/** Create and destroy button */
104PCUT_TEST(create_destroy)
105{
106 ui_wdecor_t *wdecor = NULL;
107 errno_t rc;
108
109 rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
110 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
111 PCUT_ASSERT_NOT_NULL(wdecor);
112
113 ui_wdecor_destroy(wdecor);
114}
115
116/** ui_wdecor_destroy() can take NULL argument (no-op) */
117PCUT_TEST(destroy_null)
118{
119 ui_wdecor_destroy(NULL);
120}
121
122/** Set window decoration rectangle sets internal field */
123PCUT_TEST(set_rect)
124{
125 ui_wdecor_t *wdecor;
126 gfx_rect_t rect;
127 errno_t rc;
128
129 rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
130 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
131
132 rect.p0.x = 1;
133 rect.p0.y = 2;
134 rect.p1.x = 3;
135 rect.p1.y = 4;
136
137 ui_wdecor_set_rect(wdecor, &rect);
138 PCUT_ASSERT_INT_EQUALS(rect.p0.x, wdecor->rect.p0.x);
139 PCUT_ASSERT_INT_EQUALS(rect.p0.y, wdecor->rect.p0.y);
140 PCUT_ASSERT_INT_EQUALS(rect.p1.x, wdecor->rect.p1.x);
141 PCUT_ASSERT_INT_EQUALS(rect.p1.y, wdecor->rect.p1.y);
142
143 ui_wdecor_destroy(wdecor);
144}
145
146/** Set window decoration active sets internal field */
147PCUT_TEST(set_active)
148{
149 ui_wdecor_t *wdecor;
150 errno_t rc;
151
152 rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
153 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
154
155 PCUT_ASSERT_TRUE(wdecor->active);
156
157 ui_wdecor_set_active(wdecor, false);
158 PCUT_ASSERT_FALSE(wdecor->active);
159
160 ui_wdecor_set_active(wdecor, true);
161 PCUT_ASSERT_TRUE(wdecor->active);
162
163 ui_wdecor_destroy(wdecor);
164}
165
166/** Paint button */
167PCUT_TEST(paint)
168{
169 errno_t rc;
170 gfx_context_t *gc = NULL;
171 test_gc_t tgc;
172 ui_resource_t *resource = NULL;
173 ui_wdecor_t *wdecor;
174
175 memset(&tgc, 0, sizeof(tgc));
176 rc = gfx_context_new(&ops, &tgc, &gc);
177 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
178
179 rc = ui_resource_create(gc, &resource);
180 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
181 PCUT_ASSERT_NOT_NULL(resource);
182
183 rc = ui_wdecor_create(resource, "Hello", ui_wds_none, &wdecor);
184 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
185
186 rc = ui_wdecor_paint(wdecor);
187 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
188
189 ui_wdecor_destroy(wdecor);
190 ui_resource_destroy(resource);
191
192 rc = gfx_context_delete(gc);
193 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
194}
195
196/** Test ui_wdecor_close() */
197PCUT_TEST(close)
198{
199 errno_t rc;
200 ui_wdecor_t *wdecor;
201 test_cb_resp_t resp;
202
203 rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
204 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
205
206 /* Close callback with no callbacks set */
207 ui_wdecor_close(wdecor);
208
209 /* Close callback with close callback not implemented */
210 ui_wdecor_set_cb(wdecor, &dummy_wdecor_cb, NULL);
211 ui_wdecor_close(wdecor);
212
213 /* Close callback with real callback set */
214 resp.close = false;
215 ui_wdecor_set_cb(wdecor, &test_wdecor_cb, &resp);
216 ui_wdecor_close(wdecor);
217 PCUT_ASSERT_TRUE(resp.close);
218
219 ui_wdecor_destroy(wdecor);
220}
221
222/** Test ui_wdecor_move() */
223PCUT_TEST(move)
224{
225 errno_t rc;
226 ui_wdecor_t *wdecor;
227 test_cb_resp_t resp;
228 gfx_coord2_t pos;
229
230 rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
231 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
232
233 pos.x = 3;
234 pos.y = 4;
235
236 /* Move callback with no callbacks set */
237 ui_wdecor_move(wdecor, &pos);
238
239 /* Move callback with move callback not implemented */
240 ui_wdecor_set_cb(wdecor, &dummy_wdecor_cb, NULL);
241 ui_wdecor_move(wdecor, &pos);
242
243 /* Move callback with real callback set */
244 resp.move = false;
245 resp.pos.x = 0;
246 resp.pos.y = 0;
247 ui_wdecor_set_cb(wdecor, &test_wdecor_cb, &resp);
248 ui_wdecor_move(wdecor, &pos);
249 PCUT_ASSERT_TRUE(resp.move);
250 PCUT_ASSERT_INT_EQUALS(pos.x, resp.pos.x);
251 PCUT_ASSERT_INT_EQUALS(pos.y, resp.pos.y);
252
253 ui_wdecor_destroy(wdecor);
254}
255
256/** Test ui_wdecor_resize() */
257PCUT_TEST(resize)
258{
259 errno_t rc;
260 ui_wdecor_t *wdecor;
261 test_cb_resp_t resp;
262 ui_wdecor_rsztype_t rsztype;
263 gfx_coord2_t pos;
264
265 rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
266 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
267
268 rsztype = ui_wr_bottom;
269 pos.x = 3;
270 pos.y = 4;
271
272 /* Resize callback with no callbacks set */
273 ui_wdecor_resize(wdecor, rsztype, &pos);
274
275 /* Resize callback with move callback not implemented */
276 ui_wdecor_set_cb(wdecor, &dummy_wdecor_cb, NULL);
277 ui_wdecor_resize(wdecor, rsztype, &pos);
278
279 /* Resize callback with real callback set */
280 resp.resize = false;
281 resp.rsztype = ui_wr_none;
282 resp.pos.x = 0;
283 resp.pos.y = 0;
284 ui_wdecor_set_cb(wdecor, &test_wdecor_cb, &resp);
285 ui_wdecor_resize(wdecor, rsztype, &pos);
286 PCUT_ASSERT_TRUE(resp.resize);
287 PCUT_ASSERT_INT_EQUALS(rsztype, resp.rsztype);
288 PCUT_ASSERT_INT_EQUALS(pos.x, resp.pos.x);
289 PCUT_ASSERT_INT_EQUALS(pos.y, resp.pos.y);
290
291 ui_wdecor_destroy(wdecor);
292}
293
294/** Test ui_wdecor_set_cursor() */
295PCUT_TEST(set_cursor)
296{
297 errno_t rc;
298 ui_wdecor_t *wdecor;
299 test_cb_resp_t resp;
300 ui_stock_cursor_t cursor;
301
302 rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
303 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
304
305 cursor = ui_curs_size_uldr;
306
307 /* Set cursor callback with no callbacks set */
308 ui_wdecor_set_cursor(wdecor, cursor);
309
310 /* Set cursor callback with move callback not implemented */
311 ui_wdecor_set_cb(wdecor, &dummy_wdecor_cb, NULL);
312 ui_wdecor_set_cursor(wdecor, cursor);
313
314 /* Set cursor callback with real callback set */
315 resp.set_cursor = false;
316 resp.cursor = ui_curs_arrow;
317 ui_wdecor_set_cb(wdecor, &test_wdecor_cb, &resp);
318 ui_wdecor_set_cursor(wdecor, cursor);
319 PCUT_ASSERT_TRUE(resp.set_cursor);
320 PCUT_ASSERT_INT_EQUALS(cursor, resp.cursor);
321
322 ui_wdecor_destroy(wdecor);
323}
324
325/** Clicking the close button generates close callback */
326PCUT_TEST(close_btn_clicked)
327{
328 ui_wdecor_t *wdecor;
329 gfx_rect_t rect;
330 test_cb_resp_t resp;
331 errno_t rc;
332
333 rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
334 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
335
336 rect.p0.x = 10;
337 rect.p0.y = 20;
338 rect.p1.x = 100;
339 rect.p1.y = 200;
340
341 ui_wdecor_set_rect(wdecor, &rect);
342
343 ui_wdecor_set_cb(wdecor, &test_wdecor_cb, (void *) &resp);
344
345 resp.close = false;
346
347 ui_pbutton_clicked(wdecor->btn_close);
348 PCUT_ASSERT_TRUE(resp.close);
349
350 ui_wdecor_destroy(wdecor);
351}
352
353/** Button press on title bar generates move callback */
354PCUT_TEST(pos_event_move)
355{
356 ui_wdecor_t *wdecor;
357 gfx_rect_t rect;
358 pos_event_t event;
359 test_cb_resp_t resp;
360 errno_t rc;
361
362 rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
363 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
364
365 rect.p0.x = 10;
366 rect.p0.y = 20;
367 rect.p1.x = 100;
368 rect.p1.y = 200;
369
370 ui_wdecor_set_rect(wdecor, &rect);
371
372 ui_wdecor_set_cb(wdecor, &test_wdecor_cb, (void *) &resp);
373
374 resp.move = false;
375 resp.pos.x = 0;
376 resp.pos.y = 0;
377
378 event.type = POS_PRESS;
379 event.hpos = 50;
380 event.vpos = 25;
381 ui_wdecor_pos_event(wdecor, &event);
382
383 PCUT_ASSERT_TRUE(resp.move);
384 PCUT_ASSERT_INT_EQUALS(event.hpos, resp.pos.x);
385 PCUT_ASSERT_INT_EQUALS(event.vpos, resp.pos.y);
386
387 ui_wdecor_destroy(wdecor);
388}
389
390/** ui_wdecor_get_geom() produces the correct geometry */
391PCUT_TEST(get_geom)
392{
393 ui_wdecor_t *wdecor;
394 gfx_rect_t rect;
395 ui_wdecor_geom_t geom;
396 errno_t rc;
397
398 rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
399 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
400
401 rect.p0.x = 10;
402 rect.p0.y = 20;
403 rect.p1.x = 100;
404 rect.p1.y = 200;
405
406 ui_wdecor_set_rect(wdecor, &rect);
407 ui_wdecor_get_geom(wdecor, &geom);
408
409 PCUT_ASSERT_INT_EQUALS(14, geom.interior_rect.p0.x);
410 PCUT_ASSERT_INT_EQUALS(24, geom.interior_rect.p0.y);
411 PCUT_ASSERT_INT_EQUALS(96, geom.interior_rect.p1.x);
412 PCUT_ASSERT_INT_EQUALS(196, geom.interior_rect.p1.y);
413
414 PCUT_ASSERT_INT_EQUALS(14, geom.title_bar_rect.p0.x);
415 PCUT_ASSERT_INT_EQUALS(24, geom.title_bar_rect.p0.y);
416 PCUT_ASSERT_INT_EQUALS(96, geom.title_bar_rect.p1.x);
417 PCUT_ASSERT_INT_EQUALS(46, geom.title_bar_rect.p1.y);
418
419 PCUT_ASSERT_INT_EQUALS(75, geom.btn_close_rect.p0.x);
420 PCUT_ASSERT_INT_EQUALS(25, geom.btn_close_rect.p0.y);
421 PCUT_ASSERT_INT_EQUALS(95, geom.btn_close_rect.p1.x);
422 PCUT_ASSERT_INT_EQUALS(45, geom.btn_close_rect.p1.y);
423
424 PCUT_ASSERT_INT_EQUALS(14, geom.app_area_rect.p0.x);
425 PCUT_ASSERT_INT_EQUALS(46, geom.app_area_rect.p0.y);
426 PCUT_ASSERT_INT_EQUALS(96, geom.app_area_rect.p1.x);
427 PCUT_ASSERT_INT_EQUALS(196, geom.app_area_rect.p1.y);
428
429 ui_wdecor_destroy(wdecor);
430}
431
432/** ui_wdecor_rect_from_app() correctly converts application to window rect */
433PCUT_TEST(rect_from_app)
434{
435 gfx_rect_t arect;
436 gfx_rect_t rect;
437
438 arect.p0.x = 14;
439 arect.p0.y = 46;
440 arect.p1.x = 96;
441 arect.p1.y = 196;
442
443 ui_wdecor_rect_from_app(&arect, &rect);
444
445 PCUT_ASSERT_INT_EQUALS(10, rect.p0.x);
446 PCUT_ASSERT_INT_EQUALS(20, rect.p0.y);
447 PCUT_ASSERT_INT_EQUALS(100, rect.p1.x);
448 PCUT_ASSERT_INT_EQUALS(200, rect.p1.y);
449}
450
451/** Test ui_wdecor_get_rsztype() */
452PCUT_TEST(get_rsztype)
453{
454 ui_wdecor_t *wdecor;
455 gfx_rect_t rect;
456 ui_wdecor_rsztype_t rsztype;
457 gfx_coord2_t pos;
458 errno_t rc;
459
460 rc = ui_wdecor_create(NULL, "Hello", ui_wds_resizable, &wdecor);
461 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
462
463 rect.p0.x = 10;
464 rect.p0.y = 20;
465 rect.p1.x = 100;
466 rect.p1.y = 200;
467
468 ui_wdecor_set_rect(wdecor, &rect);
469
470 /* Outside of the window */
471 pos.x = 0;
472 pos.y = -1;
473 rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
474 PCUT_ASSERT_EQUALS(ui_wr_none, rsztype);
475
476 /* Middle of the window */
477 pos.x = 50;
478 pos.y = 100;
479 rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
480 PCUT_ASSERT_EQUALS(ui_wr_none, rsztype);
481
482 /* Top-left corner, but not on edge */
483 pos.x = 20;
484 pos.y = 30;
485 rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
486 PCUT_ASSERT_EQUALS(ui_wr_none, rsztype);
487
488 /* Top-left corner on top edge */
489 pos.x = 20;
490 pos.y = 20;
491 rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
492 PCUT_ASSERT_EQUALS(ui_wr_top_left, rsztype);
493
494 /* Top-left corner on left edge */
495 pos.x = 10;
496 pos.y = 30;
497 rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
498 PCUT_ASSERT_EQUALS(ui_wr_top_left, rsztype);
499
500 /* Top-right corner on top edge */
501 pos.x = 90;
502 pos.y = 20;
503 rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
504 PCUT_ASSERT_EQUALS(ui_wr_top_right, rsztype);
505
506 /* Top-right corner on right edge */
507 pos.x = 99;
508 pos.y = 30;
509 rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
510 PCUT_ASSERT_EQUALS(ui_wr_top_right, rsztype);
511
512 /* Top edge */
513 pos.x = 50;
514 pos.y = 20;
515 rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
516 PCUT_ASSERT_EQUALS(ui_wr_top, rsztype);
517
518 /* Bottom edge */
519 pos.x = 50;
520 pos.y = 199;
521 rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
522 PCUT_ASSERT_EQUALS(ui_wr_bottom, rsztype);
523
524 /* Left edge */
525 pos.x = 10;
526 pos.y = 100;
527 rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
528 PCUT_ASSERT_EQUALS(ui_wr_left, rsztype);
529
530 /* Right edge */
531 pos.x = 99;
532 pos.y = 100;
533 rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
534 PCUT_ASSERT_EQUALS(ui_wr_right, rsztype);
535
536 ui_wdecor_destroy(wdecor);
537
538 /* Non-resizable window */
539
540 rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor);
541 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
542
543 rect.p0.x = 10;
544 rect.p0.y = 20;
545 rect.p1.x = 100;
546 rect.p1.y = 200;
547
548 ui_wdecor_set_rect(wdecor, &rect);
549
550 pos.x = 10;
551 pos.y = 20;
552 rsztype = ui_wdecor_get_rsztype(wdecor, &pos);
553 PCUT_ASSERT_EQUALS(ui_wr_none, rsztype);
554
555 ui_wdecor_destroy(wdecor);
556}
557
558/** Test ui_wdecor_cursor_from_rsztype() */
559PCUT_TEST(cursor_from_rsztype)
560{
561 PCUT_ASSERT_EQUALS(ui_curs_arrow,
562 ui_wdecor_cursor_from_rsztype(ui_wr_none));
563 PCUT_ASSERT_EQUALS(ui_curs_size_ud,
564 ui_wdecor_cursor_from_rsztype(ui_wr_top));
565 PCUT_ASSERT_EQUALS(ui_curs_size_ud,
566 ui_wdecor_cursor_from_rsztype(ui_wr_bottom));
567 PCUT_ASSERT_EQUALS(ui_curs_size_lr,
568 ui_wdecor_cursor_from_rsztype(ui_wr_left));
569 PCUT_ASSERT_EQUALS(ui_curs_size_lr,
570 ui_wdecor_cursor_from_rsztype(ui_wr_right));
571 PCUT_ASSERT_EQUALS(ui_curs_size_uldr,
572 ui_wdecor_cursor_from_rsztype(ui_wr_top_left));
573 PCUT_ASSERT_EQUALS(ui_curs_size_uldr,
574 ui_wdecor_cursor_from_rsztype(ui_wr_bottom_right));
575 PCUT_ASSERT_EQUALS(ui_curs_size_urdl,
576 ui_wdecor_cursor_from_rsztype(ui_wr_top_right));
577 PCUT_ASSERT_EQUALS(ui_curs_size_urdl,
578 ui_wdecor_cursor_from_rsztype(ui_wr_bottom_left));
579}
580
581/** Test ui_wdecor_frame_pos_event() */
582PCUT_TEST(frame_pos_event)
583{
584 ui_wdecor_t *wdecor;
585 gfx_rect_t rect;
586 test_cb_resp_t resp;
587 pos_event_t event;
588 errno_t rc;
589
590 rc = ui_wdecor_create(NULL, "Hello", ui_wds_resizable, &wdecor);
591 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
592
593 rect.p0.x = 10;
594 rect.p0.y = 20;
595 rect.p1.x = 100;
596 rect.p1.y = 200;
597
598 ui_wdecor_set_rect(wdecor, &rect);
599 ui_wdecor_set_cb(wdecor, &test_wdecor_cb, &resp);
600
601 /* Release on window border should do nothing */
602 resp.resize = false;
603 event.type = POS_RELEASE;
604 event.hpos = 10;
605 event.vpos = 10;
606 ui_wdecor_frame_pos_event(wdecor, &event);
607 PCUT_ASSERT_FALSE(resp.resize);
608
609 /* Press in the middle of the window should do nothing */
610 resp.resize = false;
611 event.type = POS_PRESS;
612 event.hpos = 50;
613 event.vpos = 100;
614 ui_wdecor_frame_pos_event(wdecor, &event);
615 PCUT_ASSERT_FALSE(resp.resize);
616
617 /* Press on window border should cause resize to be called */
618 resp.resize = false;
619 event.type = POS_PRESS;
620 event.hpos = 10;
621 event.vpos = 20;
622 ui_wdecor_frame_pos_event(wdecor, &event);
623 PCUT_ASSERT_TRUE(resp.resize);
624
625 ui_wdecor_destroy(wdecor);
626}
627
628static errno_t testgc_set_color(void *arg, gfx_color_t *color)
629{
630 (void) arg;
631 (void) color;
632 return EOK;
633}
634
635static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect)
636{
637 (void) arg;
638 (void) rect;
639 return EOK;
640}
641
642static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params,
643 gfx_bitmap_alloc_t *alloc, void **rbm)
644{
645 test_gc_t *tgc = (test_gc_t *) arg;
646 testgc_bitmap_t *tbm;
647
648 tbm = calloc(1, sizeof(testgc_bitmap_t));
649 if (tbm == NULL)
650 return ENOMEM;
651
652 if (alloc == NULL) {
653 tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) *
654 sizeof(uint32_t);
655 tbm->alloc.off0 = 0;
656 tbm->alloc.pixels = calloc(sizeof(uint32_t),
657 (params->rect.p1.x - params->rect.p0.x) *
658 (params->rect.p1.y - params->rect.p0.y));
659 tbm->myalloc = true;
660 if (tbm->alloc.pixels == NULL) {
661 free(tbm);
662 return ENOMEM;
663 }
664 } else {
665 tbm->alloc = *alloc;
666 }
667
668 tbm->tgc = tgc;
669 tgc->bm_created = true;
670 tgc->bm_params = *params;
671 tgc->bm_pixels = tbm->alloc.pixels;
672 *rbm = (void *)tbm;
673 return EOK;
674}
675
676static errno_t testgc_bitmap_destroy(void *bm)
677{
678 testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
679 if (tbm->myalloc)
680 free(tbm->alloc.pixels);
681 tbm->tgc->bm_destroyed = true;
682 free(tbm);
683 return EOK;
684}
685
686static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect,
687 gfx_coord2_t *offs)
688{
689 testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
690 tbm->tgc->bm_rendered = true;
691 tbm->tgc->bm_srect = *srect;
692 tbm->tgc->bm_offs = *offs;
693 return EOK;
694}
695
696static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)
697{
698 testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
699 *alloc = tbm->alloc;
700 tbm->tgc->bm_got_alloc = true;
701 return EOK;
702}
703
704static void test_wdecor_close(ui_wdecor_t *wdecor, void *arg)
705{
706 test_cb_resp_t *resp = (test_cb_resp_t *) arg;
707
708 resp->close = true;
709}
710
711static void test_wdecor_move(ui_wdecor_t *wdecor, void *arg, gfx_coord2_t *pos)
712{
713 test_cb_resp_t *resp = (test_cb_resp_t *) arg;
714
715 resp->move = true;
716 resp->pos = *pos;
717}
718
719static void test_wdecor_resize(ui_wdecor_t *wdecor, void *arg,
720 ui_wdecor_rsztype_t rsztype, gfx_coord2_t *pos)
721{
722 test_cb_resp_t *resp = (test_cb_resp_t *) arg;
723
724 resp->resize = true;
725 resp->rsztype = rsztype;
726 resp->pos = *pos;
727}
728
729static void test_wdecor_set_cursor(ui_wdecor_t *wdecor, void *arg,
730 ui_stock_cursor_t cursor)
731{
732 test_cb_resp_t *resp = (test_cb_resp_t *) arg;
733
734 resp->set_cursor = true;
735 resp->cursor = cursor;
736}
737
738PCUT_EXPORT(wdecor);
Note: See TracBrowser for help on using the repository browser.