source: mainline/uspace/lib/ui/test/pbutton.c@ 3a6d44b7

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

Update window button when window caption changes

  • Property mode set to 100644
File size: 16.7 KB
Line 
1/*
2 * Copyright (c) 2022 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/control.h>
35#include <ui/pbutton.h>
36#include <ui/resource.h>
37#include "../private/pbutton.h"
38
39PCUT_INIT;
40
41PCUT_TEST_SUITE(pbutton);
42
43static errno_t testgc_set_clip_rect(void *, gfx_rect_t *);
44static errno_t testgc_set_color(void *, gfx_color_t *);
45static errno_t testgc_fill_rect(void *, gfx_rect_t *);
46static errno_t testgc_update(void *);
47static errno_t testgc_bitmap_create(void *, gfx_bitmap_params_t *,
48 gfx_bitmap_alloc_t *, void **);
49static errno_t testgc_bitmap_destroy(void *);
50static errno_t testgc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *);
51static errno_t testgc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *);
52
53static gfx_context_ops_t ops = {
54 .set_clip_rect = testgc_set_clip_rect,
55 .set_color = testgc_set_color,
56 .fill_rect = testgc_fill_rect,
57 .update = testgc_update,
58 .bitmap_create = testgc_bitmap_create,
59 .bitmap_destroy = testgc_bitmap_destroy,
60 .bitmap_render = testgc_bitmap_render,
61 .bitmap_get_alloc = testgc_bitmap_get_alloc
62};
63
64static void test_pbutton_clicked(ui_pbutton_t *, void *);
65static void test_pbutton_down(ui_pbutton_t *, void *);
66static void test_pbutton_up(ui_pbutton_t *, void *);
67
68static ui_pbutton_cb_t test_pbutton_cb = {
69 .clicked = test_pbutton_clicked,
70 .down = test_pbutton_down,
71 .up = test_pbutton_up
72};
73
74static ui_pbutton_cb_t dummy_pbutton_cb = {
75};
76
77typedef struct {
78 bool bm_created;
79 bool bm_destroyed;
80 gfx_bitmap_params_t bm_params;
81 void *bm_pixels;
82 gfx_rect_t bm_srect;
83 gfx_coord2_t bm_offs;
84 bool bm_rendered;
85 bool bm_got_alloc;
86} test_gc_t;
87
88typedef struct {
89 test_gc_t *tgc;
90 gfx_bitmap_alloc_t alloc;
91 bool myalloc;
92} testgc_bitmap_t;
93
94typedef struct {
95 bool clicked;
96 bool down;
97 bool up;
98} test_cb_resp_t;
99
100/** Create and destroy button */
101PCUT_TEST(create_destroy)
102{
103 ui_pbutton_t *pbutton = NULL;
104 errno_t rc;
105
106 rc = ui_pbutton_create(NULL, "Hello", &pbutton);
107 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
108 PCUT_ASSERT_NOT_NULL(pbutton);
109
110 ui_pbutton_destroy(pbutton);
111}
112
113/** ui_pbutton_destroy() can take NULL argument (no-op) */
114PCUT_TEST(destroy_null)
115{
116 ui_pbutton_destroy(NULL);
117}
118
119/** ui_pbutton_ctl() returns control that has a working virtual destructor */
120PCUT_TEST(ctl)
121{
122 ui_pbutton_t *pbutton;
123 ui_control_t *control;
124 errno_t rc;
125
126 rc = ui_pbutton_create(NULL, "Hello", &pbutton);
127 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
128
129 control = ui_pbutton_ctl(pbutton);
130 PCUT_ASSERT_NOT_NULL(control);
131
132 ui_control_destroy(control);
133}
134
135/** Set flags sets internal field */
136PCUT_TEST(set_flags)
137{
138 ui_pbutton_t *pbutton;
139 errno_t rc;
140
141 rc = ui_pbutton_create(NULL, "Hello", &pbutton);
142 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
143
144 ui_pbutton_set_flags(pbutton, ui_pbf_no_text_depress);
145 PCUT_ASSERT_INT_EQUALS(ui_pbf_no_text_depress, pbutton->flags);
146
147 ui_pbutton_destroy(pbutton);
148}
149
150/** Set button rectangle sets internal field */
151PCUT_TEST(set_rect)
152{
153 ui_pbutton_t *pbutton;
154 gfx_rect_t rect;
155 errno_t rc;
156
157 rc = ui_pbutton_create(NULL, "Hello", &pbutton);
158 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
159
160 rect.p0.x = 1;
161 rect.p0.y = 2;
162 rect.p1.x = 3;
163 rect.p1.y = 4;
164
165 ui_pbutton_set_rect(pbutton, &rect);
166 PCUT_ASSERT_INT_EQUALS(rect.p0.x, pbutton->rect.p0.x);
167 PCUT_ASSERT_INT_EQUALS(rect.p0.y, pbutton->rect.p0.y);
168 PCUT_ASSERT_INT_EQUALS(rect.p1.x, pbutton->rect.p1.x);
169 PCUT_ASSERT_INT_EQUALS(rect.p1.y, pbutton->rect.p1.y);
170
171 ui_pbutton_destroy(pbutton);
172}
173
174/** Set default flag sets internal field */
175PCUT_TEST(set_default)
176{
177 ui_pbutton_t *pbutton;
178 errno_t rc;
179
180 rc = ui_pbutton_create(NULL, "Hello", &pbutton);
181 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
182
183 ui_pbutton_set_default(pbutton, true);
184 PCUT_ASSERT_TRUE(pbutton->isdefault);
185
186 ui_pbutton_set_default(pbutton, false);
187 PCUT_ASSERT_FALSE(pbutton->isdefault);
188
189 ui_pbutton_destroy(pbutton);
190}
191
192/** Set caption sets internal field */
193PCUT_TEST(set_caption)
194{
195 ui_pbutton_t *pbutton;
196 errno_t rc;
197
198 rc = ui_pbutton_create(NULL, "Hello", &pbutton);
199 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
200
201 PCUT_ASSERT_STR_EQUALS("Hello", pbutton->caption);
202
203 rc = ui_pbutton_set_caption(pbutton, "World");
204 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
205
206 PCUT_ASSERT_STR_EQUALS("World", pbutton->caption);
207
208 ui_pbutton_destroy(pbutton);
209}
210
211/** Paint button */
212PCUT_TEST(paint)
213{
214 errno_t rc;
215 gfx_context_t *gc = NULL;
216 test_gc_t tgc;
217 ui_resource_t *resource = NULL;
218 ui_pbutton_t *pbutton;
219
220 memset(&tgc, 0, sizeof(tgc));
221 rc = gfx_context_new(&ops, &tgc, &gc);
222 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
223
224 rc = ui_resource_create(gc, false, &resource);
225 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
226 PCUT_ASSERT_NOT_NULL(resource);
227
228 rc = ui_pbutton_create(resource, "Hello", &pbutton);
229 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
230
231 rc = ui_pbutton_paint(pbutton);
232 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
233
234 ui_pbutton_destroy(pbutton);
235 ui_resource_destroy(resource);
236
237 rc = gfx_context_delete(gc);
238 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
239}
240
241/** Test ui_pbutton_clicked() */
242PCUT_TEST(clicked)
243{
244 errno_t rc;
245 ui_pbutton_t *pbutton;
246 test_cb_resp_t resp;
247
248 rc = ui_pbutton_create(NULL, "Hello", &pbutton);
249 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
250
251 /* Clicked with no callbacks set */
252 ui_pbutton_clicked(pbutton);
253
254 /* Clicked with callback not implementing clicked */
255 ui_pbutton_set_cb(pbutton, &dummy_pbutton_cb, NULL);
256 ui_pbutton_clicked(pbutton);
257
258 /* Clicked with real callback set */
259 resp.clicked = false;
260 ui_pbutton_set_cb(pbutton, &test_pbutton_cb, &resp);
261 ui_pbutton_clicked(pbutton);
262 PCUT_ASSERT_TRUE(resp.clicked);
263
264 ui_pbutton_destroy(pbutton);
265}
266
267/** Test ui_pbutton_down() */
268PCUT_TEST(down)
269{
270 errno_t rc;
271 ui_pbutton_t *pbutton;
272 test_cb_resp_t resp;
273
274 rc = ui_pbutton_create(NULL, "Hello", &pbutton);
275 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
276
277 /* Down with no callbacks set */
278 ui_pbutton_clicked(pbutton);
279
280 /* Down with callback not implementing down */
281 ui_pbutton_set_cb(pbutton, &dummy_pbutton_cb, NULL);
282 ui_pbutton_down(pbutton);
283
284 /* Down with real callback set */
285 resp.down = false;
286 ui_pbutton_set_cb(pbutton, &test_pbutton_cb, &resp);
287 ui_pbutton_down(pbutton);
288 PCUT_ASSERT_TRUE(resp.down);
289
290 ui_pbutton_destroy(pbutton);
291}
292
293/** Test ui_pbutton_up() */
294PCUT_TEST(up)
295{
296 errno_t rc;
297 ui_pbutton_t *pbutton;
298 test_cb_resp_t resp;
299
300 rc = ui_pbutton_create(NULL, "Hello", &pbutton);
301 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
302
303 /* Up with no callbacks set */
304 ui_pbutton_clicked(pbutton);
305
306 /* Up with callback not implementing up */
307 ui_pbutton_set_cb(pbutton, &dummy_pbutton_cb, NULL);
308 ui_pbutton_up(pbutton);
309
310 /* Up with real callback set */
311 resp.up = false;
312 ui_pbutton_set_cb(pbutton, &test_pbutton_cb, &resp);
313 ui_pbutton_up(pbutton);
314 PCUT_ASSERT_TRUE(resp.up);
315
316 ui_pbutton_destroy(pbutton);
317}
318
319/** Press and release button */
320PCUT_TEST(press_release)
321{
322 errno_t rc;
323 gfx_context_t *gc = NULL;
324 test_gc_t tgc;
325 ui_resource_t *resource = NULL;
326 ui_pbutton_t *pbutton;
327 test_cb_resp_t resp;
328
329 memset(&tgc, 0, sizeof(tgc));
330 rc = gfx_context_new(&ops, &tgc, &gc);
331 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
332
333 rc = ui_resource_create(gc, false, &resource);
334 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
335 PCUT_ASSERT_NOT_NULL(resource);
336
337 rc = ui_pbutton_create(resource, "Hello", &pbutton);
338 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
339
340 resp.clicked = false;
341 resp.down = false;
342 resp.up = false;
343 ui_pbutton_set_cb(pbutton, &test_pbutton_cb, &resp);
344
345 PCUT_ASSERT_FALSE(pbutton->held);
346 PCUT_ASSERT_FALSE(pbutton->inside);
347
348 ui_pbutton_press(pbutton);
349 PCUT_ASSERT_TRUE(pbutton->held);
350 PCUT_ASSERT_TRUE(pbutton->inside);
351 PCUT_ASSERT_TRUE(resp.down);
352 PCUT_ASSERT_FALSE(resp.up);
353 PCUT_ASSERT_FALSE(resp.clicked);
354
355 ui_pbutton_release(pbutton);
356 PCUT_ASSERT_FALSE(pbutton->held);
357 PCUT_ASSERT_TRUE(pbutton->inside);
358 PCUT_ASSERT_TRUE(resp.up);
359 PCUT_ASSERT_TRUE(resp.clicked);
360
361 ui_pbutton_destroy(pbutton);
362 ui_resource_destroy(resource);
363
364 rc = gfx_context_delete(gc);
365 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
366}
367
368/** Press, leave and release button */
369PCUT_TEST(press_leave_release)
370{
371 errno_t rc;
372 gfx_context_t *gc = NULL;
373 test_gc_t tgc;
374 ui_resource_t *resource = NULL;
375 ui_pbutton_t *pbutton;
376 test_cb_resp_t resp;
377
378 memset(&tgc, 0, sizeof(tgc));
379 rc = gfx_context_new(&ops, &tgc, &gc);
380 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
381
382 rc = ui_resource_create(gc, false, &resource);
383 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
384 PCUT_ASSERT_NOT_NULL(resource);
385
386 rc = ui_pbutton_create(resource, "Hello", &pbutton);
387 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
388
389 resp.clicked = false;
390 ui_pbutton_set_cb(pbutton, &test_pbutton_cb, &resp);
391
392 PCUT_ASSERT_FALSE(pbutton->held);
393 PCUT_ASSERT_FALSE(pbutton->inside);
394
395 ui_pbutton_press(pbutton);
396 PCUT_ASSERT_TRUE(pbutton->held);
397 PCUT_ASSERT_TRUE(pbutton->inside);
398 PCUT_ASSERT_FALSE(resp.clicked);
399
400 ui_pbutton_leave(pbutton);
401 PCUT_ASSERT_TRUE(pbutton->held);
402 PCUT_ASSERT_FALSE(pbutton->inside);
403 PCUT_ASSERT_FALSE(resp.clicked);
404
405 ui_pbutton_release(pbutton);
406 PCUT_ASSERT_FALSE(pbutton->held);
407 PCUT_ASSERT_FALSE(pbutton->inside);
408 PCUT_ASSERT_FALSE(resp.clicked);
409
410 ui_pbutton_destroy(pbutton);
411 ui_resource_destroy(resource);
412
413 rc = gfx_context_delete(gc);
414 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
415}
416
417/** Press, leave, enter and release button */
418PCUT_TEST(press_leave_enter_release)
419{
420 errno_t rc;
421 gfx_context_t *gc = NULL;
422 test_gc_t tgc;
423 ui_resource_t *resource = NULL;
424 ui_pbutton_t *pbutton;
425 test_cb_resp_t resp;
426
427 memset(&tgc, 0, sizeof(tgc));
428 rc = gfx_context_new(&ops, &tgc, &gc);
429 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
430
431 rc = ui_resource_create(gc, false, &resource);
432 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
433 PCUT_ASSERT_NOT_NULL(resource);
434
435 rc = ui_pbutton_create(resource, "Hello", &pbutton);
436 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
437
438 resp.clicked = false;
439 ui_pbutton_set_cb(pbutton, &test_pbutton_cb, &resp);
440
441 PCUT_ASSERT_FALSE(pbutton->held);
442 PCUT_ASSERT_FALSE(pbutton->inside);
443
444 ui_pbutton_press(pbutton);
445 PCUT_ASSERT_TRUE(pbutton->held);
446 PCUT_ASSERT_TRUE(pbutton->inside);
447 PCUT_ASSERT_FALSE(resp.clicked);
448
449 ui_pbutton_leave(pbutton);
450 PCUT_ASSERT_TRUE(pbutton->held);
451 PCUT_ASSERT_FALSE(pbutton->inside);
452 PCUT_ASSERT_FALSE(resp.clicked);
453
454 ui_pbutton_enter(pbutton);
455 PCUT_ASSERT_TRUE(pbutton->held);
456 PCUT_ASSERT_TRUE(pbutton->inside);
457 PCUT_ASSERT_FALSE(resp.clicked);
458
459 ui_pbutton_release(pbutton);
460 PCUT_ASSERT_FALSE(pbutton->held);
461 PCUT_ASSERT_TRUE(pbutton->inside);
462 PCUT_ASSERT_TRUE(resp.clicked);
463
464 ui_pbutton_destroy(pbutton);
465 ui_resource_destroy(resource);
466
467 rc = gfx_context_delete(gc);
468 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
469}
470
471/** ui_pos_event() correctly translates POS_PRESS/POS_RELEASE */
472PCUT_TEST(pos_event_press_release)
473{
474 errno_t rc;
475 gfx_context_t *gc = NULL;
476 test_gc_t tgc;
477 ui_resource_t *resource = NULL;
478 ui_pbutton_t *pbutton;
479 ui_evclaim_t claim;
480 pos_event_t event;
481 gfx_rect_t rect;
482
483 memset(&tgc, 0, sizeof(tgc));
484 rc = gfx_context_new(&ops, &tgc, &gc);
485 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
486
487 rc = ui_resource_create(gc, false, &resource);
488 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
489 PCUT_ASSERT_NOT_NULL(resource);
490
491 rc = ui_pbutton_create(resource, "Hello", &pbutton);
492 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
493
494 PCUT_ASSERT_FALSE(pbutton->held);
495
496 rect.p0.x = 10;
497 rect.p0.y = 20;
498 rect.p1.x = 30;
499 rect.p1.y = 40;
500 ui_pbutton_set_rect(pbutton, &rect);
501
502 /* Press outside is not claimed and does nothing */
503 event.type = POS_PRESS;
504 event.hpos = 9;
505 event.vpos = 20;
506 claim = ui_pbutton_pos_event(pbutton, &event);
507 PCUT_ASSERT_FALSE(pbutton->held);
508 PCUT_ASSERT_EQUALS(ui_unclaimed, claim);
509
510 /* Press inside is claimed and depresses button */
511 event.type = POS_PRESS;
512 event.hpos = 10;
513 event.vpos = 20;
514 claim = ui_pbutton_pos_event(pbutton, &event);
515 PCUT_ASSERT_TRUE(pbutton->held);
516 PCUT_ASSERT_EQUALS(ui_claimed, claim);
517
518 /* Release outside (or anywhere) is claimed and relases button */
519 event.type = POS_RELEASE;
520 event.hpos = 9;
521 event.vpos = 20;
522 claim = ui_pbutton_pos_event(pbutton, &event);
523 PCUT_ASSERT_FALSE(pbutton->held);
524 PCUT_ASSERT_EQUALS(ui_claimed, claim);
525
526 ui_pbutton_destroy(pbutton);
527 ui_resource_destroy(resource);
528
529 rc = gfx_context_delete(gc);
530 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
531}
532
533/** ui_pos_event() correctly translates POS_UPDATE to enter/leave */
534PCUT_TEST(pos_event_enter_leave)
535{
536 errno_t rc;
537 gfx_context_t *gc = NULL;
538 test_gc_t tgc;
539 ui_resource_t *resource = NULL;
540 ui_pbutton_t *pbutton;
541 pos_event_t event;
542 gfx_rect_t rect;
543
544 memset(&tgc, 0, sizeof(tgc));
545 rc = gfx_context_new(&ops, &tgc, &gc);
546 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
547
548 rc = ui_resource_create(gc, false, &resource);
549 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
550 PCUT_ASSERT_NOT_NULL(resource);
551
552 rc = ui_pbutton_create(resource, "Hello", &pbutton);
553 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
554
555 PCUT_ASSERT_FALSE(pbutton->inside);
556
557 rect.p0.x = 10;
558 rect.p0.y = 20;
559 rect.p1.x = 30;
560 rect.p1.y = 40;
561 ui_pbutton_set_rect(pbutton, &rect);
562
563 /* Moving outside does nothing */
564 event.type = POS_UPDATE;
565 event.hpos = 9;
566 event.vpos = 20;
567 ui_pbutton_pos_event(pbutton, &event);
568 PCUT_ASSERT_FALSE(pbutton->inside);
569
570 /* Moving inside sets inside flag */
571 event.type = POS_UPDATE;
572 event.hpos = 10;
573 event.vpos = 20;
574 ui_pbutton_pos_event(pbutton, &event);
575 PCUT_ASSERT_TRUE(pbutton->inside);
576
577 /* Moving outside clears inside flag */
578 event.type = POS_UPDATE;
579 event.hpos = 9;
580 event.vpos = 20;
581 ui_pbutton_pos_event(pbutton, &event);
582 PCUT_ASSERT_FALSE(pbutton->inside);
583
584 ui_pbutton_destroy(pbutton);
585 ui_resource_destroy(resource);
586
587 rc = gfx_context_delete(gc);
588 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
589}
590
591static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect)
592{
593 (void) arg;
594 (void) rect;
595 return EOK;
596}
597
598static errno_t testgc_set_color(void *arg, gfx_color_t *color)
599{
600 (void) arg;
601 (void) color;
602 return EOK;
603}
604
605static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect)
606{
607 (void) arg;
608 (void) rect;
609 return EOK;
610}
611
612static errno_t testgc_update(void *arg)
613{
614 (void) arg;
615 return EOK;
616}
617
618static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params,
619 gfx_bitmap_alloc_t *alloc, void **rbm)
620{
621 test_gc_t *tgc = (test_gc_t *) arg;
622 testgc_bitmap_t *tbm;
623
624 tbm = calloc(1, sizeof(testgc_bitmap_t));
625 if (tbm == NULL)
626 return ENOMEM;
627
628 if (alloc == NULL) {
629 tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) *
630 sizeof(uint32_t);
631 tbm->alloc.off0 = 0;
632 tbm->alloc.pixels = calloc(sizeof(uint32_t),
633 (params->rect.p1.x - params->rect.p0.x) *
634 (params->rect.p1.y - params->rect.p0.y));
635 tbm->myalloc = true;
636 if (tbm->alloc.pixels == NULL) {
637 free(tbm);
638 return ENOMEM;
639 }
640 } else {
641 tbm->alloc = *alloc;
642 }
643
644 tbm->tgc = tgc;
645 tgc->bm_created = true;
646 tgc->bm_params = *params;
647 tgc->bm_pixels = tbm->alloc.pixels;
648 *rbm = (void *)tbm;
649 return EOK;
650}
651
652static errno_t testgc_bitmap_destroy(void *bm)
653{
654 testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
655 if (tbm->myalloc)
656 free(tbm->alloc.pixels);
657 tbm->tgc->bm_destroyed = true;
658 free(tbm);
659 return EOK;
660}
661
662static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect,
663 gfx_coord2_t *offs)
664{
665 testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
666 tbm->tgc->bm_rendered = true;
667 tbm->tgc->bm_srect = *srect;
668 tbm->tgc->bm_offs = *offs;
669 return EOK;
670}
671
672static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)
673{
674 testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
675 *alloc = tbm->alloc;
676 tbm->tgc->bm_got_alloc = true;
677 return EOK;
678}
679
680static void test_pbutton_clicked(ui_pbutton_t *pbutton, void *arg)
681{
682 test_cb_resp_t *resp = (test_cb_resp_t *) arg;
683
684 resp->clicked = true;
685}
686
687static void test_pbutton_down(ui_pbutton_t *pbutton, void *arg)
688{
689 test_cb_resp_t *resp = (test_cb_resp_t *) arg;
690
691 resp->down = true;
692}
693
694static void test_pbutton_up(ui_pbutton_t *pbutton, void *arg)
695{
696 test_cb_resp_t *resp = (test_cb_resp_t *) arg;
697
698 resp->up = true;
699}
700
701PCUT_EXPORT(pbutton);
Note: See TracBrowser for help on using the repository browser.