Changes in uspace/srv/hid/display/test/display.c [9e84d2c:b3eeae5] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/display/test/display.c
r9e84d2c rb3eeae5 1 1 /* 2 * Copyright (c) 20 19Jiri Svoboda2 * Copyright (c) 2023 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 32 32 #include <str.h> 33 33 34 #include "../cfgclient.h" 34 35 #include "../client.h" 35 36 #include "../display.h" 37 #include "../idevcfg.h" 36 38 #include "../seat.h" 37 39 #include "../window.h" 40 #include "../wmclient.h" 38 41 39 42 PCUT_INIT; … … 47 50 }; 48 51 52 static void test_ds_wmev_pending(void *); 53 54 static ds_wmclient_cb_t test_ds_wmclient_cb = { 55 .ev_pending = test_ds_wmev_pending 56 }; 57 58 static void test_ds_cfgev_pending(void *); 59 60 static ds_cfgclient_cb_t test_ds_cfgclient_cb = { 61 .ev_pending = test_ds_cfgev_pending 62 }; 63 49 64 static void test_ds_ev_pending(void *arg) 50 65 { … … 53 68 } 54 69 70 static void test_ds_wmev_pending(void *arg) 71 { 72 bool *called_cb = (bool *) arg; 73 *called_cb = true; 74 } 75 76 static void test_ds_cfgev_pending(void *arg) 77 { 78 bool *called_cb = (bool *) arg; 79 *called_cb = true; 80 } 81 55 82 /** Display creation and destruction. */ 56 83 PCUT_TEST(display_create_destroy) … … 86 113 87 114 ds_client_destroy(client); 115 ds_display_destroy(disp); 116 } 117 118 /** Basic WM client operation. */ 119 PCUT_TEST(display_wmclient) 120 { 121 ds_display_t *disp; 122 ds_wmclient_t *wmclient; 123 ds_wmclient_t *c0, *c1; 124 errno_t rc; 125 126 rc = ds_display_create(NULL, df_none, &disp); 127 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 128 129 rc = ds_wmclient_create(disp, &test_ds_wmclient_cb, NULL, &wmclient); 130 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 131 132 c0 = ds_display_first_wmclient(disp); 133 PCUT_ASSERT_EQUALS(c0, wmclient); 134 135 c1 = ds_display_next_wmclient(c0); 136 PCUT_ASSERT_NULL(c1); 137 138 ds_wmclient_destroy(wmclient); 139 ds_display_destroy(disp); 140 } 141 142 /** Basic CFG client operation. */ 143 PCUT_TEST(display_cfgclient) 144 { 145 ds_display_t *disp; 146 ds_cfgclient_t *cfgclient; 147 errno_t rc; 148 149 rc = ds_display_create(NULL, df_none, &disp); 150 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 151 152 rc = ds_cfgclient_create(disp, &test_ds_cfgclient_cb, NULL, &cfgclient); 153 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 154 155 ds_cfgclient_destroy(cfgclient); 88 156 ds_display_destroy(disp); 89 157 } … … 108 176 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 109 177 110 rc = ds_seat_create(disp, &seat);178 rc = ds_seat_create(disp, "Alice", &seat); 111 179 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 112 180 … … 150 218 wnd = ds_display_find_window(disp, w0->id + 1); 151 219 PCUT_ASSERT_NULL(wnd); 220 221 ds_window_destroy(w0); 222 ds_window_destroy(w1); 223 ds_seat_destroy(seat); 224 ds_client_destroy(client); 225 ds_display_destroy(disp); 226 } 227 228 /** Test ds_display_enlist_window() */ 229 PCUT_TEST(display_enlist_window) 230 { 231 ds_display_t *disp; 232 ds_client_t *client; 233 ds_seat_t *seat; 234 ds_window_t *w0; 235 ds_window_t *w1; 236 ds_window_t *w2; 237 ds_window_t *w3; 238 ds_window_t *w; 239 display_wnd_params_t params; 240 bool called_cb = false; 241 errno_t rc; 242 243 rc = ds_display_create(NULL, df_none, &disp); 244 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 245 246 rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client); 247 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 248 249 rc = ds_seat_create(disp, "Alice", &seat); 250 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 251 252 display_wnd_params_init(¶ms); 253 params.rect.p0.x = params.rect.p0.y = 0; 254 params.rect.p1.x = params.rect.p1.y = 100; 255 256 /* Regular windows */ 257 258 rc = ds_window_create(client, ¶ms, &w0); 259 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 260 261 rc = ds_window_create(client, ¶ms, &w1); 262 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 263 264 /* Topmost windows */ 265 266 params.flags |= wndf_topmost; 267 268 rc = ds_window_create(client, ¶ms, &w2); 269 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 270 271 rc = ds_window_create(client, ¶ms, &w3); 272 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 273 274 /* Delist w1 and w2 */ 275 list_remove(&w1->ldwindows); 276 list_remove(&w2->ldwindows); 277 278 /* Enlist the windows back and check their order */ 279 ds_display_enlist_window(disp, w1); 280 ds_display_enlist_window(disp, w2); 281 282 w = ds_display_first_window(disp); 283 PCUT_ASSERT_EQUALS(w2, w); 284 w = ds_display_next_window(w); 285 PCUT_ASSERT_EQUALS(w3, w); 286 w = ds_display_next_window(w); 287 PCUT_ASSERT_EQUALS(w1, w); 288 w = ds_display_next_window(w); 289 PCUT_ASSERT_EQUALS(w0, w); 290 w = ds_display_next_window(w); 291 PCUT_ASSERT_EQUALS(NULL, w); 292 293 ds_window_destroy(w0); 294 ds_window_destroy(w1); 295 ds_window_destroy(w2); 296 ds_window_destroy(w3); 297 ds_seat_destroy(seat); 298 ds_client_destroy(client); 299 ds_display_destroy(disp); 300 } 301 302 /** Test ds_display_window_to_top() */ 303 PCUT_TEST(display_window_to_top) 304 { 305 ds_display_t *disp; 306 ds_client_t *client; 307 ds_seat_t *seat; 308 ds_window_t *w0; 309 ds_window_t *w1; 310 display_wnd_params_t params; 311 bool called_cb = false; 312 errno_t rc; 313 314 rc = ds_display_create(NULL, df_none, &disp); 315 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 316 317 rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client); 318 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 319 320 rc = ds_seat_create(disp, "Alice", &seat); 321 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 322 323 display_wnd_params_init(¶ms); 324 params.rect.p0.x = params.rect.p0.y = 0; 325 params.rect.p1.x = params.rect.p1.y = 100; 326 327 rc = ds_window_create(client, ¶ms, &w0); 328 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 329 330 rc = ds_window_create(client, ¶ms, &w1); 331 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 332 333 PCUT_ASSERT_EQUALS(w1, ds_display_first_window(disp)); 334 ds_display_window_to_top(w0); 335 PCUT_ASSERT_EQUALS(w0, ds_display_first_window(disp)); 152 336 153 337 ds_window_destroy(w0); … … 178 362 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 179 363 180 rc = ds_seat_create(disp, &seat);364 rc = ds_seat_create(disp, "Alice", &seat); 181 365 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 182 366 … … 214 398 } 215 399 400 /** Basic idevcfg operation */ 401 PCUT_TEST(display_idevcfg) 402 { 403 ds_display_t *disp; 404 ds_seat_t *seat; 405 ds_idevcfg_t *idevcfg; 406 errno_t rc; 407 408 rc = ds_display_create(NULL, df_none, &disp); 409 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 410 411 rc = ds_seat_create(disp, "Alice", &seat); 412 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 413 414 rc = ds_idevcfg_create(disp, 42, seat, &idevcfg); 415 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 416 417 ds_idevcfg_destroy(idevcfg); 418 419 ds_seat_destroy(seat); 420 ds_display_destroy(disp); 421 } 422 216 423 /** Basic seat operation. */ 217 424 PCUT_TEST(display_seat) … … 219 426 ds_display_t *disp; 220 427 ds_seat_t *seat; 221 ds_seat_t *s0, *s1 ;222 errno_t rc; 223 224 rc = ds_display_create(NULL, df_none, &disp); 225 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 226 227 rc = ds_seat_create(disp, &seat);428 ds_seat_t *s0, *s1, *s2; 429 errno_t rc; 430 431 rc = ds_display_create(NULL, df_none, &disp); 432 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 433 434 rc = ds_seat_create(disp, "Alice", &seat); 228 435 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 229 436 … … 234 441 PCUT_ASSERT_NULL(s1); 235 442 236 ds_seat_destroy(seat); 237 ds_display_destroy(disp); 443 s2 = ds_display_find_seat(disp, seat->id); 444 PCUT_ASSERT_EQUALS(s2, seat); 445 446 ds_seat_destroy(seat); 447 ds_display_destroy(disp); 448 } 449 450 /** ds_display_seat_by_idev() returns the correct seat. */ 451 PCUT_TEST(display_seat_by_idev) 452 { 453 // XXX TODO 238 454 } 239 455 … … 254 470 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 255 471 256 rc = ds_seat_create(disp, &seat);472 rc = ds_seat_create(disp, "Alice", &seat); 257 473 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 258 474 … … 302 518 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 303 519 304 rc = ds_seat_create(disp, &seat);520 rc = ds_seat_create(disp, "Alice", &seat); 305 521 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 306 522 … … 370 586 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 371 587 372 rc = ds_seat_create(disp, &seat);588 rc = ds_seat_create(disp, "Alice", &seat); 373 589 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 374 590 … … 442 658 } 443 659 660 /** ds_display_update_max_rect() updates maximization rectangle */ 661 PCUT_TEST(display_update_max_rect) 662 { 663 ds_display_t *disp; 664 ds_seat_t *seat; 665 ds_client_t *client; 666 ds_window_t *wnd; 667 display_wnd_params_t params; 668 errno_t rc; 669 670 rc = ds_display_create(NULL, df_none, &disp); 671 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 672 673 rc = ds_seat_create(disp, "Alice", &seat); 674 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 675 676 rc = ds_client_create(disp, NULL, NULL, &client); 677 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 678 679 /* 680 * We need to set display dimensions Here we do it directly 681 * instead of adding a display device. 682 */ 683 disp->rect.p0.x = 0; 684 disp->rect.p0.y = 0; 685 disp->rect.p1.x = 500; 686 disp->rect.p1.y = 500; 687 688 /* Set maximize rectangle as well */ 689 disp->max_rect = disp->rect; 690 691 /* A panel-like window at the bottom */ 692 display_wnd_params_init(¶ms); 693 params.flags |= wndf_setpos; 694 params.pos.x = 0; 695 params.pos.y = 450; 696 params.rect.p0.x = 0; 697 params.rect.p0.y = 0; 698 params.rect.p1.x = 500; 699 params.rect.p1.y = 50; 700 701 rc = ds_window_create(client, ¶ms, &wnd); 702 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 703 704 /* 705 * At this point the maximize rect should be unaltered because 706 * the avoid flag has not been set. 707 */ 708 PCUT_ASSERT_INT_EQUALS(0, disp->max_rect.p0.x); 709 PCUT_ASSERT_INT_EQUALS(0, disp->max_rect.p0.y); 710 PCUT_ASSERT_INT_EQUALS(500, disp->max_rect.p1.x); 711 PCUT_ASSERT_INT_EQUALS(500, disp->max_rect.p1.y); 712 713 wnd->flags |= wndf_avoid; 714 715 /* Update maximize rectangle */ 716 ds_display_update_max_rect(disp); 717 718 /* Verify maximize rectangle */ 719 PCUT_ASSERT_INT_EQUALS(0, disp->max_rect.p0.x); 720 PCUT_ASSERT_INT_EQUALS(0, disp->max_rect.p0.y); 721 PCUT_ASSERT_INT_EQUALS(500, disp->max_rect.p1.x); 722 PCUT_ASSERT_INT_EQUALS(450, disp->max_rect.p1.y); 723 724 ds_window_destroy(wnd); 725 ds_client_destroy(client); 726 ds_seat_destroy(seat); 727 ds_display_destroy(disp); 728 } 729 730 /** Cropping maximization rectangle from the top */ 731 PCUT_TEST(display_crop_max_rect_top) 732 { 733 gfx_rect_t arect; 734 gfx_rect_t mrect; 735 736 arect.p0.x = 10; 737 arect.p0.y = 20; 738 arect.p1.x = 30; 739 arect.p1.y = 5; 740 741 mrect.p0.x = 10; 742 mrect.p0.y = 20; 743 mrect.p1.x = 30; 744 mrect.p1.y = 40; 745 746 ds_display_crop_max_rect(&arect, &mrect); 747 748 PCUT_ASSERT_INT_EQUALS(10, mrect.p0.x); 749 PCUT_ASSERT_INT_EQUALS(5, mrect.p0.y); 750 PCUT_ASSERT_INT_EQUALS(30, mrect.p1.x); 751 PCUT_ASSERT_INT_EQUALS(40, mrect.p1.y); 752 } 753 754 /** Cropping maximization rectangle from the bottom */ 755 PCUT_TEST(display_crop_max_rect_bottom) 756 { 757 gfx_rect_t arect; 758 gfx_rect_t mrect; 759 760 arect.p0.x = 10; 761 arect.p0.y = 35; 762 arect.p1.x = 30; 763 arect.p1.y = 40; 764 765 mrect.p0.x = 10; 766 mrect.p0.y = 20; 767 mrect.p1.x = 30; 768 mrect.p1.y = 40; 769 770 ds_display_crop_max_rect(&arect, &mrect); 771 772 PCUT_ASSERT_INT_EQUALS(10, mrect.p0.x); 773 PCUT_ASSERT_INT_EQUALS(20, mrect.p0.y); 774 PCUT_ASSERT_INT_EQUALS(30, mrect.p1.x); 775 PCUT_ASSERT_INT_EQUALS(35, mrect.p1.y); 776 } 777 778 /** Cropping maximization rectangle from the left */ 779 PCUT_TEST(display_crop_max_rect_left) 780 { 781 gfx_rect_t arect; 782 gfx_rect_t mrect; 783 784 arect.p0.x = 10; 785 arect.p0.y = 20; 786 arect.p1.x = 15; 787 arect.p1.y = 40; 788 789 mrect.p0.x = 10; 790 mrect.p0.y = 20; 791 mrect.p1.x = 30; 792 mrect.p1.y = 40; 793 794 ds_display_crop_max_rect(&arect, &mrect); 795 796 PCUT_ASSERT_INT_EQUALS(15, mrect.p0.x); 797 PCUT_ASSERT_INT_EQUALS(20, mrect.p0.y); 798 PCUT_ASSERT_INT_EQUALS(30, mrect.p1.x); 799 PCUT_ASSERT_INT_EQUALS(40, mrect.p1.y); 800 } 801 802 /** Cropping maximization rectangle from the right */ 803 PCUT_TEST(display_crop_max_rect_right) 804 { 805 gfx_rect_t arect; 806 gfx_rect_t mrect; 807 808 arect.p0.x = 25; 809 arect.p0.y = 20; 810 arect.p1.x = 30; 811 arect.p1.y = 40; 812 813 mrect.p0.x = 10; 814 mrect.p0.y = 20; 815 mrect.p1.x = 30; 816 mrect.p1.y = 40; 817 818 ds_display_crop_max_rect(&arect, &mrect); 819 820 PCUT_ASSERT_INT_EQUALS(10, mrect.p0.x); 821 PCUT_ASSERT_INT_EQUALS(20, mrect.p0.y); 822 PCUT_ASSERT_INT_EQUALS(25, mrect.p1.x); 823 PCUT_ASSERT_INT_EQUALS(40, mrect.p1.y); 824 } 825 444 826 PCUT_EXPORT(display);
Note:
See TracChangeset
for help on using the changeset viewer.