HelenOS sources
This source file includes following definitions.
- test_ds_ev_pending
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
#include <disp_srv.h>
#include <errno.h>
#include <pcut/pcut.h>
#include <str.h>
#include "../client.h"
#include "../display.h"
#include "../seat.h"
#include "../window.h"
PCUT_INIT;
PCUT_TEST_SUITE(client);
static void test_ds_ev_pending(void *);
static ds_client_cb_t test_ds_client_cb = {
.ev_pending = test_ds_ev_pending
};
static void test_ds_ev_pending(void *arg)
{
bool *called_cb = (bool *) arg;
*called_cb = true;
}
PCUT_TEST(client_create_destroy)
{
ds_display_t *disp;
ds_client_t *client;
errno_t rc;
rc = ds_display_create(NULL, df_none, &disp);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = ds_client_create(disp, &test_ds_client_cb, NULL, &client);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
ds_client_destroy(client);
ds_display_destroy(disp);
}
PCUT_TEST(client_find_window)
{
ds_display_t *disp;
ds_client_t *client;
ds_seat_t *seat;
ds_window_t *w0;
ds_window_t *w1;
ds_window_t *wnd;
display_wnd_params_t params;
bool called_cb = NULL;
errno_t rc;
rc = ds_display_create(NULL, df_none, &disp);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = ds_seat_create(disp, "Alice", &seat);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
display_wnd_params_init(¶ms);
params.rect.p0.x = params.rect.p0.y = 0;
params.rect.p1.x = params.rect.p1.y = 1;
rc = ds_window_create(client, ¶ms, &w0);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = ds_window_create(client, ¶ms, &w1);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
wnd = ds_client_find_window(client, w0->id);
PCUT_ASSERT_EQUALS(w0, wnd);
wnd = ds_client_find_window(client, w1->id);
PCUT_ASSERT_EQUALS(w1, wnd);
wnd = ds_client_find_window(client, 0);
PCUT_ASSERT_NULL(wnd);
wnd = ds_client_find_window(client, w1->id + 1);
PCUT_ASSERT_NULL(wnd);
ds_window_destroy(w0);
ds_window_destroy(w1);
ds_seat_destroy(seat);
ds_client_destroy(client);
ds_display_destroy(disp);
}
PCUT_TEST(client_first_next_window)
{
ds_display_t *disp;
ds_client_t *client;
ds_seat_t *seat;
ds_window_t *w0;
ds_window_t *w1;
ds_window_t *wnd;
display_wnd_params_t params;
bool called_cb = NULL;
errno_t rc;
rc = ds_display_create(NULL, df_none, &disp);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = ds_seat_create(disp, "Alice", &seat);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
display_wnd_params_init(¶ms);
params.rect.p0.x = params.rect.p0.y = 0;
params.rect.p1.x = params.rect.p1.y = 1;
rc = ds_window_create(client, ¶ms, &w0);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = ds_window_create(client, ¶ms, &w1);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
wnd = ds_client_first_window(client);
PCUT_ASSERT_EQUALS(w0, wnd);
wnd = ds_client_next_window(w0);
PCUT_ASSERT_EQUALS(w1, wnd);
wnd = ds_client_next_window(w1);
PCUT_ASSERT_NULL(wnd);
ds_window_destroy(w0);
ds_window_destroy(w1);
ds_seat_destroy(seat);
ds_client_destroy(client);
ds_display_destroy(disp);
}
PCUT_TEST(client_get_post_close_event)
{
ds_display_t *disp;
ds_client_t *client;
ds_seat_t *seat;
ds_window_t *wnd;
display_wnd_params_t params;
ds_window_t *rwindow;
display_wnd_ev_t revent;
bool called_cb = NULL;
errno_t rc;
rc = ds_display_create(NULL, df_none, &disp);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = ds_seat_create(disp, "Alice", &seat);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
display_wnd_params_init(¶ms);
params.rect.p0.x = params.rect.p0.y = 0;
params.rect.p1.x = params.rect.p1.y = 1;
rc = ds_window_create(client, ¶ms, &wnd);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_TRUE(called_cb);
rc = ds_client_get_event(client, &rwindow, &revent);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
called_cb = false;
rc = ds_client_get_event(client, &rwindow, &revent);
PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
rc = ds_client_post_close_event(client, wnd);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_TRUE(called_cb);
rc = ds_client_get_event(client, &rwindow, &revent);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_EQUALS(wnd, rwindow);
PCUT_ASSERT_EQUALS(wev_close, revent.etype);
rc = ds_client_get_event(client, &rwindow, &revent);
PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
ds_window_destroy(wnd);
ds_seat_destroy(seat);
ds_client_destroy(client);
ds_display_destroy(disp);
}
PCUT_TEST(client_get_post_focus_event)
{
ds_display_t *disp;
ds_client_t *client;
ds_seat_t *seat;
ds_window_t *wnd;
display_wnd_params_t params;
ds_window_t *rwindow;
display_wnd_focus_ev_t efocus;
display_wnd_ev_t revent;
bool called_cb = NULL;
errno_t rc;
rc = ds_display_create(NULL, df_none, &disp);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = ds_seat_create(disp, "Alice", &seat);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
display_wnd_params_init(¶ms);
params.rect.p0.x = params.rect.p0.y = 0;
params.rect.p1.x = params.rect.p1.y = 1;
rc = ds_window_create(client, ¶ms, &wnd);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_TRUE(called_cb);
rc = ds_client_get_event(client, &rwindow, &revent);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
called_cb = false;
rc = ds_client_get_event(client, &rwindow, &revent);
PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
efocus.nfocus = 42;
rc = ds_client_post_focus_event(client, wnd, &efocus);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_TRUE(called_cb);
rc = ds_client_get_event(client, &rwindow, &revent);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_EQUALS(wnd, rwindow);
PCUT_ASSERT_EQUALS(wev_focus, revent.etype);
PCUT_ASSERT_INT_EQUALS(efocus.nfocus, revent.ev.focus.nfocus);
rc = ds_client_get_event(client, &rwindow, &revent);
PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
ds_window_destroy(wnd);
ds_seat_destroy(seat);
ds_client_destroy(client);
ds_display_destroy(disp);
}
PCUT_TEST(client_get_post_kbd_event)
{
ds_display_t *disp;
ds_client_t *client;
ds_seat_t *seat;
ds_window_t *wnd;
display_wnd_params_t params;
kbd_event_t event;
ds_window_t *rwindow;
display_wnd_ev_t revent;
bool called_cb = NULL;
errno_t rc;
rc = ds_display_create(NULL, df_none, &disp);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = ds_seat_create(disp, "Alice", &seat);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
display_wnd_params_init(¶ms);
params.rect.p0.x = params.rect.p0.y = 0;
params.rect.p1.x = params.rect.p1.y = 1;
rc = ds_window_create(client, ¶ms, &wnd);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_TRUE(called_cb);
rc = ds_client_get_event(client, &rwindow, &revent);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
called_cb = false;
rc = ds_client_get_event(client, &rwindow, &revent);
PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
event.type = KEY_PRESS;
event.key = KC_ENTER;
event.mods = 0;
event.c = L'\0';
rc = ds_client_post_kbd_event(client, wnd, &event);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_TRUE(called_cb);
rc = ds_client_get_event(client, &rwindow, &revent);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_EQUALS(wnd, rwindow);
PCUT_ASSERT_EQUALS(wev_kbd, revent.etype);
PCUT_ASSERT_EQUALS(event.type, revent.ev.kbd.type);
PCUT_ASSERT_EQUALS(event.key, revent.ev.kbd.key);
PCUT_ASSERT_EQUALS(event.mods, revent.ev.kbd.mods);
PCUT_ASSERT_EQUALS(event.c, revent.ev.kbd.c);
rc = ds_client_get_event(client, &rwindow, &revent);
PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
ds_window_destroy(wnd);
ds_seat_destroy(seat);
ds_client_destroy(client);
ds_display_destroy(disp);
}
PCUT_TEST(client_get_post_pos_event)
{
ds_display_t *disp;
ds_client_t *client;
ds_seat_t *seat;
ds_window_t *wnd;
display_wnd_params_t params;
pos_event_t event;
ds_window_t *rwindow;
display_wnd_ev_t revent;
bool called_cb = NULL;
errno_t rc;
rc = ds_display_create(NULL, df_none, &disp);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = ds_seat_create(disp, "Alice", &seat);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
display_wnd_params_init(¶ms);
params.rect.p0.x = params.rect.p0.y = 0;
params.rect.p1.x = params.rect.p1.y = 1;
rc = ds_window_create(client, ¶ms, &wnd);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_TRUE(called_cb);
rc = ds_client_get_event(client, &rwindow, &revent);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
called_cb = false;
PCUT_ASSERT_FALSE(called_cb);
rc = ds_client_get_event(client, &rwindow, &revent);
PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
event.type = POS_PRESS;
event.hpos = 1;
event.vpos = 2;
rc = ds_client_post_pos_event(client, wnd, &event);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_TRUE(called_cb);
rc = ds_client_get_event(client, &rwindow, &revent);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_EQUALS(wnd, rwindow);
PCUT_ASSERT_EQUALS(wev_pos, revent.etype);
PCUT_ASSERT_EQUALS(event.type, revent.ev.pos.type);
PCUT_ASSERT_EQUALS(event.hpos, revent.ev.pos.hpos);
PCUT_ASSERT_EQUALS(event.vpos, revent.ev.pos.vpos);
rc = ds_client_get_event(client, &rwindow, &revent);
PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
ds_window_destroy(wnd);
ds_seat_destroy(seat);
ds_client_destroy(client);
ds_display_destroy(disp);
}
PCUT_TEST(client_get_post_resize_event)
{
ds_display_t *disp;
ds_client_t *client;
ds_seat_t *seat;
ds_window_t *wnd;
display_wnd_params_t params;
gfx_rect_t rect;
ds_window_t *rwindow;
display_wnd_ev_t revent;
bool called_cb = NULL;
errno_t rc;
rc = ds_display_create(NULL, df_none, &disp);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = ds_seat_create(disp, "Alice", &seat);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
display_wnd_params_init(¶ms);
params.rect.p0.x = params.rect.p0.y = 0;
params.rect.p1.x = params.rect.p1.y = 1;
rc = ds_window_create(client, ¶ms, &wnd);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_TRUE(called_cb);
rc = ds_client_get_event(client, &rwindow, &revent);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
called_cb = false;
PCUT_ASSERT_FALSE(called_cb);
rc = ds_client_get_event(client, &rwindow, &revent);
PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
rect.p0.x = 1;
rect.p0.y = 2;
rect.p1.x = 3;
rect.p1.y = 4;
rc = ds_client_post_resize_event(client, wnd, &rect);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_TRUE(called_cb);
rc = ds_client_get_event(client, &rwindow, &revent);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_EQUALS(wnd, rwindow);
PCUT_ASSERT_EQUALS(wev_resize, revent.etype);
PCUT_ASSERT_EQUALS(rect.p0.x, revent.ev.resize.rect.p0.x);
PCUT_ASSERT_EQUALS(rect.p0.y, revent.ev.resize.rect.p0.y);
PCUT_ASSERT_EQUALS(rect.p1.x, revent.ev.resize.rect.p1.x);
PCUT_ASSERT_EQUALS(rect.p1.y, revent.ev.resize.rect.p1.y);
rc = ds_client_get_event(client, &rwindow, &revent);
PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
ds_window_destroy(wnd);
ds_seat_destroy(seat);
ds_client_destroy(client);
ds_display_destroy(disp);
}
PCUT_TEST(client_get_post_unfocus_event)
{
ds_display_t *disp;
ds_client_t *client;
ds_seat_t *seat;
ds_window_t *wnd;
display_wnd_params_t params;
ds_window_t *rwindow;
display_wnd_unfocus_ev_t eunfocus;
display_wnd_ev_t revent;
bool called_cb = NULL;
errno_t rc;
rc = ds_display_create(NULL, df_none, &disp);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = ds_seat_create(disp, "Alice", &seat);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
display_wnd_params_init(¶ms);
params.rect.p0.x = params.rect.p0.y = 0;
params.rect.p1.x = params.rect.p1.y = 1;
rc = ds_window_create(client, ¶ms, &wnd);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_TRUE(called_cb);
rc = ds_client_get_event(client, &rwindow, &revent);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
called_cb = false;
rc = ds_client_get_event(client, &rwindow, &revent);
PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
eunfocus.nfocus = 42;
rc = ds_client_post_unfocus_event(client, wnd, &eunfocus);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_TRUE(called_cb);
rc = ds_client_get_event(client, &rwindow, &revent);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_EQUALS(wnd, rwindow);
PCUT_ASSERT_EQUALS(wev_unfocus, revent.etype);
PCUT_ASSERT_INT_EQUALS(eunfocus.nfocus, revent.ev.unfocus.nfocus);
rc = ds_client_get_event(client, &rwindow, &revent);
PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
ds_window_destroy(wnd);
ds_seat_destroy(seat);
ds_client_destroy(client);
ds_display_destroy(disp);
}
PCUT_TEST(client_purge_window_events)
{
ds_display_t *disp;
ds_client_t *client;
ds_seat_t *seat;
ds_window_t *wnd;
display_wnd_params_t params;
ds_window_t *rwindow;
display_wnd_ev_t revent;
bool called_cb = NULL;
errno_t rc;
rc = ds_display_create(NULL, df_none, &disp);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = ds_seat_create(disp, "Alice", &seat);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
display_wnd_params_init(¶ms);
params.rect.p0.x = params.rect.p0.y = 0;
params.rect.p1.x = params.rect.p1.y = 1;
rc = ds_window_create(client, ¶ms, &wnd);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_TRUE(called_cb);
ds_client_purge_window_events(client, wnd);
rc = ds_client_get_event(client, &rwindow, &revent);
PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
ds_window_destroy(wnd);
ds_seat_destroy(seat);
ds_client_destroy(client);
ds_display_destroy(disp);
}
PCUT_TEST(client_leftover_window)
{
ds_display_t *disp;
ds_client_t *client;
ds_seat_t *seat;
ds_window_t *wnd;
display_wnd_params_t params;
errno_t rc;
rc = ds_display_create(NULL, df_none, &disp);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = ds_client_create(disp, NULL, NULL, &client);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = ds_seat_create(disp, "Alice", &seat);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
display_wnd_params_init(¶ms);
params.rect.p0.x = params.rect.p0.y = 0;
params.rect.p1.x = params.rect.p1.y = 1;
rc = ds_window_create(client, ¶ms, &wnd);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
ds_seat_destroy(seat);
ds_client_destroy(client);
ds_display_destroy(disp);
}
PCUT_EXPORT(client);
HelenOS homepage, sources at GitHub