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

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

Scroll as soon as scroll button is pressed

  • Property mode set to 100644
File size: 15.9 KB
Line 
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/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 button rectangle sets internal field */
136PCUT_TEST(set_rect)
137{
138 ui_pbutton_t *pbutton;
139 gfx_rect_t rect;
140 errno_t rc;
141
142 rc = ui_pbutton_create(NULL, "Hello", &pbutton);
143 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
144
145 rect.p0.x = 1;
146 rect.p0.y = 2;
147 rect.p1.x = 3;
148 rect.p1.y = 4;
149
150 ui_pbutton_set_rect(pbutton, &rect);
151 PCUT_ASSERT_INT_EQUALS(rect.p0.x, pbutton->rect.p0.x);
152 PCUT_ASSERT_INT_EQUALS(rect.p0.y, pbutton->rect.p0.y);
153 PCUT_ASSERT_INT_EQUALS(rect.p1.x, pbutton->rect.p1.x);
154 PCUT_ASSERT_INT_EQUALS(rect.p1.y, pbutton->rect.p1.y);
155
156 ui_pbutton_destroy(pbutton);
157}
158
159/** Set default flag sets internal field */
160PCUT_TEST(set_default)
161{
162 ui_pbutton_t *pbutton;
163 errno_t rc;
164
165 rc = ui_pbutton_create(NULL, "Hello", &pbutton);
166 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
167
168 ui_pbutton_set_default(pbutton, true);
169 PCUT_ASSERT_TRUE(pbutton->isdefault);
170
171 ui_pbutton_set_default(pbutton, false);
172 PCUT_ASSERT_FALSE(pbutton->isdefault);
173
174 ui_pbutton_destroy(pbutton);
175}
176
177/** Paint button */
178PCUT_TEST(paint)
179{
180 errno_t rc;
181 gfx_context_t *gc = NULL;
182 test_gc_t tgc;
183 ui_resource_t *resource = NULL;
184 ui_pbutton_t *pbutton;
185
186 memset(&tgc, 0, sizeof(tgc));
187 rc = gfx_context_new(&ops, &tgc, &gc);
188 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
189
190 rc = ui_resource_create(gc, false, &resource);
191 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
192 PCUT_ASSERT_NOT_NULL(resource);
193
194 rc = ui_pbutton_create(resource, "Hello", &pbutton);
195 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
196
197 rc = ui_pbutton_paint(pbutton);
198 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
199
200 ui_pbutton_destroy(pbutton);
201 ui_resource_destroy(resource);
202
203 rc = gfx_context_delete(gc);
204 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
205}
206
207/** Test ui_pbutton_clicked() */
208PCUT_TEST(clicked)
209{
210 errno_t rc;
211 ui_pbutton_t *pbutton;
212 test_cb_resp_t resp;
213
214 rc = ui_pbutton_create(NULL, "Hello", &pbutton);
215 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
216
217 /* Clicked with no callbacks set */
218 ui_pbutton_clicked(pbutton);
219
220 /* Clicked with callback not implementing clicked */
221 ui_pbutton_set_cb(pbutton, &dummy_pbutton_cb, NULL);
222 ui_pbutton_clicked(pbutton);
223
224 /* Clicked with real callback set */
225 resp.clicked = false;
226 ui_pbutton_set_cb(pbutton, &test_pbutton_cb, &resp);
227 ui_pbutton_clicked(pbutton);
228 PCUT_ASSERT_TRUE(resp.clicked);
229
230 ui_pbutton_destroy(pbutton);
231}
232
233/** Test ui_pbutton_down() */
234PCUT_TEST(down)
235{
236 errno_t rc;
237 ui_pbutton_t *pbutton;
238 test_cb_resp_t resp;
239
240 rc = ui_pbutton_create(NULL, "Hello", &pbutton);
241 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
242
243 /* Down with no callbacks set */
244 ui_pbutton_clicked(pbutton);
245
246 /* Down with callback not implementing down */
247 ui_pbutton_set_cb(pbutton, &dummy_pbutton_cb, NULL);
248 ui_pbutton_down(pbutton);
249
250 /* Down with real callback set */
251 resp.down = false;
252 ui_pbutton_set_cb(pbutton, &test_pbutton_cb, &resp);
253 ui_pbutton_down(pbutton);
254 PCUT_ASSERT_TRUE(resp.down);
255
256 ui_pbutton_destroy(pbutton);
257}
258
259/** Test ui_pbutton_up() */
260PCUT_TEST(up)
261{
262 errno_t rc;
263 ui_pbutton_t *pbutton;
264 test_cb_resp_t resp;
265
266 rc = ui_pbutton_create(NULL, "Hello", &pbutton);
267 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
268
269 /* Up with no callbacks set */
270 ui_pbutton_clicked(pbutton);
271
272 /* Up with callback not implementing up */
273 ui_pbutton_set_cb(pbutton, &dummy_pbutton_cb, NULL);
274 ui_pbutton_up(pbutton);
275
276 /* Up with real callback set */
277 resp.up = false;
278 ui_pbutton_set_cb(pbutton, &test_pbutton_cb, &resp);
279 ui_pbutton_up(pbutton);
280 PCUT_ASSERT_TRUE(resp.up);
281
282 ui_pbutton_destroy(pbutton);
283}
284
285/** Press and release button */
286PCUT_TEST(press_release)
287{
288 errno_t rc;
289 gfx_context_t *gc = NULL;
290 test_gc_t tgc;
291 ui_resource_t *resource = NULL;
292 ui_pbutton_t *pbutton;
293 test_cb_resp_t resp;
294
295 memset(&tgc, 0, sizeof(tgc));
296 rc = gfx_context_new(&ops, &tgc, &gc);
297 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
298
299 rc = ui_resource_create(gc, false, &resource);
300 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
301 PCUT_ASSERT_NOT_NULL(resource);
302
303 rc = ui_pbutton_create(resource, "Hello", &pbutton);
304 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
305
306 resp.clicked = false;
307 resp.down = false;
308 resp.up = false;
309 ui_pbutton_set_cb(pbutton, &test_pbutton_cb, &resp);
310
311 PCUT_ASSERT_FALSE(pbutton->held);
312 PCUT_ASSERT_FALSE(pbutton->inside);
313
314 ui_pbutton_press(pbutton);
315 PCUT_ASSERT_TRUE(pbutton->held);
316 PCUT_ASSERT_TRUE(pbutton->inside);
317 PCUT_ASSERT_TRUE(resp.down);
318 PCUT_ASSERT_FALSE(resp.up);
319 PCUT_ASSERT_FALSE(resp.clicked);
320
321 ui_pbutton_release(pbutton);
322 PCUT_ASSERT_FALSE(pbutton->held);
323 PCUT_ASSERT_TRUE(pbutton->inside);
324 PCUT_ASSERT_TRUE(resp.up);
325 PCUT_ASSERT_TRUE(resp.clicked);
326
327 ui_pbutton_destroy(pbutton);
328 ui_resource_destroy(resource);
329
330 rc = gfx_context_delete(gc);
331 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
332}
333
334/** Press, leave and release button */
335PCUT_TEST(press_leave_release)
336{
337 errno_t rc;
338 gfx_context_t *gc = NULL;
339 test_gc_t tgc;
340 ui_resource_t *resource = NULL;
341 ui_pbutton_t *pbutton;
342 test_cb_resp_t resp;
343
344 memset(&tgc, 0, sizeof(tgc));
345 rc = gfx_context_new(&ops, &tgc, &gc);
346 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
347
348 rc = ui_resource_create(gc, false, &resource);
349 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
350 PCUT_ASSERT_NOT_NULL(resource);
351
352 rc = ui_pbutton_create(resource, "Hello", &pbutton);
353 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
354
355 resp.clicked = false;
356 ui_pbutton_set_cb(pbutton, &test_pbutton_cb, &resp);
357
358 PCUT_ASSERT_FALSE(pbutton->held);
359 PCUT_ASSERT_FALSE(pbutton->inside);
360
361 ui_pbutton_press(pbutton);
362 PCUT_ASSERT_TRUE(pbutton->held);
363 PCUT_ASSERT_TRUE(pbutton->inside);
364 PCUT_ASSERT_FALSE(resp.clicked);
365
366 ui_pbutton_leave(pbutton);
367 PCUT_ASSERT_TRUE(pbutton->held);
368 PCUT_ASSERT_FALSE(pbutton->inside);
369 PCUT_ASSERT_FALSE(resp.clicked);
370
371 ui_pbutton_release(pbutton);
372 PCUT_ASSERT_FALSE(pbutton->held);
373 PCUT_ASSERT_FALSE(pbutton->inside);
374 PCUT_ASSERT_FALSE(resp.clicked);
375
376 ui_pbutton_destroy(pbutton);
377 ui_resource_destroy(resource);
378
379 rc = gfx_context_delete(gc);
380 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
381}
382
383/** Press, leave, enter and release button */
384PCUT_TEST(press_leave_enter_release)
385{
386 errno_t rc;
387 gfx_context_t *gc = NULL;
388 test_gc_t tgc;
389 ui_resource_t *resource = NULL;
390 ui_pbutton_t *pbutton;
391 test_cb_resp_t resp;
392
393 memset(&tgc, 0, sizeof(tgc));
394 rc = gfx_context_new(&ops, &tgc, &gc);
395 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
396
397 rc = ui_resource_create(gc, false, &resource);
398 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
399 PCUT_ASSERT_NOT_NULL(resource);
400
401 rc = ui_pbutton_create(resource, "Hello", &pbutton);
402 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
403
404 resp.clicked = false;
405 ui_pbutton_set_cb(pbutton, &test_pbutton_cb, &resp);
406
407 PCUT_ASSERT_FALSE(pbutton->held);
408 PCUT_ASSERT_FALSE(pbutton->inside);
409
410 ui_pbutton_press(pbutton);
411 PCUT_ASSERT_TRUE(pbutton->held);
412 PCUT_ASSERT_TRUE(pbutton->inside);
413 PCUT_ASSERT_FALSE(resp.clicked);
414
415 ui_pbutton_leave(pbutton);
416 PCUT_ASSERT_TRUE(pbutton->held);
417 PCUT_ASSERT_FALSE(pbutton->inside);
418 PCUT_ASSERT_FALSE(resp.clicked);
419
420 ui_pbutton_enter(pbutton);
421 PCUT_ASSERT_TRUE(pbutton->held);
422 PCUT_ASSERT_TRUE(pbutton->inside);
423 PCUT_ASSERT_FALSE(resp.clicked);
424
425 ui_pbutton_release(pbutton);
426 PCUT_ASSERT_FALSE(pbutton->held);
427 PCUT_ASSERT_TRUE(pbutton->inside);
428 PCUT_ASSERT_TRUE(resp.clicked);
429
430 ui_pbutton_destroy(pbutton);
431 ui_resource_destroy(resource);
432
433 rc = gfx_context_delete(gc);
434 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
435}
436
437/** ui_pos_event() correctly translates POS_PRESS/POS_RELEASE */
438PCUT_TEST(pos_event_press_release)
439{
440 errno_t rc;
441 gfx_context_t *gc = NULL;
442 test_gc_t tgc;
443 ui_resource_t *resource = NULL;
444 ui_pbutton_t *pbutton;
445 ui_evclaim_t claim;
446 pos_event_t event;
447 gfx_rect_t rect;
448
449 memset(&tgc, 0, sizeof(tgc));
450 rc = gfx_context_new(&ops, &tgc, &gc);
451 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
452
453 rc = ui_resource_create(gc, false, &resource);
454 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
455 PCUT_ASSERT_NOT_NULL(resource);
456
457 rc = ui_pbutton_create(resource, "Hello", &pbutton);
458 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
459
460 PCUT_ASSERT_FALSE(pbutton->held);
461
462 rect.p0.x = 10;
463 rect.p0.y = 20;
464 rect.p1.x = 30;
465 rect.p1.y = 40;
466 ui_pbutton_set_rect(pbutton, &rect);
467
468 /* Press outside is not claimed and does nothing */
469 event.type = POS_PRESS;
470 event.hpos = 9;
471 event.vpos = 20;
472 claim = ui_pbutton_pos_event(pbutton, &event);
473 PCUT_ASSERT_FALSE(pbutton->held);
474 PCUT_ASSERT_EQUALS(ui_unclaimed, claim);
475
476 /* Press inside is claimed and depresses button */
477 event.type = POS_PRESS;
478 event.hpos = 10;
479 event.vpos = 20;
480 claim = ui_pbutton_pos_event(pbutton, &event);
481 PCUT_ASSERT_TRUE(pbutton->held);
482 PCUT_ASSERT_EQUALS(ui_claimed, claim);
483
484 /* Release outside (or anywhere) is claimed and relases button */
485 event.type = POS_RELEASE;
486 event.hpos = 9;
487 event.vpos = 20;
488 claim = ui_pbutton_pos_event(pbutton, &event);
489 PCUT_ASSERT_FALSE(pbutton->held);
490 PCUT_ASSERT_EQUALS(ui_claimed, claim);
491
492 ui_pbutton_destroy(pbutton);
493 ui_resource_destroy(resource);
494
495 rc = gfx_context_delete(gc);
496 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
497}
498
499/** ui_pos_event() correctly translates POS_UPDATE to enter/leave */
500PCUT_TEST(pos_event_enter_leave)
501{
502 errno_t rc;
503 gfx_context_t *gc = NULL;
504 test_gc_t tgc;
505 ui_resource_t *resource = NULL;
506 ui_pbutton_t *pbutton;
507 pos_event_t event;
508 gfx_rect_t rect;
509
510 memset(&tgc, 0, sizeof(tgc));
511 rc = gfx_context_new(&ops, &tgc, &gc);
512 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
513
514 rc = ui_resource_create(gc, false, &resource);
515 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
516 PCUT_ASSERT_NOT_NULL(resource);
517
518 rc = ui_pbutton_create(resource, "Hello", &pbutton);
519 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
520
521 PCUT_ASSERT_FALSE(pbutton->inside);
522
523 rect.p0.x = 10;
524 rect.p0.y = 20;
525 rect.p1.x = 30;
526 rect.p1.y = 40;
527 ui_pbutton_set_rect(pbutton, &rect);
528
529 /* Moving outside does nothing */
530 event.type = POS_UPDATE;
531 event.hpos = 9;
532 event.vpos = 20;
533 ui_pbutton_pos_event(pbutton, &event);
534 PCUT_ASSERT_FALSE(pbutton->inside);
535
536 /* Moving inside sets inside flag */
537 event.type = POS_UPDATE;
538 event.hpos = 10;
539 event.vpos = 20;
540 ui_pbutton_pos_event(pbutton, &event);
541 PCUT_ASSERT_TRUE(pbutton->inside);
542
543 /* Moving outside clears inside flag */
544 event.type = POS_UPDATE;
545 event.hpos = 9;
546 event.vpos = 20;
547 ui_pbutton_pos_event(pbutton, &event);
548 PCUT_ASSERT_FALSE(pbutton->inside);
549
550 ui_pbutton_destroy(pbutton);
551 ui_resource_destroy(resource);
552
553 rc = gfx_context_delete(gc);
554 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
555}
556
557static errno_t testgc_set_clip_rect(void *arg, gfx_rect_t *rect)
558{
559 (void) arg;
560 (void) rect;
561 return EOK;
562}
563
564static errno_t testgc_set_color(void *arg, gfx_color_t *color)
565{
566 (void) arg;
567 (void) color;
568 return EOK;
569}
570
571static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect)
572{
573 (void) arg;
574 (void) rect;
575 return EOK;
576}
577
578static errno_t testgc_update(void *arg)
579{
580 (void) arg;
581 return EOK;
582}
583
584static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params,
585 gfx_bitmap_alloc_t *alloc, void **rbm)
586{
587 test_gc_t *tgc = (test_gc_t *) arg;
588 testgc_bitmap_t *tbm;
589
590 tbm = calloc(1, sizeof(testgc_bitmap_t));
591 if (tbm == NULL)
592 return ENOMEM;
593
594 if (alloc == NULL) {
595 tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) *
596 sizeof(uint32_t);
597 tbm->alloc.off0 = 0;
598 tbm->alloc.pixels = calloc(sizeof(uint32_t),
599 (params->rect.p1.x - params->rect.p0.x) *
600 (params->rect.p1.y - params->rect.p0.y));
601 tbm->myalloc = true;
602 if (tbm->alloc.pixels == NULL) {
603 free(tbm);
604 return ENOMEM;
605 }
606 } else {
607 tbm->alloc = *alloc;
608 }
609
610 tbm->tgc = tgc;
611 tgc->bm_created = true;
612 tgc->bm_params = *params;
613 tgc->bm_pixels = tbm->alloc.pixels;
614 *rbm = (void *)tbm;
615 return EOK;
616}
617
618static errno_t testgc_bitmap_destroy(void *bm)
619{
620 testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
621 if (tbm->myalloc)
622 free(tbm->alloc.pixels);
623 tbm->tgc->bm_destroyed = true;
624 free(tbm);
625 return EOK;
626}
627
628static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect,
629 gfx_coord2_t *offs)
630{
631 testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
632 tbm->tgc->bm_rendered = true;
633 tbm->tgc->bm_srect = *srect;
634 tbm->tgc->bm_offs = *offs;
635 return EOK;
636}
637
638static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc)
639{
640 testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm;
641 *alloc = tbm->alloc;
642 tbm->tgc->bm_got_alloc = true;
643 return EOK;
644}
645
646static void test_pbutton_clicked(ui_pbutton_t *pbutton, void *arg)
647{
648 test_cb_resp_t *resp = (test_cb_resp_t *) arg;
649
650 resp->clicked = true;
651}
652
653static void test_pbutton_down(ui_pbutton_t *pbutton, void *arg)
654{
655 test_cb_resp_t *resp = (test_cb_resp_t *) arg;
656
657 resp->down = true;
658}
659
660static void test_pbutton_up(ui_pbutton_t *pbutton, void *arg)
661{
662 test_cb_resp_t *resp = (test_cb_resp_t *) arg;
663
664 resp->up = true;
665}
666
667PCUT_EXPORT(pbutton);
Note: See TracBrowser for help on using the repository browser.