Changeset b0a94854 in mainline for uspace/lib/display/test/display.c
- Timestamp:
- 2020-02-19T13:28:34Z (5 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0a052b0
- Parents:
- e1f2079
- git-author:
- Jiri Svoboda <jiri@…> (2020-01-18 18:28:21)
- git-committer:
- Jiri Svoboda <jiri@…> (2020-02-19 13:28:34)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/display/test/display.c
re1f2079 rb0a94854 47 47 48 48 static void test_display_conn(ipc_call_t *, void *); 49 50 static void test_focus_event(void *); 49 51 static void test_kbd_event(void *, kbd_event_t *); 50 52 static void test_pos_event(void *, pos_event_t *); 53 static void test_unfocus_event(void *); 51 54 52 55 static errno_t test_window_create(void *, display_wnd_params_t *, sysarg_t *); … … 63 66 64 67 static display_wnd_cb_t test_display_wnd_cb = { 68 .focus_event = test_focus_event, 65 69 .kbd_event = test_kbd_event, 66 .pos_event = test_pos_event 70 .pos_event = test_pos_event, 71 .unfocus_event = test_unfocus_event 67 72 }; 68 73 … … 85 90 bool get_event_called; 86 91 bool set_color_called; 92 bool focus_event_called; 87 93 bool kbd_event_called; 88 94 bool pos_event_called; 95 bool unfocus_event_called; 89 96 fibril_condvar_t event_cv; 90 97 fibril_mutex_t event_lock; … … 382 389 383 390 display_close(disp); 391 rc = loc_service_unregister(sid); 392 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 393 } 394 395 /** Focus event can be delivered from server to client callback function */ 396 PCUT_TEST(focus_event_deliver) 397 { 398 errno_t rc; 399 service_id_t sid; 400 display_t *disp = NULL; 401 display_wnd_params_t params; 402 display_window_t *wnd; 403 test_response_t resp; 404 405 async_set_fallback_port_handler(test_display_conn, &resp); 406 407 // FIXME This causes this test to be non-reentrant! 408 rc = loc_server_register(test_display_server); 409 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 410 411 rc = loc_service_register(test_display_svc, &sid); 412 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 413 414 rc = display_open(test_display_svc, &disp); 415 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 416 PCUT_ASSERT_NOT_NULL(disp); 417 PCUT_ASSERT_NOT_NULL(resp.srv); 418 419 wnd = NULL; 420 resp.rc = EOK; 421 display_wnd_params_init(¶ms); 422 params.rect.p0.x = 0; 423 params.rect.p0.y = 0; 424 params.rect.p0.x = 100; 425 params.rect.p0.y = 100; 426 427 rc = display_window_create(disp, ¶ms, &test_display_wnd_cb, 428 (void *) &resp, &wnd); 429 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 430 PCUT_ASSERT_NOT_NULL(wnd); 431 432 resp.event_cnt = 1; 433 resp.event.etype = wev_focus; 434 resp.wnd_id = wnd->id; 435 resp.focus_event_called = false; 436 fibril_mutex_initialize(&resp.event_lock); 437 fibril_condvar_initialize(&resp.event_cv); 438 display_srv_ev_pending(resp.srv); 439 440 /* Wait for the event handler to be called. */ 441 fibril_mutex_lock(&resp.event_lock); 442 while (!resp.focus_event_called) { 443 fibril_condvar_wait(&resp.event_cv, &resp.event_lock); 444 } 445 fibril_mutex_unlock(&resp.event_lock); 446 447 /* Verify that the event was delivered correctly */ 448 PCUT_ASSERT_EQUALS(resp.event.etype, 449 resp.revent.etype); 450 451 rc = display_window_destroy(wnd); 452 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 453 454 display_close(disp); 455 384 456 rc = loc_service_unregister(sid); 385 457 PCUT_ASSERT_ERRNO_VAL(EOK, rc); … … 540 612 } 541 613 614 /** Unfocus event can be delivered from server to client callback function */ 615 PCUT_TEST(unfocus_event_deliver) 616 { 617 errno_t rc; 618 service_id_t sid; 619 display_t *disp = NULL; 620 display_wnd_params_t params; 621 display_window_t *wnd; 622 test_response_t resp; 623 624 async_set_fallback_port_handler(test_display_conn, &resp); 625 626 // FIXME This causes this test to be non-reentrant! 627 rc = loc_server_register(test_display_server); 628 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 629 630 rc = loc_service_register(test_display_svc, &sid); 631 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 632 633 rc = display_open(test_display_svc, &disp); 634 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 635 PCUT_ASSERT_NOT_NULL(disp); 636 PCUT_ASSERT_NOT_NULL(resp.srv); 637 638 wnd = NULL; 639 resp.rc = EOK; 640 display_wnd_params_init(¶ms); 641 params.rect.p0.x = 0; 642 params.rect.p0.y = 0; 643 params.rect.p0.x = 100; 644 params.rect.p0.y = 100; 645 646 rc = display_window_create(disp, ¶ms, &test_display_wnd_cb, 647 (void *) &resp, &wnd); 648 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 649 PCUT_ASSERT_NOT_NULL(wnd); 650 651 resp.event_cnt = 1; 652 resp.event.etype = wev_unfocus; 653 resp.wnd_id = wnd->id; 654 resp.focus_event_called = false; 655 fibril_mutex_initialize(&resp.event_lock); 656 fibril_condvar_initialize(&resp.event_cv); 657 display_srv_ev_pending(resp.srv); 658 659 /* Wait for the event handler to be called. */ 660 fibril_mutex_lock(&resp.event_lock); 661 while (!resp.unfocus_event_called) { 662 fibril_condvar_wait(&resp.event_cv, &resp.event_lock); 663 } 664 fibril_mutex_unlock(&resp.event_lock); 665 666 /* Verify that the event was delivered correctly */ 667 PCUT_ASSERT_EQUALS(resp.event.etype, 668 resp.revent.etype); 669 670 rc = display_window_destroy(wnd); 671 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 672 673 display_close(disp); 674 675 rc = loc_service_unregister(sid); 676 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 677 } 678 542 679 /** Test display service connection. 543 680 * … … 587 724 } 588 725 726 static void test_focus_event(void *arg) 727 { 728 test_response_t *resp = (test_response_t *) arg; 729 730 resp->revent.etype = wev_focus; 731 732 fibril_mutex_lock(&resp->event_lock); 733 resp->focus_event_called = true; 734 fibril_condvar_broadcast(&resp->event_cv); 735 fibril_mutex_unlock(&resp->event_lock); 736 } 737 589 738 static void test_kbd_event(void *arg, kbd_event_t *event) 590 739 { … … 609 758 fibril_mutex_lock(&resp->event_lock); 610 759 resp->pos_event_called = true; 760 fibril_condvar_broadcast(&resp->event_cv); 761 fibril_mutex_unlock(&resp->event_lock); 762 } 763 764 static void test_unfocus_event(void *arg) 765 { 766 test_response_t *resp = (test_response_t *) arg; 767 768 resp->revent.etype = wev_unfocus; 769 770 fibril_mutex_lock(&resp->event_lock); 771 resp->unfocus_event_called = true; 611 772 fibril_condvar_broadcast(&resp->event_cv); 612 773 fibril_mutex_unlock(&resp->event_lock);
Note:
See TracChangeset
for help on using the changeset viewer.