Changeset b0a94854 in mainline for uspace/lib/display/test/display.c


Ignore:
Timestamp:
2020-02-19T13:28:34Z (4 years ago)
Author:
Jiri Svoboda <jiri@…>
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)
Message:

Deliver window focus and unfocus events

File:
1 edited

Legend:

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

    re1f2079 rb0a94854  
    4747
    4848static void test_display_conn(ipc_call_t *, void *);
     49
     50static void test_focus_event(void *);
    4951static void test_kbd_event(void *, kbd_event_t *);
    5052static void test_pos_event(void *, pos_event_t *);
     53static void test_unfocus_event(void *);
    5154
    5255static errno_t test_window_create(void *, display_wnd_params_t *, sysarg_t *);
     
    6366
    6467static display_wnd_cb_t test_display_wnd_cb = {
     68        .focus_event = test_focus_event,
    6569        .kbd_event = test_kbd_event,
    66         .pos_event = test_pos_event
     70        .pos_event = test_pos_event,
     71        .unfocus_event = test_unfocus_event
    6772};
    6873
     
    8590        bool get_event_called;
    8691        bool set_color_called;
     92        bool focus_event_called;
    8793        bool kbd_event_called;
    8894        bool pos_event_called;
     95        bool unfocus_event_called;
    8996        fibril_condvar_t event_cv;
    9097        fibril_mutex_t event_lock;
     
    382389
    383390        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 */
     396PCUT_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(&params);
     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, &params, &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
    384456        rc = loc_service_unregister(sid);
    385457        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     
    540612}
    541613
     614/** Unfocus event can be delivered from server to client callback function */
     615PCUT_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(&params);
     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, &params, &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
    542679/** Test display service connection.
    543680 *
     
    587724}
    588725
     726static 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
    589738static void test_kbd_event(void *arg, kbd_event_t *event)
    590739{
     
    609758        fibril_mutex_lock(&resp->event_lock);
    610759        resp->pos_event_called = true;
     760        fibril_condvar_broadcast(&resp->event_cv);
     761        fibril_mutex_unlock(&resp->event_lock);
     762}
     763
     764static 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;
    611772        fibril_condvar_broadcast(&resp->event_cv);
    612773        fibril_mutex_unlock(&resp->event_lock);
Note: See TracChangeset for help on using the changeset viewer.