HelenOS sources
This source file includes following definitions.
- 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
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- test_window_sysmenu
- test_window_minimize
- test_window_maximize
- test_window_unmaximize
- test_window_close
- test_window_focus
- test_window_kbd
- test_window_paint
- test_window_pos
- test_window_unfocus
- test_window_resize
- test_ctl_paint
- test_ctl_pos_event
- test_ctl_unfocus
#include <gfx/context.h>
#include <gfx/coord.h>
#include <gfx/render.h>
#include <io/kbd_event.h>
#include <io/pos_event.h>
#include <mem.h>
#include <pcut/pcut.h>
#include <stdbool.h>
#include <ui/control.h>
#include <ui/resource.h>
#include <ui/ui.h>
#include <ui/window.h>
#include "../private/window.h"
PCUT_INIT;
PCUT_TEST_SUITE(window);
static void test_window_sysmenu(ui_window_t *, void *, sysarg_t);
static void test_window_minimize(ui_window_t *, void *);
static void test_window_maximize(ui_window_t *, void *);
static void test_window_unmaximize(ui_window_t *, void *);
static void test_window_close(ui_window_t *, void *);
static void test_window_focus(ui_window_t *, void *, unsigned);
static void test_window_kbd(ui_window_t *, void *, kbd_event_t *);
static errno_t test_window_paint(ui_window_t *, void *);
static void test_window_pos(ui_window_t *, void *, pos_event_t *);
static void test_window_unfocus(ui_window_t *, void *, unsigned);
static void test_window_resize(ui_window_t *, void *);
static ui_window_cb_t test_window_cb = {
.sysmenu = test_window_sysmenu,
.minimize = test_window_minimize,
.maximize = test_window_maximize,
.unmaximize = test_window_unmaximize,
.close = test_window_close,
.focus = test_window_focus,
.kbd = test_window_kbd,
.paint = test_window_paint,
.pos = test_window_pos,
.unfocus = test_window_unfocus,
.resize = test_window_resize
};
static ui_window_cb_t dummy_window_cb = {
};
static errno_t test_ctl_paint(void *);
static ui_evclaim_t test_ctl_pos_event(void *, pos_event_t *);
static void test_ctl_unfocus(void *, unsigned);
static ui_control_ops_t test_ctl_ops = {
.paint = test_ctl_paint,
.pos_event = test_ctl_pos_event,
.unfocus = test_ctl_unfocus
};
typedef struct {
errno_t rc;
bool sysmenu;
sysarg_t sysmenu_idev_id;
bool minimize;
bool maximize;
bool unmaximize;
bool close;
bool focus;
unsigned focus_nfocus;
bool kbd;
kbd_event_t kbd_event;
bool paint;
bool pos;
pos_event_t pos_event;
bool unfocus;
unsigned unfocus_nfocus;
bool resize;
} test_cb_resp_t;
typedef struct {
errno_t rc;
ui_evclaim_t claim;
bool paint;
bool pos;
pos_event_t pos_event;
bool unfocus;
unsigned unfocus_nfocus;
} test_ctl_resp_t;
PCUT_TEST(create_destroy)
{
errno_t rc;
ui_t *ui = NULL;
ui_wnd_params_t params;
ui_window_t *window = NULL;
rc = ui_create_disp(NULL, &ui);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
ui_wnd_params_init(¶ms);
params.caption = "Hello";
rc = ui_window_create(ui, ¶ms, &window);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(window);
ui_window_destroy(window);
ui_destroy(ui);
}
PCUT_TEST(destroy_null)
{
ui_window_destroy(NULL);
}
PCUT_TEST(add_remove)
{
errno_t rc;
ui_t *ui = NULL;
ui_wnd_params_t params;
ui_window_t *window = NULL;
ui_control_t *control = NULL;
test_ctl_resp_t resp;
rc = ui_create_disp(NULL, &ui);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
ui_wnd_params_init(¶ms);
params.caption = "Hello";
rc = ui_window_create(ui, ¶ms, &window);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(window);
rc = ui_control_new(&test_ctl_ops, &resp, &control);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
resp.rc = ENOMEM;
resp.paint = false;
rc = ui_window_def_paint(window);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_FALSE(resp.paint);
ui_window_add(window, control);
resp.rc = EOK;
resp.paint = false;
rc = ui_window_def_paint(window);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_TRUE(resp.paint);
ui_window_remove(window, control);
resp.rc = ENOMEM;
resp.paint = false;
rc = ui_window_def_paint(window);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_FALSE(resp.paint);
ui_window_destroy(window);
ui_destroy(ui);
}
PCUT_TEST(get_active)
{
errno_t rc;
ui_t *ui = NULL;
ui_wnd_params_t params;
ui_window_t *window1 = NULL;
ui_window_t *window2 = NULL;
ui_window_t *awnd;
rc = ui_create_cons(NULL, &ui);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
awnd = ui_window_get_active(ui);
PCUT_ASSERT_NULL(awnd);
ui_wnd_params_init(¶ms);
params.caption = "Hello";
rc = ui_window_create(ui, ¶ms, &window1);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(window1);
awnd = ui_window_get_active(ui);
PCUT_ASSERT_EQUALS(window1, awnd);
rc = ui_window_create(ui, ¶ms, &window2);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(window2);
awnd = ui_window_get_active(ui);
PCUT_ASSERT_EQUALS(window2, awnd);
ui_window_destroy(window2);
awnd = ui_window_get_active(ui);
PCUT_ASSERT_EQUALS(window1, awnd);
ui_window_destroy(window1);
awnd = ui_window_get_active(ui);
PCUT_ASSERT_NULL(awnd);
ui_destroy(ui);
}
PCUT_TEST(resize)
{
errno_t rc;
ui_t *ui = NULL;
ui_wnd_params_t params;
ui_window_t *window = NULL;
gfx_rect_t nrect;
rc = ui_create_disp(NULL, &ui);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
ui_wnd_params_init(¶ms);
params.caption = "Hello";
params.rect.p0.x = 0;
params.rect.p0.y = 0;
params.rect.p1.x = 1;
params.rect.p1.y = 1;
rc = ui_window_create(ui, ¶ms, &window);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(window);
nrect.p0.x = -1;
nrect.p0.y = -1;
nrect.p1.x = 2;
nrect.p1.y = 2;
rc = ui_window_resize(window, &nrect);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
ui_window_destroy(window);
ui_destroy(ui);
}
PCUT_TEST(get_ui)
{
errno_t rc;
ui_t *ui = NULL;
ui_t *rui;
ui_wnd_params_t params;
ui_window_t *window = NULL;
rc = ui_create_disp(NULL, &ui);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
ui_wnd_params_init(¶ms);
params.caption = "Hello";
rc = ui_window_create(ui, ¶ms, &window);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(window);
rui = ui_window_get_ui(window);
PCUT_ASSERT_EQUALS(ui, rui);
ui_window_destroy(window);
ui_destroy(ui);
}
PCUT_TEST(get_res_gc_rect)
{
errno_t rc;
ui_t *ui = NULL;
ui_wnd_params_t params;
ui_window_t *window = NULL;
ui_resource_t *res;
gfx_context_t *gc;
gfx_rect_t rect;
rc = ui_create_disp(NULL, &ui);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
ui_wnd_params_init(¶ms);
params.caption = "Hello";
rc = ui_window_create(ui, ¶ms, &window);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(window);
res = ui_window_get_res(window);
PCUT_ASSERT_NOT_NULL(res);
gc = ui_window_get_gc(window);
PCUT_ASSERT_NOT_NULL(gc);
ui_window_get_app_rect(window, &rect);
ui_window_destroy(window);
ui_destroy(ui);
}
PCUT_TEST(set_ctl_cursor)
{
errno_t rc;
ui_t *ui = NULL;
ui_wnd_params_t params;
ui_window_t *window = NULL;
rc = ui_create_disp(NULL, &ui);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
ui_wnd_params_init(¶ms);
params.caption = "Hello";
rc = ui_window_create(ui, ¶ms, &window);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(window);
ui_window_set_ctl_cursor(window, ui_curs_ibeam);
ui_window_destroy(window);
ui_destroy(ui);
}
PCUT_TEST(get_app_gc)
{
errno_t rc;
ui_t *ui = NULL;
ui_wnd_params_t params;
ui_window_t *window = NULL;
gfx_context_t *gc;
rc = ui_create_disp(NULL, &ui);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
ui_wnd_params_init(¶ms);
params.caption = "Hello";
params.rect.p0.x = 0;
params.rect.p0.y = 0;
params.rect.p0.x = 100;
params.rect.p0.y = 100;
rc = ui_window_create(ui, ¶ms, &window);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(window);
rc = ui_window_get_app_gc(window, &gc);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(gc);
rc = gfx_fill_rect(gc, ¶ms.rect);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
ui_window_destroy(window);
ui_destroy(ui);
}
PCUT_TEST(paint)
{
errno_t rc;
ui_t *ui = NULL;
ui_wnd_params_t params;
ui_window_t *window = NULL;
rc = ui_create_disp(NULL, &ui);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
ui_wnd_params_init(¶ms);
params.caption = "Hello";
rc = ui_window_create(ui, ¶ms, &window);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(window);
ui_window_paint(window);
ui_window_destroy(window);
ui_destroy(ui);
}
PCUT_TEST(def_paint)
{
errno_t rc;
ui_t *ui = NULL;
ui_wnd_params_t params;
ui_window_t *window = NULL;
ui_control_t *control = NULL;
test_ctl_resp_t resp;
rc = ui_create_disp(NULL, &ui);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
ui_wnd_params_init(¶ms);
params.caption = "Hello";
rc = ui_window_create(ui, ¶ms, &window);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(window);
rc = ui_control_new(&test_ctl_ops, &resp, &control);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
ui_window_add(window, control);
resp.rc = EOK;
resp.paint = false;
rc = ui_window_def_paint(window);
PCUT_ASSERT_ERRNO_VAL(resp.rc, rc);
PCUT_ASSERT_TRUE(resp.paint);
resp.rc = ENOMEM;
resp.paint = false;
rc = ui_window_def_paint(window);
PCUT_ASSERT_ERRNO_VAL(resp.rc, rc);
PCUT_ASSERT_TRUE(resp.paint);
PCUT_ASSERT_TRUE(resp.paint);
ui_window_remove(window, control);
ui_window_destroy(window);
ui_destroy(ui);
}
PCUT_TEST(def_pos)
{
errno_t rc;
ui_t *ui = NULL;
ui_wnd_params_t params;
ui_window_t *window = NULL;
ui_control_t *control = NULL;
test_ctl_resp_t resp;
pos_event_t event;
rc = ui_create_disp(NULL, &ui);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
ui_wnd_params_init(¶ms);
params.caption = "Hello";
rc = ui_window_create(ui, ¶ms, &window);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = ui_control_new(&test_ctl_ops, &resp, &control);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
ui_window_add(window, control);
event.pos_id = 1;
event.type = POS_PRESS;
event.btn_num = 2;
event.hpos = 3;
event.vpos = 4;
resp.pos = false;
resp.claim = ui_claimed;
ui_window_def_pos(window, &event);
PCUT_ASSERT_TRUE(resp.pos);
PCUT_ASSERT_INT_EQUALS(event.pos_id, resp.pos_event.pos_id);
PCUT_ASSERT_INT_EQUALS(event.type, resp.pos_event.type);
PCUT_ASSERT_INT_EQUALS(event.btn_num, resp.pos_event.btn_num);
PCUT_ASSERT_INT_EQUALS(event.hpos, resp.pos_event.hpos);
PCUT_ASSERT_INT_EQUALS(event.vpos, resp.pos_event.vpos);
ui_window_remove(window, control);
ui_window_destroy(window);
ui_destroy(ui);
}
PCUT_TEST(def_unfocus)
{
errno_t rc;
ui_t *ui = NULL;
ui_wnd_params_t params;
ui_window_t *window = NULL;
ui_control_t *control = NULL;
test_ctl_resp_t resp;
rc = ui_create_disp(NULL, &ui);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
ui_wnd_params_init(¶ms);
params.caption = "Hello";
rc = ui_window_create(ui, ¶ms, &window);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = ui_control_new(&test_ctl_ops, &resp, &control);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
ui_window_add(window, control);
resp.unfocus = false;
ui_window_def_unfocus(window, 42);
PCUT_ASSERT_TRUE(resp.unfocus);
PCUT_ASSERT_INT_EQUALS(42, resp.unfocus_nfocus);
ui_window_remove(window, control);
ui_window_destroy(window);
ui_destroy(ui);
}
PCUT_TEST(send_sysmenu)
{
errno_t rc;
ui_t *ui = NULL;
ui_wnd_params_t params;
ui_window_t *window = NULL;
test_cb_resp_t resp;
rc = ui_create_disp(NULL, &ui);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
ui_wnd_params_init(¶ms);
params.caption = "Hello";
rc = ui_window_create(ui, ¶ms, &window);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(window);
ui_window_send_sysmenu(window, 42);
ui_window_set_cb(window, &dummy_window_cb, NULL);
ui_window_send_sysmenu(window, 42);
resp.sysmenu = false;
resp.sysmenu_idev_id = 0;
ui_window_set_cb(window, &test_window_cb, &resp);
ui_window_send_sysmenu(window, 42);
PCUT_ASSERT_TRUE(resp.sysmenu);
PCUT_ASSERT_INT_EQUALS(42, resp.sysmenu_idev_id);
ui_window_destroy(window);
ui_destroy(ui);
}
PCUT_TEST(send_minimize)
{
errno_t rc;
ui_t *ui = NULL;
ui_wnd_params_t params;
ui_window_t *window = NULL;
test_cb_resp_t resp;
rc = ui_create_disp(NULL, &ui);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
ui_wnd_params_init(¶ms);
params.caption = "Hello";
rc = ui_window_create(ui, ¶ms, &window);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(window);
ui_window_send_minimize(window);
ui_window_set_cb(window, &dummy_window_cb, NULL);
ui_window_send_minimize(window);
resp.minimize = false;
ui_window_set_cb(window, &test_window_cb, &resp);
ui_window_send_minimize(window);
PCUT_ASSERT_TRUE(resp.minimize);
ui_window_destroy(window);
ui_destroy(ui);
}
PCUT_TEST(send_maximize)
{
errno_t rc;
ui_t *ui = NULL;
ui_wnd_params_t params;
ui_window_t *window = NULL;
test_cb_resp_t resp;
rc = ui_create_disp(NULL, &ui);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
ui_wnd_params_init(¶ms);
params.caption = "Hello";
rc = ui_window_create(ui, ¶ms, &window);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(window);
ui_window_send_maximize(window);
ui_window_set_cb(window, &dummy_window_cb, NULL);
ui_window_send_maximize(window);
resp.maximize = false;
ui_window_set_cb(window, &test_window_cb, &resp);
ui_window_send_maximize(window);
PCUT_ASSERT_TRUE(resp.maximize);
ui_window_destroy(window);
ui_destroy(ui);
}
PCUT_TEST(send_unmaximize)
{
errno_t rc;
ui_t *ui = NULL;
ui_wnd_params_t params;
ui_window_t *window = NULL;
test_cb_resp_t resp;
rc = ui_create_disp(NULL, &ui);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
ui_wnd_params_init(¶ms);
params.caption = "Hello";
rc = ui_window_create(ui, ¶ms, &window);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(window);
ui_window_send_unmaximize(window);
ui_window_set_cb(window, &dummy_window_cb, NULL);
ui_window_send_unmaximize(window);
resp.unmaximize = false;
ui_window_set_cb(window, &test_window_cb, &resp);
ui_window_send_unmaximize(window);
PCUT_ASSERT_TRUE(resp.unmaximize);
ui_window_destroy(window);
ui_destroy(ui);
}
PCUT_TEST(send_close)
{
errno_t rc;
ui_t *ui = NULL;
ui_wnd_params_t params;
ui_window_t *window = NULL;
test_cb_resp_t resp;
rc = ui_create_disp(NULL, &ui);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
ui_wnd_params_init(¶ms);
params.caption = "Hello";
rc = ui_window_create(ui, ¶ms, &window);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(window);
ui_window_send_close(window);
ui_window_set_cb(window, &dummy_window_cb, NULL);
ui_window_send_close(window);
resp.close = false;
ui_window_set_cb(window, &test_window_cb, &resp);
ui_window_send_close(window);
PCUT_ASSERT_TRUE(resp.close);
ui_window_destroy(window);
ui_destroy(ui);
}
PCUT_TEST(send_focus)
{
errno_t rc;
ui_t *ui = NULL;
ui_wnd_params_t params;
ui_window_t *window = NULL;
test_cb_resp_t resp;
rc = ui_create_disp(NULL, &ui);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
ui_wnd_params_init(¶ms);
params.caption = "Hello";
rc = ui_window_create(ui, ¶ms, &window);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(window);
ui_window_send_focus(window, 42);
ui_window_set_cb(window, &dummy_window_cb, NULL);
ui_window_send_focus(window, 42);
resp.focus = false;
ui_window_set_cb(window, &test_window_cb, &resp);
ui_window_send_focus(window, 42);
PCUT_ASSERT_TRUE(resp.focus);
PCUT_ASSERT_INT_EQUALS(42, resp.focus_nfocus);
ui_window_destroy(window);
ui_destroy(ui);
}
PCUT_TEST(send_kbd)
{
errno_t rc;
ui_t *ui = NULL;
ui_wnd_params_t params;
ui_window_t *window = NULL;
kbd_event_t kbd_event;
test_cb_resp_t resp;
rc = ui_create_disp(NULL, &ui);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
ui_wnd_params_init(¶ms);
params.caption = "Hello";
rc = ui_window_create(ui, ¶ms, &window);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(window);
kbd_event.type = KEY_PRESS;
kbd_event.key = KC_X;
kbd_event.mods = 0;
kbd_event.c = 'x';
ui_window_send_kbd(window, &kbd_event);
ui_window_set_cb(window, &dummy_window_cb, NULL);
ui_window_send_kbd(window, &kbd_event);
resp.kbd = false;
ui_window_set_cb(window, &test_window_cb, &resp);
ui_window_send_kbd(window, &kbd_event);
PCUT_ASSERT_TRUE(resp.kbd);
PCUT_ASSERT_EQUALS(kbd_event.type, resp.kbd_event.type);
PCUT_ASSERT_INT_EQUALS(kbd_event.key, resp.kbd_event.key);
PCUT_ASSERT_INT_EQUALS(kbd_event.mods, resp.kbd_event.mods);
PCUT_ASSERT_INT_EQUALS(kbd_event.c, resp.kbd_event.c);
ui_window_destroy(window);
ui_destroy(ui);
}
PCUT_TEST(send_paint)
{
errno_t rc;
ui_t *ui = NULL;
ui_wnd_params_t params;
ui_window_t *window = NULL;
test_cb_resp_t resp;
rc = ui_create_disp(NULL, &ui);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
ui_wnd_params_init(¶ms);
params.caption = "Hello";
rc = ui_window_create(ui, ¶ms, &window);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(window);
ui_window_send_paint(window);
ui_window_set_cb(window, &dummy_window_cb, NULL);
ui_window_send_paint(window);
resp.paint = false;
resp.rc = EOK;
ui_window_set_cb(window, &test_window_cb, &resp);
rc = ui_window_send_paint(window);
PCUT_ASSERT_ERRNO_VAL(resp.rc, rc);
PCUT_ASSERT_TRUE(resp.paint);
ui_window_destroy(window);
ui_destroy(ui);
}
PCUT_TEST(send_pos)
{
errno_t rc;
ui_t *ui = NULL;
ui_wnd_params_t params;
ui_window_t *window = NULL;
pos_event_t pos_event;
test_cb_resp_t resp;
rc = ui_create_disp(NULL, &ui);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
ui_wnd_params_init(¶ms);
params.caption = "Hello";
rc = ui_window_create(ui, ¶ms, &window);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(window);
pos_event.pos_id = 1;
pos_event.type = POS_PRESS;
pos_event.btn_num = 2;
pos_event.hpos = 3;
pos_event.vpos = 4;
ui_window_send_pos(window, &pos_event);
ui_window_set_cb(window, &dummy_window_cb, NULL);
ui_window_send_pos(window, &pos_event);
resp.pos = false;
ui_window_set_cb(window, &test_window_cb, &resp);
ui_window_send_pos(window, &pos_event);
PCUT_ASSERT_TRUE(resp.pos);
PCUT_ASSERT_INT_EQUALS(pos_event.pos_id, resp.pos_event.pos_id);
PCUT_ASSERT_EQUALS(pos_event.type, resp.pos_event.type);
PCUT_ASSERT_INT_EQUALS(pos_event.btn_num, resp.pos_event.btn_num);
PCUT_ASSERT_INT_EQUALS(pos_event.hpos, resp.pos_event.hpos);
PCUT_ASSERT_INT_EQUALS(pos_event.vpos, resp.pos_event.vpos);
ui_window_destroy(window);
ui_destroy(ui);
}
PCUT_TEST(send_unfocus)
{
errno_t rc;
ui_t *ui = NULL;
ui_wnd_params_t params;
ui_window_t *window = NULL;
test_cb_resp_t resp;
rc = ui_create_disp(NULL, &ui);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
ui_wnd_params_init(¶ms);
params.caption = "Hello";
rc = ui_window_create(ui, ¶ms, &window);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(window);
ui_window_send_unfocus(window, 42);
ui_window_set_cb(window, &dummy_window_cb, NULL);
ui_window_send_unfocus(window, 42);
resp.close = false;
ui_window_set_cb(window, &test_window_cb, &resp);
ui_window_send_unfocus(window, 42);
PCUT_ASSERT_TRUE(resp.unfocus);
PCUT_ASSERT_INT_EQUALS(42, resp.unfocus_nfocus);
ui_window_destroy(window);
ui_destroy(ui);
}
PCUT_TEST(send_resize)
{
errno_t rc;
ui_t *ui = NULL;
ui_wnd_params_t params;
ui_window_t *window = NULL;
test_cb_resp_t resp;
rc = ui_create_disp(NULL, &ui);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
ui_wnd_params_init(¶ms);
params.caption = "Hello";
rc = ui_window_create(ui, ¶ms, &window);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(window);
ui_window_send_resize(window);
ui_window_set_cb(window, &dummy_window_cb, NULL);
ui_window_send_resize(window);
resp.close = false;
ui_window_set_cb(window, &test_window_cb, &resp);
ui_window_send_resize(window);
PCUT_ASSERT_TRUE(resp.resize);
ui_window_destroy(window);
ui_destroy(ui);
}
static void test_window_sysmenu(ui_window_t *window, void *arg, sysarg_t idev_id)
{
test_cb_resp_t *resp = (test_cb_resp_t *) arg;
resp->sysmenu = true;
resp->sysmenu_idev_id = idev_id;
}
static void test_window_minimize(ui_window_t *window, void *arg)
{
test_cb_resp_t *resp = (test_cb_resp_t *) arg;
resp->minimize = true;
}
static void test_window_maximize(ui_window_t *window, void *arg)
{
test_cb_resp_t *resp = (test_cb_resp_t *) arg;
resp->maximize = true;
}
static void test_window_unmaximize(ui_window_t *window, void *arg)
{
test_cb_resp_t *resp = (test_cb_resp_t *) arg;
resp->unmaximize = true;
}
static void test_window_close(ui_window_t *window, void *arg)
{
test_cb_resp_t *resp = (test_cb_resp_t *) arg;
resp->close = true;
}
static void test_window_focus(ui_window_t *window, void *arg, unsigned nfocus)
{
test_cb_resp_t *resp = (test_cb_resp_t *) arg;
resp->focus = true;
resp->focus_nfocus = nfocus;
}
static void test_window_kbd(ui_window_t *window, void *arg,
kbd_event_t *event)
{
test_cb_resp_t *resp = (test_cb_resp_t *) arg;
resp->kbd = true;
resp->kbd_event = *event;
}
static errno_t test_window_paint(ui_window_t *window, void *arg)
{
test_cb_resp_t *resp = (test_cb_resp_t *) arg;
resp->paint = true;
return resp->rc;
}
static void test_window_pos(ui_window_t *window, void *arg,
pos_event_t *event)
{
test_cb_resp_t *resp = (test_cb_resp_t *) arg;
resp->pos = true;
resp->pos_event = *event;
}
static void test_window_unfocus(ui_window_t *window, void *arg, unsigned nfocus)
{
test_cb_resp_t *resp = (test_cb_resp_t *) arg;
resp->unfocus = true;
resp->unfocus_nfocus = nfocus;
}
static void test_window_resize(ui_window_t *window, void *arg)
{
test_cb_resp_t *resp = (test_cb_resp_t *) arg;
resp->resize = true;
}
static errno_t test_ctl_paint(void *arg)
{
test_ctl_resp_t *resp = (test_ctl_resp_t *) arg;
resp->paint = true;
return resp->rc;
}
static ui_evclaim_t test_ctl_pos_event(void *arg, pos_event_t *event)
{
test_ctl_resp_t *resp = (test_ctl_resp_t *) arg;
resp->pos = true;
resp->pos_event = *event;
return resp->claim;
}
static void test_ctl_unfocus(void *arg, unsigned nfocus)
{
test_ctl_resp_t *resp = (test_ctl_resp_t *) arg;
resp->unfocus = true;
resp->unfocus_nfocus = nfocus;
}
PCUT_EXPORT(window);
HelenOS homepage, sources at GitHub