Changeset 3583ffb in mainline for uspace/lib/ui/test/pbutton.c
- Timestamp:
- 2020-11-08T19:51:04Z (3 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f93e4e3
- Parents:
- 8c772c4
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/test/pbutton.c
r8c772c4 r3583ffb 34 34 #include <ui/control.h> 35 35 #include <ui/pbutton.h> 36 #include <ui/ ui.h>36 #include <ui/resource.h> 37 37 #include "../private/pbutton.h" 38 38 … … 40 40 41 41 PCUT_TEST_SUITE(pbutton); 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 }; 42 59 43 60 static void test_pbutton_clicked(ui_pbutton_t *, void *); … … 49 66 static ui_pbutton_cb_t dummy_pbutton_cb = { 50 67 }; 68 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; 51 85 52 86 typedef struct { … … 135 169 { 136 170 errno_t rc; 137 ui_t *ui; 138 ui_pbutton_t *pbutton; 139 140 rc = ui_create_disp(NULL, &ui); 141 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 142 143 rc = ui_pbutton_create(ui, "Hello", &pbutton); 171 gfx_context_t *gc = NULL; 172 test_gc_t tgc; 173 ui_resource_t *resource = NULL; 174 ui_pbutton_t *pbutton; 175 176 memset(&tgc, 0, sizeof(tgc)); 177 rc = gfx_context_new(&ops, &tgc, &gc); 178 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 179 180 rc = ui_resource_create(gc, &resource); 181 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 182 PCUT_ASSERT_NOT_NULL(resource); 183 184 rc = ui_pbutton_create(resource, "Hello", &pbutton); 144 185 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 145 186 … … 148 189 149 190 ui_pbutton_destroy(pbutton); 150 ui_destroy(ui); 191 ui_resource_destroy(resource); 192 193 rc = gfx_context_delete(gc); 194 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 151 195 } 152 196 … … 181 225 { 182 226 errno_t rc; 183 ui_t *ui; 227 gfx_context_t *gc = NULL; 228 test_gc_t tgc; 229 ui_resource_t *resource = NULL; 184 230 ui_pbutton_t *pbutton; 185 231 test_cb_resp_t resp; 186 232 187 rc = ui_create_disp(NULL, &ui); 188 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 189 190 rc = ui_pbutton_create(ui, "Hello", &pbutton); 233 memset(&tgc, 0, sizeof(tgc)); 234 rc = gfx_context_new(&ops, &tgc, &gc); 235 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 236 237 rc = ui_resource_create(gc, &resource); 238 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 239 PCUT_ASSERT_NOT_NULL(resource); 240 241 rc = ui_pbutton_create(resource, "Hello", &pbutton); 191 242 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 192 243 … … 208 259 209 260 ui_pbutton_destroy(pbutton); 210 ui_destroy(ui); 261 ui_resource_destroy(resource); 262 263 rc = gfx_context_delete(gc); 264 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 211 265 } 212 266 … … 215 269 { 216 270 errno_t rc; 217 ui_t *ui; 271 gfx_context_t *gc = NULL; 272 test_gc_t tgc; 273 ui_resource_t *resource = NULL; 218 274 ui_pbutton_t *pbutton; 219 275 test_cb_resp_t resp; 220 276 221 rc = ui_create_disp(NULL, &ui); 222 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 223 224 rc = ui_pbutton_create(ui, "Hello", &pbutton); 277 memset(&tgc, 0, sizeof(tgc)); 278 rc = gfx_context_new(&ops, &tgc, &gc); 279 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 280 281 rc = ui_resource_create(gc, &resource); 282 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 283 PCUT_ASSERT_NOT_NULL(resource); 284 285 rc = ui_pbutton_create(resource, "Hello", &pbutton); 225 286 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 226 287 … … 247 308 248 309 ui_pbutton_destroy(pbutton); 249 ui_destroy(ui); 310 ui_resource_destroy(resource); 311 312 rc = gfx_context_delete(gc); 313 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 250 314 } 251 315 … … 254 318 { 255 319 errno_t rc; 256 ui_t *ui; 320 gfx_context_t *gc = NULL; 321 test_gc_t tgc; 322 ui_resource_t *resource = NULL; 257 323 ui_pbutton_t *pbutton; 258 324 test_cb_resp_t resp; 259 325 260 rc = ui_create_disp(NULL, &ui); 261 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 262 263 rc = ui_pbutton_create(ui, "Hello", &pbutton); 326 memset(&tgc, 0, sizeof(tgc)); 327 rc = gfx_context_new(&ops, &tgc, &gc); 328 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 329 330 rc = ui_resource_create(gc, &resource); 331 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 332 PCUT_ASSERT_NOT_NULL(resource); 333 334 rc = ui_pbutton_create(resource, "Hello", &pbutton); 264 335 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 265 336 … … 291 362 292 363 ui_pbutton_destroy(pbutton); 293 ui_destroy(ui); 364 ui_resource_destroy(resource); 365 366 rc = gfx_context_delete(gc); 367 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 294 368 } 295 369 … … 298 372 { 299 373 errno_t rc; 300 ui_t *ui; 374 gfx_context_t *gc = NULL; 375 test_gc_t tgc; 376 ui_resource_t *resource = NULL; 301 377 ui_pbutton_t *pbutton; 302 378 ui_evclaim_t claim; … … 304 380 gfx_rect_t rect; 305 381 306 rc = ui_create_disp(NULL, &ui); 307 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 308 309 rc = ui_pbutton_create(ui, "Hello", &pbutton); 382 memset(&tgc, 0, sizeof(tgc)); 383 rc = gfx_context_new(&ops, &tgc, &gc); 384 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 385 386 rc = ui_resource_create(gc, &resource); 387 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 388 PCUT_ASSERT_NOT_NULL(resource); 389 390 rc = ui_pbutton_create(resource, "Hello", &pbutton); 310 391 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 311 392 … … 343 424 344 425 ui_pbutton_destroy(pbutton); 345 ui_destroy(ui); 426 ui_resource_destroy(resource); 427 428 rc = gfx_context_delete(gc); 429 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 346 430 } 347 431 … … 350 434 { 351 435 errno_t rc; 352 ui_t *ui; 436 gfx_context_t *gc = NULL; 437 test_gc_t tgc; 438 ui_resource_t *resource = NULL; 353 439 ui_pbutton_t *pbutton; 354 440 pos_event_t event; 355 441 gfx_rect_t rect; 356 442 357 rc = ui_create_disp(NULL, &ui); 358 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 359 360 rc = ui_pbutton_create(ui, "Hello", &pbutton); 443 memset(&tgc, 0, sizeof(tgc)); 444 rc = gfx_context_new(&ops, &tgc, &gc); 445 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 446 447 rc = ui_resource_create(gc, &resource); 448 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 449 PCUT_ASSERT_NOT_NULL(resource); 450 451 rc = ui_pbutton_create(resource, "Hello", &pbutton); 361 452 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 362 453 … … 391 482 392 483 ui_pbutton_destroy(pbutton); 393 ui_destroy(ui); 484 ui_resource_destroy(resource); 485 486 rc = gfx_context_delete(gc); 487 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 488 } 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; 394 564 } 395 565
Note:
See TracChangeset
for help on using the changeset viewer.