HelenOS sources
This source file includes following definitions.
- test_ds_ev_pending
- test_ds_wmev_pending
- test_ds_cfgev_pending
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- 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 "../cfgclient.h"
#include "../client.h"
#include "../display.h"
#include "../idevcfg.h"
#include "../seat.h"
#include "../window.h"
#include "../wmclient.h"
PCUT_INIT;
PCUT_TEST_SUITE(display);
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_wmev_pending(void *);
static ds_wmclient_cb_t test_ds_wmclient_cb = {
.ev_pending = test_ds_wmev_pending
};
static void test_ds_cfgev_pending(void *);
static ds_cfgclient_cb_t test_ds_cfgclient_cb = {
.ev_pending = test_ds_cfgev_pending
};
static void test_ds_ev_pending(void *arg)
{
bool *called_cb = (bool *) arg;
*called_cb = true;
}
static void test_ds_wmev_pending(void *arg)
{
bool *called_cb = (bool *) arg;
*called_cb = true;
}
static void test_ds_cfgev_pending(void *arg)
{
bool *called_cb = (bool *) arg;
*called_cb = true;
}
PCUT_TEST(display_create_destroy)
{
ds_display_t *disp;
errno_t rc;
rc = ds_display_create(NULL, df_none, &disp);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
ds_display_destroy(disp);
}
PCUT_TEST(display_client)
{
ds_display_t *disp;
ds_client_t *client;
ds_client_t *c0, *c1;
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);
c0 = ds_display_first_client(disp);
PCUT_ASSERT_EQUALS(c0, client);
c1 = ds_display_next_client(c0);
PCUT_ASSERT_NULL(c1);
ds_client_destroy(client);
ds_display_destroy(disp);
}
PCUT_TEST(display_wmclient)
{
ds_display_t *disp;
ds_wmclient_t *wmclient;
ds_wmclient_t *c0, *c1;
errno_t rc;
rc = ds_display_create(NULL, df_none, &disp);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = ds_wmclient_create(disp, &test_ds_wmclient_cb, NULL, &wmclient);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
c0 = ds_display_first_wmclient(disp);
PCUT_ASSERT_EQUALS(c0, wmclient);
c1 = ds_display_next_wmclient(c0);
PCUT_ASSERT_NULL(c1);
ds_wmclient_destroy(wmclient);
ds_display_destroy(disp);
}
PCUT_TEST(display_cfgclient)
{
ds_display_t *disp;
ds_cfgclient_t *cfgclient;
errno_t rc;
rc = ds_display_create(NULL, df_none, &disp);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = ds_cfgclient_create(disp, &test_ds_cfgclient_cb, NULL, &cfgclient);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
ds_cfgclient_destroy(cfgclient);
ds_display_destroy(disp);
}
PCUT_TEST(display_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 = false;
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, &w1);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = ds_window_create(client, ¶ms, &w0);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
wnd = ds_display_first_window(disp);
PCUT_ASSERT_EQUALS(w0, wnd);
wnd = ds_display_next_window(wnd);
PCUT_ASSERT_EQUALS(w1, wnd);
wnd = ds_display_next_window(wnd);
PCUT_ASSERT_NULL(wnd);
wnd = ds_display_last_window(disp);
PCUT_ASSERT_EQUALS(w1, wnd);
wnd = ds_display_prev_window(wnd);
PCUT_ASSERT_EQUALS(w0, wnd);
wnd = ds_display_prev_window(wnd);
PCUT_ASSERT_NULL(wnd);
wnd = ds_display_find_window(disp, w0->id);
PCUT_ASSERT_EQUALS(w0, wnd);
wnd = ds_display_find_window(disp, w1->id);
PCUT_ASSERT_EQUALS(w1, wnd);
wnd = ds_display_find_window(disp, 0);
PCUT_ASSERT_NULL(wnd);
wnd = ds_display_find_window(disp, w0->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(display_enlist_window)
{
ds_display_t *disp;
ds_client_t *client;
ds_seat_t *seat;
ds_window_t *w0;
ds_window_t *w1;
ds_window_t *w2;
ds_window_t *w3;
ds_window_t *w;
display_wnd_params_t params;
bool called_cb = false;
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 = 100;
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);
params.flags |= wndf_topmost;
rc = ds_window_create(client, ¶ms, &w2);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = ds_window_create(client, ¶ms, &w3);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
list_remove(&w1->ldwindows);
list_remove(&w2->ldwindows);
ds_display_enlist_window(disp, w1);
ds_display_enlist_window(disp, w2);
w = ds_display_first_window(disp);
PCUT_ASSERT_EQUALS(w2, w);
w = ds_display_next_window(w);
PCUT_ASSERT_EQUALS(w3, w);
w = ds_display_next_window(w);
PCUT_ASSERT_EQUALS(w1, w);
w = ds_display_next_window(w);
PCUT_ASSERT_EQUALS(w0, w);
w = ds_display_next_window(w);
PCUT_ASSERT_EQUALS(NULL, w);
ds_window_destroy(w0);
ds_window_destroy(w1);
ds_window_destroy(w2);
ds_window_destroy(w3);
ds_seat_destroy(seat);
ds_client_destroy(client);
ds_display_destroy(disp);
}
PCUT_TEST(display_window_to_top)
{
ds_display_t *disp;
ds_client_t *client;
ds_seat_t *seat;
ds_window_t *w0;
ds_window_t *w1;
display_wnd_params_t params;
bool called_cb = false;
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 = 100;
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);
PCUT_ASSERT_EQUALS(w1, ds_display_first_window(disp));
ds_display_window_to_top(w0);
PCUT_ASSERT_EQUALS(w0, ds_display_first_window(disp));
ds_window_destroy(w0);
ds_window_destroy(w1);
ds_seat_destroy(seat);
ds_client_destroy(client);
ds_display_destroy(disp);
}
PCUT_TEST(display_window_by_pos)
{
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;
gfx_coord2_t pos;
bool called_cb = false;
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 = 100;
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);
w0->dpos.x = 10;
w0->dpos.y = 10;
w1->dpos.x = 400;
w1->dpos.y = 400;
pos.x = 10;
pos.y = 10;
wnd = ds_display_window_by_pos(disp, &pos);
PCUT_ASSERT_EQUALS(w0, wnd);
pos.x = 400;
pos.y = 400;
wnd = ds_display_window_by_pos(disp, &pos);
PCUT_ASSERT_EQUALS(w1, wnd);
ds_window_destroy(w0);
ds_window_destroy(w1);
ds_seat_destroy(seat);
ds_client_destroy(client);
ds_display_destroy(disp);
}
PCUT_TEST(display_idevcfg)
{
ds_display_t *disp;
ds_seat_t *seat;
ds_idevcfg_t *idevcfg;
errno_t rc;
rc = ds_display_create(NULL, df_none, &disp);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = ds_seat_create(disp, "Alice", &seat);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = ds_idevcfg_create(disp, 42, seat, &idevcfg);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
ds_idevcfg_destroy(idevcfg);
ds_seat_destroy(seat);
ds_display_destroy(disp);
}
PCUT_TEST(display_seat)
{
ds_display_t *disp;
ds_seat_t *seat;
ds_seat_t *s0, *s1, *s2;
errno_t rc;
rc = ds_display_create(NULL, df_none, &disp);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = ds_seat_create(disp, "Alice", &seat);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
s0 = ds_display_first_seat(disp);
PCUT_ASSERT_EQUALS(s0, seat);
s1 = ds_display_next_seat(s0);
PCUT_ASSERT_NULL(s1);
s2 = ds_display_find_seat(disp, seat->id);
PCUT_ASSERT_EQUALS(s2, seat);
ds_seat_destroy(seat);
ds_display_destroy(disp);
}
PCUT_TEST(display_seat_by_idev)
{
}
PCUT_TEST(display_post_kbd_event)
{
ds_display_t *disp;
ds_seat_t *seat;
ds_client_t *client;
ds_window_t *wnd;
display_wnd_params_t params;
kbd_event_t event;
bool called_cb = false;
errno_t rc;
rc = ds_display_create(NULL, df_none, &disp);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = ds_seat_create(disp, "Alice", &seat);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
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_set_focus(seat, wnd);
event.type = KEY_PRESS;
event.key = KC_ENTER;
event.mods = 0;
event.c = L'\0';
called_cb = false;
rc = ds_display_post_kbd_event(disp, &event);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_TRUE(called_cb);
ds_window_destroy(wnd);
ds_client_destroy(client);
ds_seat_destroy(seat);
ds_display_destroy(disp);
}
PCUT_TEST(display_post_kbd_event_alt_tab)
{
ds_display_t *disp;
ds_seat_t *seat;
ds_client_t *client;
ds_window_t *w0, *w1;
display_wnd_params_t params;
kbd_event_t event;
bool called_cb = false;
errno_t rc;
rc = ds_display_create(NULL, df_none, &disp);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = ds_seat_create(disp, "Alice", &seat);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
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);
ds_seat_set_focus(seat, w0);
event.type = KEY_PRESS;
event.key = KC_TAB;
event.mods = KM_ALT;
event.c = L'\0';
called_cb = false;
rc = ds_display_post_kbd_event(disp, &event);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_TRUE(called_cb);
PCUT_ASSERT_EQUALS(w1, seat->focus);
called_cb = false;
rc = ds_display_post_kbd_event(disp, &event);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_TRUE(called_cb);
PCUT_ASSERT_EQUALS(w0, seat->focus);
ds_window_destroy(w0);
ds_window_destroy(w1);
ds_client_destroy(client);
ds_seat_destroy(seat);
ds_display_destroy(disp);
}
PCUT_TEST(display_post_ptd_event_wnd_switch)
{
ds_display_t *disp;
ds_seat_t *seat;
ds_client_t *client;
ds_window_t *w0, *w1;
display_wnd_params_t params;
ptd_event_t event;
bool called_cb = false;
errno_t rc;
rc = ds_display_create(NULL, df_none, &disp);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = ds_seat_create(disp, "Alice", &seat);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
disp->rect.p0.x = 0;
disp->rect.p0.y = 0;
disp->rect.p1.x = 500;
disp->rect.p1.y = 500;
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);
w0->dpos.x = 10;
w0->dpos.y = 10;
w1->dpos.x = 400;
w1->dpos.y = 400;
ds_seat_set_focus(seat, w0);
event.type = PTD_MOVE;
event.dmove.x = 400;
event.dmove.y = 400;
rc = ds_display_post_ptd_event(disp, &event);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
event.type = PTD_PRESS;
event.btn_num = 1;
rc = ds_display_post_ptd_event(disp, &event);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_EQUALS(w1, seat->focus);
event.type = PTD_RELEASE;
event.btn_num = 1;
rc = ds_display_post_ptd_event(disp, &event);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
event.type = PTD_MOVE;
event.dmove.x = -400 + 10;
event.dmove.y = -400 + 10;
rc = ds_display_post_ptd_event(disp, &event);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
event.type = PTD_PRESS;
event.btn_num = 1;
rc = ds_display_post_ptd_event(disp, &event);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_EQUALS(w0, seat->focus);
ds_window_destroy(w0);
ds_window_destroy(w1);
ds_client_destroy(client);
ds_seat_destroy(seat);
ds_display_destroy(disp);
}
PCUT_TEST(display_update_max_rect)
{
ds_display_t *disp;
ds_seat_t *seat;
ds_client_t *client;
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_seat_create(disp, "Alice", &seat);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = ds_client_create(disp, NULL, NULL, &client);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
disp->rect.p0.x = 0;
disp->rect.p0.y = 0;
disp->rect.p1.x = 500;
disp->rect.p1.y = 500;
disp->max_rect = disp->rect;
display_wnd_params_init(¶ms);
params.flags |= wndf_setpos;
params.pos.x = 0;
params.pos.y = 450;
params.rect.p0.x = 0;
params.rect.p0.y = 0;
params.rect.p1.x = 500;
params.rect.p1.y = 50;
rc = ds_window_create(client, ¶ms, &wnd);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_INT_EQUALS(0, disp->max_rect.p0.x);
PCUT_ASSERT_INT_EQUALS(0, disp->max_rect.p0.y);
PCUT_ASSERT_INT_EQUALS(500, disp->max_rect.p1.x);
PCUT_ASSERT_INT_EQUALS(500, disp->max_rect.p1.y);
wnd->flags |= wndf_avoid;
ds_display_update_max_rect(disp);
PCUT_ASSERT_INT_EQUALS(0, disp->max_rect.p0.x);
PCUT_ASSERT_INT_EQUALS(0, disp->max_rect.p0.y);
PCUT_ASSERT_INT_EQUALS(500, disp->max_rect.p1.x);
PCUT_ASSERT_INT_EQUALS(450, disp->max_rect.p1.y);
ds_window_destroy(wnd);
ds_client_destroy(client);
ds_seat_destroy(seat);
ds_display_destroy(disp);
}
PCUT_TEST(display_crop_max_rect_top)
{
gfx_rect_t arect;
gfx_rect_t mrect;
arect.p0.x = 10;
arect.p0.y = 20;
arect.p1.x = 30;
arect.p1.y = 5;
mrect.p0.x = 10;
mrect.p0.y = 20;
mrect.p1.x = 30;
mrect.p1.y = 40;
ds_display_crop_max_rect(&arect, &mrect);
PCUT_ASSERT_INT_EQUALS(10, mrect.p0.x);
PCUT_ASSERT_INT_EQUALS(5, mrect.p0.y);
PCUT_ASSERT_INT_EQUALS(30, mrect.p1.x);
PCUT_ASSERT_INT_EQUALS(40, mrect.p1.y);
}
PCUT_TEST(display_crop_max_rect_bottom)
{
gfx_rect_t arect;
gfx_rect_t mrect;
arect.p0.x = 10;
arect.p0.y = 35;
arect.p1.x = 30;
arect.p1.y = 40;
mrect.p0.x = 10;
mrect.p0.y = 20;
mrect.p1.x = 30;
mrect.p1.y = 40;
ds_display_crop_max_rect(&arect, &mrect);
PCUT_ASSERT_INT_EQUALS(10, mrect.p0.x);
PCUT_ASSERT_INT_EQUALS(20, mrect.p0.y);
PCUT_ASSERT_INT_EQUALS(30, mrect.p1.x);
PCUT_ASSERT_INT_EQUALS(35, mrect.p1.y);
}
PCUT_TEST(display_crop_max_rect_left)
{
gfx_rect_t arect;
gfx_rect_t mrect;
arect.p0.x = 10;
arect.p0.y = 20;
arect.p1.x = 15;
arect.p1.y = 40;
mrect.p0.x = 10;
mrect.p0.y = 20;
mrect.p1.x = 30;
mrect.p1.y = 40;
ds_display_crop_max_rect(&arect, &mrect);
PCUT_ASSERT_INT_EQUALS(15, mrect.p0.x);
PCUT_ASSERT_INT_EQUALS(20, mrect.p0.y);
PCUT_ASSERT_INT_EQUALS(30, mrect.p1.x);
PCUT_ASSERT_INT_EQUALS(40, mrect.p1.y);
}
PCUT_TEST(display_crop_max_rect_right)
{
gfx_rect_t arect;
gfx_rect_t mrect;
arect.p0.x = 25;
arect.p0.y = 20;
arect.p1.x = 30;
arect.p1.y = 40;
mrect.p0.x = 10;
mrect.p0.y = 20;
mrect.p1.x = 30;
mrect.p1.y = 40;
ds_display_crop_max_rect(&arect, &mrect);
PCUT_ASSERT_INT_EQUALS(10, mrect.p0.x);
PCUT_ASSERT_INT_EQUALS(20, mrect.p0.y);
PCUT_ASSERT_INT_EQUALS(25, mrect.p1.x);
PCUT_ASSERT_INT_EQUALS(40, mrect.p1.y);
}
PCUT_EXPORT(display);
HelenOS homepage, sources at GitHub