Changeset 338d0935 in mainline for uspace/lib/display/test/display.c


Ignore:
Timestamp:
2020-03-02T11:22:01Z (5 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a2e104e
Parents:
7bb45e3
git-author:
Jiri Svoboda <jiri@…> (2020-02-01 11:18:50)
git-committer:
Jiri Svoboda <jiri@…> (2020-03-02 11:22:01)
Message:

Closing windows

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/display/test/display.c

    r7bb45e3 r338d0935  
    4848static void test_display_conn(ipc_call_t *, void *);
    4949
     50static void test_close_event(void *);
    5051static void test_focus_event(void *);
    5152static void test_kbd_event(void *, kbd_event_t *);
     
    6970
    7071static display_wnd_cb_t test_display_wnd_cb = {
     72        .close_event = test_close_event,
    7173        .focus_event = test_focus_event,
    7274        .kbd_event = test_kbd_event,
     
    100102        bool get_event_called;
    101103        bool set_color_called;
     104        bool close_event_called;
    102105        bool focus_event_called;
    103106        bool kbd_event_called;
     
    526529
    527530        display_close(disp);
     531        rc = loc_service_unregister(sid);
     532        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     533}
     534
     535/** Close event can be delivered from server to client callback function */
     536PCUT_TEST(close_event_deliver)
     537{
     538        errno_t rc;
     539        service_id_t sid;
     540        display_t *disp = NULL;
     541        display_wnd_params_t params;
     542        display_window_t *wnd;
     543        test_response_t resp;
     544
     545        async_set_fallback_port_handler(test_display_conn, &resp);
     546
     547        // FIXME This causes this test to be non-reentrant!
     548        rc = loc_server_register(test_display_server);
     549        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     550
     551        rc = loc_service_register(test_display_svc, &sid);
     552        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     553
     554        rc = display_open(test_display_svc, &disp);
     555        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     556        PCUT_ASSERT_NOT_NULL(disp);
     557        PCUT_ASSERT_NOT_NULL(resp.srv);
     558
     559        wnd = NULL;
     560        resp.rc = EOK;
     561        display_wnd_params_init(&params);
     562        params.rect.p0.x = 0;
     563        params.rect.p0.y = 0;
     564        params.rect.p0.x = 100;
     565        params.rect.p0.y = 100;
     566
     567        rc = display_window_create(disp, &params, &test_display_wnd_cb,
     568            (void *) &resp, &wnd);
     569        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     570        PCUT_ASSERT_NOT_NULL(wnd);
     571
     572        resp.event_cnt = 1;
     573        resp.event.etype = wev_close;
     574        resp.wnd_id = wnd->id;
     575        resp.close_event_called = false;
     576        fibril_mutex_initialize(&resp.event_lock);
     577        fibril_condvar_initialize(&resp.event_cv);
     578        display_srv_ev_pending(resp.srv);
     579
     580        /* Wait for the event handler to be called. */
     581        fibril_mutex_lock(&resp.event_lock);
     582        while (!resp.close_event_called) {
     583                fibril_condvar_wait(&resp.event_cv, &resp.event_lock);
     584        }
     585        fibril_mutex_unlock(&resp.event_lock);
     586
     587        /* Verify that the event was delivered correctly */
     588        PCUT_ASSERT_EQUALS(resp.event.etype,
     589            resp.revent.etype);
     590
     591        rc = display_window_destroy(wnd);
     592        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     593
     594        display_close(disp);
     595
    528596        rc = loc_service_unregister(sid);
    529597        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     
    861929}
    862930
     931static void test_close_event(void *arg)
     932{
     933        test_response_t *resp = (test_response_t *) arg;
     934
     935        resp->revent.etype = wev_close;
     936
     937        fibril_mutex_lock(&resp->event_lock);
     938        resp->close_event_called = true;
     939        fibril_condvar_broadcast(&resp->event_cv);
     940        fibril_mutex_unlock(&resp->event_lock);
     941}
     942
    863943static void test_focus_event(void *arg)
    864944{
Note: See TracChangeset for help on using the changeset viewer.