HelenOS sources
This source file includes following definitions.
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- test_popup_close
- test_popup_kbd
- test_popup_paint
- test_popup_pos
- 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/popup.h>
#include <ui/resource.h>
#include <ui/ui.h>
#include <ui/window.h>
#include "../private/popup.h"
#include "../private/window.h"
PCUT_INIT;
PCUT_TEST_SUITE(popup);
static void test_popup_close(ui_popup_t *, void *);
static void test_popup_kbd(ui_popup_t *, void *, kbd_event_t *);
static errno_t test_popup_paint(ui_popup_t *, void *);
static void test_popup_pos(ui_popup_t *, void *, pos_event_t *);
static ui_popup_cb_t test_popup_cb = {
.close = test_popup_close,
.kbd = test_popup_kbd,
.paint = test_popup_paint,
.pos = test_popup_pos,
};
static ui_popup_cb_t dummy_popup_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 close;
bool focus;
bool kbd;
kbd_event_t kbd_event;
bool paint;
bool pos;
pos_event_t pos_event;
bool unfocus;
} 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 wparams;
ui_window_t *window = NULL;
ui_popup_params_t params;
ui_popup_t *popup = NULL;
rc = ui_create_disp(NULL, &ui);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
ui_wnd_params_init(&wparams);
wparams.caption = "Hello";
rc = ui_window_create(ui, &wparams, &window);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(window);
ui_popup_params_init(¶ms);
rc = ui_popup_create(ui, window, ¶ms, &popup);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(popup);
ui_popup_destroy(popup);
ui_window_destroy(window);
ui_destroy(ui);
}
PCUT_TEST(destroy_null)
{
ui_popup_destroy(NULL);
}
PCUT_TEST(add_remove)
{
errno_t rc;
ui_t *ui = NULL;
ui_wnd_params_t wparams;
ui_window_t *window = NULL;
ui_popup_params_t params;
ui_popup_t *popup = 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(&wparams);
wparams.caption = "Hello";
rc = ui_window_create(ui, &wparams, &window);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(window);
ui_popup_params_init(¶ms);
rc = ui_popup_create(ui, window, ¶ms, &popup);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(popup);
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(popup->window);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_FALSE(resp.paint);
ui_popup_add(popup, control);
resp.rc = EOK;
resp.paint = false;
rc = ui_window_def_paint(popup->window);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_TRUE(resp.paint);
ui_popup_remove(popup, control);
resp.rc = ENOMEM;
resp.paint = false;
rc = ui_window_def_paint(popup->window);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_FALSE(resp.paint);
ui_popup_destroy(popup);
ui_window_destroy(window);
ui_destroy(ui);
}
PCUT_TEST(get_res_gc)
{
errno_t rc;
ui_t *ui = NULL;
ui_wnd_params_t wparams;
ui_window_t *window = NULL;
ui_popup_params_t params;
ui_popup_t *popup = NULL;
ui_resource_t *res;
gfx_context_t *gc;
rc = ui_create_disp(NULL, &ui);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
ui_wnd_params_init(&wparams);
wparams.caption = "Hello";
rc = ui_window_create(ui, &wparams, &window);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(window);
ui_popup_params_init(¶ms);
rc = ui_popup_create(ui, window, ¶ms, &popup);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(popup);
res = ui_popup_get_res(popup);
PCUT_ASSERT_NOT_NULL(res);
gc = ui_popup_get_gc(popup);
PCUT_ASSERT_NOT_NULL(gc);
ui_popup_destroy(popup);
ui_window_destroy(window);
ui_destroy(ui);
}
PCUT_TEST(send_pos)
{
errno_t rc;
ui_t *ui = NULL;
ui_wnd_params_t wparams;
ui_window_t *window = NULL;
ui_popup_params_t params;
ui_popup_t *popup = 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(&wparams);
wparams.caption = "Hello";
rc = ui_window_create(ui, &wparams, &window);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(window);
ui_popup_params_init(¶ms);
rc = ui_popup_create(ui, window, ¶ms, &popup);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(popup);
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(popup->window, &pos_event);
ui_popup_set_cb(popup, &dummy_popup_cb, NULL);
ui_window_send_pos(popup->window, &pos_event);
resp.pos = false;
ui_popup_set_cb(popup, &test_popup_cb, &resp);
ui_window_send_pos(popup->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_popup_destroy(popup);
ui_window_destroy(window);
ui_destroy(ui);
}
static void test_popup_close(ui_popup_t *popup, void *arg)
{
test_cb_resp_t *resp = (test_cb_resp_t *) arg;
resp->close = true;
}
static void test_popup_kbd(ui_popup_t *popup, 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_popup_paint(ui_popup_t *popup, void *arg)
{
test_cb_resp_t *resp = (test_cb_resp_t *) arg;
resp->paint = true;
return resp->rc;
}
static void test_popup_pos(ui_popup_t *popup, void *arg,
pos_event_t *event)
{
test_cb_resp_t *resp = (test_cb_resp_t *) arg;
resp->pos = true;
resp->pos_event = *event;
}
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(popup);
HelenOS homepage, sources at GitHub