Changes in uspace/lib/ui/test/pbutton.c [1fa6292:3583ffb] in mainline
- File:
-
- 1 edited
-
uspace/lib/ui/test/pbutton.c (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/test/pbutton.c
r1fa6292 r3583ffb 1 1 /* 2 * Copyright (c) 202 3Jiri Svoboda2 * Copyright (c) 2020 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 36 36 #include <ui/resource.h> 37 37 #include "../private/pbutton.h" 38 #include "../private/testgc.h"39 38 40 39 PCUT_INIT; … … 42 41 PCUT_TEST_SUITE(pbutton); 43 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_bitmap_create(void *, gfx_bitmap_params_t *, 46 gfx_bitmap_alloc_t *, void **); 47 static errno_t testgc_bitmap_destroy(void *); 48 static errno_t testgc_bitmap_render(void *, gfx_rect_t *, gfx_coord2_t *); 49 static errno_t testgc_bitmap_get_alloc(void *, gfx_bitmap_alloc_t *); 50 51 static 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 44 60 static void test_pbutton_clicked(ui_pbutton_t *, void *); 45 static void test_pbutton_down(ui_pbutton_t *, void *);46 static void test_pbutton_up(ui_pbutton_t *, void *);47 61 48 62 static ui_pbutton_cb_t test_pbutton_cb = { 49 .clicked = test_pbutton_clicked, 50 .down = test_pbutton_down, 51 .up = test_pbutton_up 63 .clicked = test_pbutton_clicked 52 64 }; 53 65 … … 56 68 57 69 typedef struct { 70 bool bm_created; 71 bool bm_destroyed; 72 gfx_bitmap_params_t bm_params; 73 void *bm_pixels; 74 gfx_rect_t bm_srect; 75 gfx_coord2_t bm_offs; 76 bool bm_rendered; 77 bool bm_got_alloc; 78 } test_gc_t; 79 80 typedef struct { 81 test_gc_t *tgc; 82 gfx_bitmap_alloc_t alloc; 83 bool myalloc; 84 } testgc_bitmap_t; 85 86 typedef struct { 58 87 bool clicked; 59 bool down;60 bool up;61 88 } test_cb_resp_t; 62 89 … … 94 121 95 122 ui_control_destroy(control); 96 }97 98 /** Set flags sets internal field */99 PCUT_TEST(set_flags)100 {101 ui_pbutton_t *pbutton;102 errno_t rc;103 104 rc = ui_pbutton_create(NULL, "Hello", &pbutton);105 PCUT_ASSERT_ERRNO_VAL(EOK, rc);106 107 ui_pbutton_set_flags(pbutton, ui_pbf_no_text_depress);108 PCUT_ASSERT_INT_EQUALS(ui_pbf_no_text_depress, pbutton->flags);109 110 ui_pbutton_destroy(pbutton);111 123 } 112 124 … … 153 165 } 154 166 155 /** Get light gets internal field */156 PCUT_TEST(get_light)157 {158 ui_pbutton_t *pbutton;159 errno_t rc;160 161 rc = ui_pbutton_create(NULL, "Hello", &pbutton);162 PCUT_ASSERT_ERRNO_VAL(EOK, rc);163 164 pbutton->light = true;165 PCUT_ASSERT_TRUE(ui_pbutton_get_light(pbutton));166 167 pbutton->light = false;168 PCUT_ASSERT_FALSE(ui_pbutton_get_light(pbutton));169 170 ui_pbutton_destroy(pbutton);171 }172 173 /** Set light sets internal field */174 PCUT_TEST(set_light)175 {176 ui_pbutton_t *pbutton;177 errno_t rc;178 179 rc = ui_pbutton_create(NULL, "Hello", &pbutton);180 PCUT_ASSERT_ERRNO_VAL(EOK, rc);181 182 ui_pbutton_set_light(pbutton, true);183 PCUT_ASSERT_TRUE(pbutton->light);184 185 ui_pbutton_set_light(pbutton, false);186 PCUT_ASSERT_FALSE(pbutton->light);187 188 ui_pbutton_destroy(pbutton);189 }190 191 /** Set caption sets internal field */192 PCUT_TEST(set_caption)193 {194 ui_pbutton_t *pbutton;195 errno_t rc;196 197 rc = ui_pbutton_create(NULL, "Hello", &pbutton);198 PCUT_ASSERT_ERRNO_VAL(EOK, rc);199 200 PCUT_ASSERT_STR_EQUALS("Hello", pbutton->caption);201 202 rc = ui_pbutton_set_caption(pbutton, "World");203 PCUT_ASSERT_ERRNO_VAL(EOK, rc);204 205 PCUT_ASSERT_STR_EQUALS("World", pbutton->caption);206 207 ui_pbutton_destroy(pbutton);208 }209 210 167 /** Paint button */ 211 168 PCUT_TEST(paint) … … 221 178 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 222 179 223 rc = ui_resource_create(gc, false,&resource);180 rc = ui_resource_create(gc, &resource); 224 181 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 225 182 PCUT_ASSERT_NOT_NULL(resource); … … 264 221 } 265 222 266 /** Test ui_pbutton_down() */267 PCUT_TEST(down)268 {269 errno_t rc;270 ui_pbutton_t *pbutton;271 test_cb_resp_t resp;272 273 rc = ui_pbutton_create(NULL, "Hello", &pbutton);274 PCUT_ASSERT_ERRNO_VAL(EOK, rc);275 276 /* Down with no callbacks set */277 ui_pbutton_clicked(pbutton);278 279 /* Down with callback not implementing down */280 ui_pbutton_set_cb(pbutton, &dummy_pbutton_cb, NULL);281 ui_pbutton_down(pbutton);282 283 /* Down with real callback set */284 resp.down = false;285 ui_pbutton_set_cb(pbutton, &test_pbutton_cb, &resp);286 ui_pbutton_down(pbutton);287 PCUT_ASSERT_TRUE(resp.down);288 289 ui_pbutton_destroy(pbutton);290 }291 292 /** Test ui_pbutton_up() */293 PCUT_TEST(up)294 {295 errno_t rc;296 ui_pbutton_t *pbutton;297 test_cb_resp_t resp;298 299 rc = ui_pbutton_create(NULL, "Hello", &pbutton);300 PCUT_ASSERT_ERRNO_VAL(EOK, rc);301 302 /* Up with no callbacks set */303 ui_pbutton_clicked(pbutton);304 305 /* Up with callback not implementing up */306 ui_pbutton_set_cb(pbutton, &dummy_pbutton_cb, NULL);307 ui_pbutton_up(pbutton);308 309 /* Up with real callback set */310 resp.up = false;311 ui_pbutton_set_cb(pbutton, &test_pbutton_cb, &resp);312 ui_pbutton_up(pbutton);313 PCUT_ASSERT_TRUE(resp.up);314 315 ui_pbutton_destroy(pbutton);316 }317 318 223 /** Press and release button */ 319 224 PCUT_TEST(press_release) … … 330 235 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 331 236 332 rc = ui_resource_create(gc, false,&resource);237 rc = ui_resource_create(gc, &resource); 333 238 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 334 239 PCUT_ASSERT_NOT_NULL(resource); … … 338 243 339 244 resp.clicked = false; 340 resp.down = false;341 resp.up = false;342 245 ui_pbutton_set_cb(pbutton, &test_pbutton_cb, &resp); 343 246 … … 348 251 PCUT_ASSERT_TRUE(pbutton->held); 349 252 PCUT_ASSERT_TRUE(pbutton->inside); 350 PCUT_ASSERT_TRUE(resp.down);351 PCUT_ASSERT_FALSE(resp.up);352 253 PCUT_ASSERT_FALSE(resp.clicked); 353 254 … … 355 256 PCUT_ASSERT_FALSE(pbutton->held); 356 257 PCUT_ASSERT_TRUE(pbutton->inside); 357 PCUT_ASSERT_TRUE(resp.up);358 258 PCUT_ASSERT_TRUE(resp.clicked); 359 259 … … 379 279 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 380 280 381 rc = ui_resource_create(gc, false,&resource);281 rc = ui_resource_create(gc, &resource); 382 282 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 383 283 PCUT_ASSERT_NOT_NULL(resource); … … 428 328 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 429 329 430 rc = ui_resource_create(gc, false,&resource);330 rc = ui_resource_create(gc, &resource); 431 331 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 432 332 PCUT_ASSERT_NOT_NULL(resource); … … 484 384 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 485 385 486 rc = ui_resource_create(gc, false,&resource);386 rc = ui_resource_create(gc, &resource); 487 387 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 488 388 PCUT_ASSERT_NOT_NULL(resource); … … 545 445 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 546 446 547 rc = ui_resource_create(gc, false,&resource);447 rc = ui_resource_create(gc, &resource); 548 448 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 549 449 PCUT_ASSERT_NOT_NULL(resource); … … 588 488 } 589 489 490 static errno_t testgc_set_color(void *arg, gfx_color_t *color) 491 { 492 (void) arg; 493 (void) color; 494 return EOK; 495 } 496 497 static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect) 498 { 499 (void) arg; 500 (void) rect; 501 return EOK; 502 } 503 504 static errno_t testgc_bitmap_create(void *arg, gfx_bitmap_params_t *params, 505 gfx_bitmap_alloc_t *alloc, void **rbm) 506 { 507 test_gc_t *tgc = (test_gc_t *) arg; 508 testgc_bitmap_t *tbm; 509 510 tbm = calloc(1, sizeof(testgc_bitmap_t)); 511 if (tbm == NULL) 512 return ENOMEM; 513 514 if (alloc == NULL) { 515 tbm->alloc.pitch = (params->rect.p1.x - params->rect.p0.x) * 516 sizeof(uint32_t); 517 tbm->alloc.off0 = 0; 518 tbm->alloc.pixels = calloc(sizeof(uint32_t), 519 (params->rect.p1.x - params->rect.p0.x) * 520 (params->rect.p1.y - params->rect.p0.y)); 521 tbm->myalloc = true; 522 if (tbm->alloc.pixels == NULL) { 523 free(tbm); 524 return ENOMEM; 525 } 526 } else { 527 tbm->alloc = *alloc; 528 } 529 530 tbm->tgc = tgc; 531 tgc->bm_created = true; 532 tgc->bm_params = *params; 533 tgc->bm_pixels = tbm->alloc.pixels; 534 *rbm = (void *)tbm; 535 return EOK; 536 } 537 538 static errno_t testgc_bitmap_destroy(void *bm) 539 { 540 testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm; 541 if (tbm->myalloc) 542 free(tbm->alloc.pixels); 543 tbm->tgc->bm_destroyed = true; 544 free(tbm); 545 return EOK; 546 } 547 548 static errno_t testgc_bitmap_render(void *bm, gfx_rect_t *srect, 549 gfx_coord2_t *offs) 550 { 551 testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm; 552 tbm->tgc->bm_rendered = true; 553 tbm->tgc->bm_srect = *srect; 554 tbm->tgc->bm_offs = *offs; 555 return EOK; 556 } 557 558 static errno_t testgc_bitmap_get_alloc(void *bm, gfx_bitmap_alloc_t *alloc) 559 { 560 testgc_bitmap_t *tbm = (testgc_bitmap_t *)bm; 561 *alloc = tbm->alloc; 562 tbm->tgc->bm_got_alloc = true; 563 return EOK; 564 } 565 590 566 static void test_pbutton_clicked(ui_pbutton_t *pbutton, void *arg) 591 567 { … … 595 571 } 596 572 597 static void test_pbutton_down(ui_pbutton_t *pbutton, void *arg)598 {599 test_cb_resp_t *resp = (test_cb_resp_t *) arg;600 601 resp->down = true;602 }603 604 static void test_pbutton_up(ui_pbutton_t *pbutton, void *arg)605 {606 test_cb_resp_t *resp = (test_cb_resp_t *) arg;607 608 resp->up = true;609 }610 611 573 PCUT_EXPORT(pbutton);
Note:
See TracChangeset
for help on using the changeset viewer.
