Changeset 2d879f7 in mainline for uspace/lib/ui/test/wdecor.c
- Timestamp:
- 2020-11-26T11:59:59Z (5 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 554a5f1
- Parents:
- d8ddf7a
- git-author:
- Jiri Svoboda <jiri@…> (2020-11-25 18:46:07)
- git-committer:
- Jiri Svoboda <jiri@…> (2020-11-26 11:59:59)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/test/wdecor.c
rd8ddf7a r2d879f7 60 60 static void test_wdecor_close(ui_wdecor_t *, void *); 61 61 static void test_wdecor_move(ui_wdecor_t *, void *, gfx_coord2_t *); 62 static void test_wdecor_resize(ui_wdecor_t *, void *, ui_wdecor_rsztype_t, 63 gfx_coord2_t *); 64 static void test_wdecor_set_cursor(ui_wdecor_t *, void *, ui_stock_cursor_t); 62 65 63 66 static ui_wdecor_cb_t test_wdecor_cb = { 64 67 .close = test_wdecor_close, 65 .move = test_wdecor_move 68 .move = test_wdecor_move, 69 .resize = test_wdecor_resize, 70 .set_cursor = test_wdecor_set_cursor 66 71 }; 67 72 … … 90 95 bool move; 91 96 gfx_coord2_t pos; 97 bool resize; 98 ui_wdecor_rsztype_t rsztype; 99 bool set_cursor; 100 ui_stock_cursor_t cursor; 92 101 } test_cb_resp_t; 93 102 … … 98 107 errno_t rc; 99 108 100 rc = ui_wdecor_create(NULL, "Hello", &wdecor);109 rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor); 101 110 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 102 111 PCUT_ASSERT_NOT_NULL(wdecor); … … 118 127 errno_t rc; 119 128 120 rc = ui_wdecor_create(NULL, "Hello", &wdecor);129 rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor); 121 130 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 122 131 … … 141 150 errno_t rc; 142 151 143 rc = ui_wdecor_create(NULL, "Hello", &wdecor);152 rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor); 144 153 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 145 154 … … 172 181 PCUT_ASSERT_NOT_NULL(resource); 173 182 174 rc = ui_wdecor_create(resource, "Hello", &wdecor);183 rc = ui_wdecor_create(resource, "Hello", ui_wds_none, &wdecor); 175 184 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 176 185 … … 192 201 test_cb_resp_t resp; 193 202 194 rc = ui_wdecor_create(NULL, "Hello", &wdecor);203 rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor); 195 204 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 196 205 … … 219 228 gfx_coord2_t pos; 220 229 221 rc = ui_wdecor_create(NULL, "Hello", &wdecor);230 rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor); 222 231 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 223 232 … … 245 254 } 246 255 256 /** Test ui_wdecor_resize() */ 257 PCUT_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() */ 295 PCUT_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 247 325 /** Clicking the close button generates close callback */ 248 326 PCUT_TEST(close_btn_clicked) … … 253 331 errno_t rc; 254 332 255 rc = ui_wdecor_create(NULL, "Hello", &wdecor);333 rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor); 256 334 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 257 335 … … 282 360 errno_t rc; 283 361 284 rc = ui_wdecor_create(NULL, "Hello", &wdecor);362 rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor); 285 363 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 286 364 … … 318 396 errno_t rc; 319 397 320 rc = ui_wdecor_create(NULL, "Hello", &wdecor);398 rc = ui_wdecor_create(NULL, "Hello", ui_wds_none, &wdecor); 321 399 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 322 400 … … 369 447 PCUT_ASSERT_INT_EQUALS(100, rect.p1.x); 370 448 PCUT_ASSERT_INT_EQUALS(200, rect.p1.y); 449 } 450 451 /** Test ui_wdecor_get_rsztype() */ 452 PCUT_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() */ 559 PCUT_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() */ 582 PCUT_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); 371 626 } 372 627 … … 462 717 } 463 718 719 static 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 729 static 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 464 738 PCUT_EXPORT(wdecor);
Note:
See TracChangeset
for help on using the changeset viewer.