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
- testmenu_left
- testmenu_right
- testmenu_close_req
- testmenu_press_accel
#include <gfx/context.h>
#include <gfx/coord.h>
#include <mem.h>
#include <pcut/pcut.h>
#include <stdbool.h>
#include <str.h>
#include <ui/control.h>
#include <ui/menu.h>
#include <ui/menubar.h>
#include <ui/menuentry.h>
#include <ui/ui.h>
#include <ui/window.h>
#include "../private/menu.h"
#include "../private/menubar.h"
PCUT_INIT;
PCUT_TEST_SUITE(menu);
typedef struct {
bool left_called;
bool right_called;
bool close_req_called;
bool press_accel_called;
ui_menu_t *menu;
sysarg_t idev_id;
char32_t c;
} test_resp_t;
static void testmenu_left(ui_menu_t *, void *, sysarg_t);
static void testmenu_right(ui_menu_t *, void *, sysarg_t);
static void testmenu_close_req(ui_menu_t *, void *);
static void testmenu_press_accel(ui_menu_t *, void *, char32_t, sysarg_t);
ui_menu_cb_t testmenu_cb = {
.left = testmenu_left,
.right = testmenu_right,
.close_req = testmenu_close_req,
.press_accel = testmenu_press_accel
};
ui_menu_cb_t dummy_cb = {
};
PCUT_TEST(create_destroy)
{
ui_menu_t *menu = NULL;
errno_t rc;
rc = ui_menu_create(NULL, &menu);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(menu);
ui_menu_destroy(menu);
}
PCUT_TEST(destroy_null)
{
ui_menu_destroy(NULL);
}
PCUT_TEST(set_cb)
{
ui_menu_t *menu = NULL;
ui_menu_cb_t cb;
int obj;
errno_t rc;
rc = ui_menu_create(NULL, &menu);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(menu);
ui_menu_set_cb(menu, &cb, (void *)&obj);
PCUT_ASSERT_EQUALS(&cb, menu->cb);
PCUT_ASSERT_EQUALS((void *)&obj, menu->arg);
ui_menu_destroy(menu);
}
PCUT_TEST(get_geom)
{
ui_t *ui = NULL;
ui_window_t *window = NULL;
ui_wnd_params_t params;
ui_menu_t *menu = NULL;
ui_menu_geom_t geom;
gfx_coord2_t pos;
errno_t rc;
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_menu_create(window, &menu);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(menu);
pos.x = 0;
pos.y = 0;
ui_menu_get_geom(menu, &pos, &geom);
PCUT_ASSERT_INT_EQUALS(0, geom.outer_rect.p0.x);
PCUT_ASSERT_INT_EQUALS(0, geom.outer_rect.p0.y);
PCUT_ASSERT_INT_EQUALS(16, geom.outer_rect.p1.x);
PCUT_ASSERT_INT_EQUALS(8, geom.outer_rect.p1.y);
PCUT_ASSERT_INT_EQUALS(4, geom.entries_rect.p0.x);
PCUT_ASSERT_INT_EQUALS(4, geom.entries_rect.p0.y);
PCUT_ASSERT_INT_EQUALS(12, geom.entries_rect.p1.x);
PCUT_ASSERT_INT_EQUALS(4, geom.entries_rect.p1.y);
ui_menu_destroy(menu);
ui_window_destroy(window);
ui_destroy(ui);
}
PCUT_TEST(get_res)
{
ui_t *ui = NULL;
ui_window_t *window = NULL;
ui_wnd_params_t params;
ui_menu_t *menu = NULL;
ui_resource_t *res;
gfx_rect_t prect;
errno_t rc;
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_menu_create(window, &menu);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(menu);
prect.p0.x = 0;
prect.p0.y = 0;
prect.p1.x = 0;
prect.p1.y = 0;
rc = ui_menu_open(menu, &prect, 0);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
res = ui_menu_get_res(menu);
PCUT_ASSERT_NOT_NULL(res);
ui_menu_destroy(menu);
ui_window_destroy(window);
ui_destroy(ui);
}
PCUT_TEST(open_close)
{
ui_t *ui = NULL;
ui_window_t *window = NULL;
ui_wnd_params_t params;
ui_menu_t *menu = NULL;
gfx_rect_t prect;
errno_t rc;
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_menu_create(window, &menu);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(menu);
prect.p0.x = 0;
prect.p0.y = 0;
prect.p1.x = 0;
prect.p1.y = 0;
rc = ui_menu_open(menu, &prect, 0);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
ui_menu_close(menu);
ui_menu_destroy(menu);
ui_window_destroy(window);
ui_destroy(ui);
}
PCUT_TEST(is_open)
{
ui_t *ui = NULL;
ui_window_t *window = NULL;
ui_wnd_params_t params;
ui_menu_t *menu = NULL;
gfx_rect_t prect;
bool open;
errno_t rc;
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_menu_create(window, &menu);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(menu);
prect.p0.x = 0;
prect.p0.y = 0;
prect.p1.x = 0;
prect.p1.y = 0;
open = ui_menu_is_open(menu);
PCUT_ASSERT_FALSE(open);
rc = ui_menu_open(menu, &prect, 0);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
open = ui_menu_is_open(menu);
PCUT_ASSERT_TRUE(open);
ui_menu_close(menu);
open = ui_menu_is_open(menu);
PCUT_ASSERT_FALSE(open);
ui_menu_destroy(menu);
ui_window_destroy(window);
ui_destroy(ui);
}
PCUT_TEST(paint_bg_gfx)
{
ui_t *ui = NULL;
ui_window_t *window = NULL;
ui_wnd_params_t params;
ui_menu_t *menu = NULL;
gfx_rect_t prect;
gfx_coord2_t pos;
errno_t rc;
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_menu_create(window, &menu);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(menu);
prect.p0.x = 0;
prect.p0.y = 0;
prect.p1.x = 0;
prect.p1.y = 0;
rc = ui_menu_open(menu, &prect, 0);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
pos.x = 0;
pos.y = 0;
rc = ui_menu_paint_bg_gfx(menu, &pos);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
ui_window_destroy(window);
ui_destroy(ui);
}
PCUT_TEST(paint_bg_text)
{
ui_t *ui = NULL;
ui_window_t *window = NULL;
ui_wnd_params_t params;
ui_menu_t *menu = NULL;
gfx_rect_t prect;
gfx_coord2_t pos;
errno_t rc;
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_menu_create(window, &menu);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(menu);
prect.p0.x = 0;
prect.p0.y = 0;
prect.p1.x = 0;
prect.p1.y = 0;
rc = ui_menu_open(menu, &prect, 0);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
pos.x = 0;
pos.y = 0;
rc = ui_menu_paint_bg_text(menu, &pos);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
ui_window_destroy(window);
ui_destroy(ui);
}
PCUT_TEST(paint)
{
ui_t *ui = NULL;
ui_window_t *window = NULL;
ui_wnd_params_t params;
ui_menu_t *menu = NULL;
gfx_rect_t prect;
gfx_coord2_t pos;
errno_t rc;
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_menu_create(window, &menu);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(menu);
prect.p0.x = 0;
prect.p0.y = 0;
prect.p1.x = 0;
prect.p1.y = 0;
rc = ui_menu_open(menu, &prect, 0);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
pos.x = 0;
pos.y = 0;
rc = ui_menu_paint(menu, &pos);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
ui_window_destroy(window);
ui_destroy(ui);
}
PCUT_TEST(pos_event_inside)
{
ui_t *ui = NULL;
ui_window_t *window = NULL;
ui_wnd_params_t params;
ui_menu_t *menu = NULL;
ui_evclaim_t claimed;
gfx_coord2_t pos;
pos_event_t event;
errno_t rc;
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_menu_create(window, &menu);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(menu);
pos.x = 0;
pos.y = 0;
event.type = POS_PRESS;
event.hpos = 0;
event.vpos = 0;
claimed = ui_menu_pos_event(menu, &pos, &event);
PCUT_ASSERT_EQUALS(ui_claimed, claimed);
ui_window_destroy(window);
ui_destroy(ui);
}
PCUT_TEST(up_empty)
{
ui_t *ui = NULL;
ui_window_t *window = NULL;
ui_wnd_params_t params;
ui_menu_t *menu = NULL;
gfx_rect_t prect;
errno_t rc;
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_menu_create(window, &menu);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(menu);
prect.p0.x = 0;
prect.p0.y = 0;
prect.p1.x = 0;
prect.p1.y = 0;
rc = ui_menu_open(menu, &prect, 0);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
ui_menu_up(menu);
ui_window_destroy(window);
ui_destroy(ui);
}
PCUT_TEST(up)
{
ui_t *ui = NULL;
ui_window_t *window = NULL;
ui_wnd_params_t params;
ui_menu_t *menu = NULL;
ui_menu_entry_t *mentry1 = NULL;
ui_menu_entry_t *mentry2 = NULL;
ui_menu_entry_t *mentry3 = NULL;
gfx_rect_t prect;
errno_t rc;
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_menu_create(window, &menu);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(menu);
rc = ui_menu_entry_create(menu, "Foo", "F1", &mentry1);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(mentry1);
rc = ui_menu_entry_sep_create(menu, &mentry2);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(mentry2);
rc = ui_menu_entry_create(menu, "Bar", "F2", &mentry3);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(mentry3);
prect.p0.x = 0;
prect.p0.y = 0;
prect.p1.x = 0;
prect.p1.y = 0;
rc = ui_menu_open(menu, &prect, 0);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_EQUALS(mentry1, menu->selected);
ui_menu_up(menu);
PCUT_ASSERT_EQUALS(mentry3, menu->selected);
ui_menu_up(menu);
PCUT_ASSERT_EQUALS(mentry1, menu->selected);
ui_window_destroy(window);
ui_destroy(ui);
}
PCUT_TEST(down_empty)
{
ui_t *ui = NULL;
ui_window_t *window = NULL;
ui_wnd_params_t params;
ui_menu_t *menu = NULL;
gfx_rect_t prect;
errno_t rc;
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_menu_create(window, &menu);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(menu);
prect.p0.x = 0;
prect.p0.y = 0;
prect.p1.x = 0;
prect.p1.y = 0;
rc = ui_menu_open(menu, &prect, 0);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
ui_menu_down(menu);
ui_window_destroy(window);
ui_destroy(ui);
}
PCUT_TEST(down)
{
ui_t *ui = NULL;
ui_window_t *window = NULL;
ui_wnd_params_t params;
ui_menu_t *menu = NULL;
ui_menu_entry_t *mentry1 = NULL;
ui_menu_entry_t *mentry2 = NULL;
ui_menu_entry_t *mentry3 = NULL;
gfx_rect_t prect;
errno_t rc;
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_menu_create(window, &menu);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(menu);
rc = ui_menu_entry_create(menu, "Foo", "F1", &mentry1);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(mentry1);
rc = ui_menu_entry_sep_create(menu, &mentry2);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(mentry2);
rc = ui_menu_entry_create(menu, "Bar", "F2", &mentry3);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(mentry3);
prect.p0.x = 0;
prect.p0.y = 0;
prect.p1.x = 0;
prect.p1.y = 0;
rc = ui_menu_open(menu, &prect, 0);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_EQUALS(mentry1, menu->selected);
ui_menu_down(menu);
PCUT_ASSERT_EQUALS(mentry3, menu->selected);
ui_menu_up(menu);
PCUT_ASSERT_EQUALS(mentry1, menu->selected);
ui_window_destroy(window);
ui_destroy(ui);
}
PCUT_TEST(send_unhandled)
{
ui_menu_t *menu = NULL;
errno_t rc;
sysarg_t idev_id;
char32_t c;
rc = ui_menu_create(NULL, &menu);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(menu);
c = 'A';
idev_id = 42;
ui_menu_left(menu, idev_id);
ui_menu_right(menu, idev_id);
ui_menu_close_req(menu);
ui_menu_press_accel(menu, c, idev_id);
ui_menu_set_cb(menu, &dummy_cb, NULL);
ui_menu_left(menu, idev_id);
ui_menu_right(menu, idev_id);
ui_menu_close_req(menu);
ui_menu_press_accel(menu, c, idev_id);
ui_menu_destroy(menu);
}
PCUT_TEST(left)
{
ui_menu_t *menu = NULL;
errno_t rc;
test_resp_t resp;
sysarg_t idev_id;
rc = ui_menu_create(NULL, &menu);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(menu);
ui_menu_set_cb(menu, &testmenu_cb, (void *)&resp);
memset(&resp, 0, sizeof(resp));
PCUT_ASSERT_FALSE(resp.left_called);
idev_id = 42;
ui_menu_left(menu, idev_id);
PCUT_ASSERT_TRUE(resp.left_called);
PCUT_ASSERT_EQUALS(menu, resp.menu);
PCUT_ASSERT_INT_EQUALS(idev_id, resp.idev_id);
ui_menu_destroy(menu);
}
PCUT_TEST(right)
{
ui_menu_t *menu = NULL;
errno_t rc;
test_resp_t resp;
sysarg_t idev_id;
rc = ui_menu_create(NULL, &menu);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(menu);
ui_menu_set_cb(menu, &testmenu_cb, (void *)&resp);
memset(&resp, 0, sizeof(resp));
PCUT_ASSERT_FALSE(resp.right_called);
idev_id = 42;
ui_menu_right(menu, idev_id);
PCUT_ASSERT_TRUE(resp.right_called);
PCUT_ASSERT_EQUALS(menu, resp.menu);
PCUT_ASSERT_INT_EQUALS(idev_id, resp.idev_id);
ui_menu_destroy(menu);
}
PCUT_TEST(close_req)
{
ui_menu_t *menu = NULL;
errno_t rc;
test_resp_t resp;
rc = ui_menu_create(NULL, &menu);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(menu);
ui_menu_set_cb(menu, &testmenu_cb, (void *)&resp);
memset(&resp, 0, sizeof(resp));
PCUT_ASSERT_FALSE(resp.close_req_called);
ui_menu_close_req(menu);
PCUT_ASSERT_TRUE(resp.close_req_called);
PCUT_ASSERT_EQUALS(menu, resp.menu);
ui_menu_destroy(menu);
}
PCUT_TEST(press_accel)
{
ui_menu_t *menu = NULL;
errno_t rc;
test_resp_t resp;
char32_t c;
sysarg_t idev_id;
rc = ui_menu_create(NULL, &menu);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(menu);
ui_menu_set_cb(menu, &testmenu_cb, (void *)&resp);
memset(&resp, 0, sizeof(resp));
PCUT_ASSERT_FALSE(resp.press_accel_called);
c = 'A';
idev_id = 42;
ui_menu_press_accel(menu, c, idev_id);
PCUT_ASSERT_TRUE(resp.press_accel_called);
PCUT_ASSERT_EQUALS(menu, resp.menu);
PCUT_ASSERT_EQUALS(c, resp.c);
PCUT_ASSERT_INT_EQUALS(idev_id, resp.idev_id);
ui_menu_destroy(menu);
}
static void testmenu_left(ui_menu_t *menu, void *arg, sysarg_t idev_id)
{
test_resp_t *resp = (test_resp_t *)arg;
resp->left_called = true;
resp->menu = menu;
resp->idev_id = idev_id;
}
static void testmenu_right(ui_menu_t *menu, void *arg, sysarg_t idev_id)
{
test_resp_t *resp = (test_resp_t *)arg;
resp->right_called = true;
resp->menu = menu;
resp->idev_id = idev_id;
}
static void testmenu_close_req(ui_menu_t *menu, void *arg)
{
test_resp_t *resp = (test_resp_t *)arg;
resp->close_req_called = true;
resp->menu = menu;
}
static void testmenu_press_accel(ui_menu_t *menu, void *arg,
char32_t c, sysarg_t kbd_id)
{
test_resp_t *resp = (test_resp_t *)arg;
resp->press_accel_called = true;
resp->menu = menu;
resp->c = c;
resp->idev_id = kbd_id;
}
PCUT_EXPORT(menu);
HelenOS homepage, sources at GitHub