HelenOS sources
This source file includes following definitions.
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
#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/menudd.h>
#include <ui/menubar.h>
#include <ui/ui.h>
#include <ui/window.h>
#include "../private/menu.h"
#include "../private/menubar.h"
PCUT_INIT;
PCUT_TEST_SUITE(menudd);
PCUT_TEST(create_destroy)
{
ui_t *ui = NULL;
ui_window_t *window = NULL;
ui_wnd_params_t params;
ui_menu_bar_t *mbar = NULL;
ui_menu_dd_t *mdd = NULL;
ui_menu_t *menu = NULL;
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_bar_create(ui, window, &mbar);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = ui_menu_dd_create(mbar, "Test", &mdd, &menu);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(mdd);
PCUT_ASSERT_NOT_NULL(menu);
ui_menu_dd_destroy(mdd);
ui_menu_bar_destroy(mbar);
ui_window_destroy(window);
ui_destroy(ui);
}
PCUT_TEST(destroy_null)
{
ui_menu_dd_destroy(NULL);
}
PCUT_TEST(first_next)
{
ui_t *ui = NULL;
ui_window_t *window = NULL;
ui_wnd_params_t params;
ui_menu_bar_t *mbar = NULL;
ui_menu_dd_t *mdd1 = NULL;
ui_menu_dd_t *mdd2 = NULL;
ui_menu_dd_t *m;
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_bar_create(ui, window, &mbar);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(mbar);
rc = ui_menu_dd_create(mbar, "Test 1", &mdd1, NULL);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(mdd1);
rc = ui_menu_dd_create(mbar, "Test 1", &mdd2, NULL);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(mdd2);
m = ui_menu_dd_first(mbar);
PCUT_ASSERT_EQUALS(mdd1, m);
m = ui_menu_dd_next(m);
PCUT_ASSERT_EQUALS(mdd2, m);
m = ui_menu_dd_next(m);
PCUT_ASSERT_NULL(m);
ui_menu_bar_destroy(mbar);
ui_window_destroy(window);
ui_destroy(ui);
}
PCUT_TEST(last_prev)
{
ui_t *ui = NULL;
ui_window_t *window = NULL;
ui_wnd_params_t params;
ui_menu_bar_t *mbar = NULL;
ui_menu_dd_t *mdd1 = NULL;
ui_menu_dd_t *mdd2 = NULL;
ui_menu_dd_t *m;
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_bar_create(ui, window, &mbar);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(mbar);
rc = ui_menu_dd_create(mbar, "Test 1", &mdd1, NULL);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(mdd1);
rc = ui_menu_dd_create(mbar, "Test 1", &mdd2, NULL);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(mdd2);
m = ui_menu_dd_last(mbar);
PCUT_ASSERT_EQUALS(mdd2, m);
m = ui_menu_dd_prev(m);
PCUT_ASSERT_EQUALS(mdd1, m);
m = ui_menu_dd_prev(m);
PCUT_ASSERT_NULL(m);
ui_menu_bar_destroy(mbar);
ui_window_destroy(window);
ui_destroy(ui);
}
PCUT_TEST(caption)
{
ui_t *ui = NULL;
ui_window_t *window = NULL;
ui_wnd_params_t params;
ui_menu_bar_t *mbar = NULL;
ui_menu_dd_t *mdd = NULL;
const char *caption;
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_bar_create(ui, window, &mbar);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(mbar);
rc = ui_menu_dd_create(mbar, "Test", &mdd, NULL);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(mdd);
caption = ui_menu_dd_caption(mdd);
PCUT_ASSERT_NOT_NULL(caption);
PCUT_ASSERT_INT_EQUALS(0, str_cmp(caption, "Test"));
ui_menu_bar_destroy(mbar);
ui_window_destroy(window);
ui_destroy(ui);
}
PCUT_TEST(get_accel)
{
ui_t *ui = NULL;
ui_window_t *window = NULL;
ui_wnd_params_t params;
ui_menu_bar_t *mbar = NULL;
ui_menu_dd_t *mdd = NULL;
char32_t accel;
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_bar_create(ui, window, &mbar);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(mbar);
rc = ui_menu_dd_create(mbar, "~T~est", &mdd, NULL);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(mdd);
accel = ui_menu_dd_get_accel(mdd);
printf("accel='%c' (%d)\n", (char)accel, (int)accel);
PCUT_ASSERT_EQUALS((char32_t)'t', accel);
ui_menu_bar_destroy(mbar);
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_bar_t *mbar = NULL;
ui_menu_dd_t *mdd = 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_bar_create(ui, window, &mbar);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(mbar);
rc = ui_menu_dd_create(mbar, "Test", &mdd, NULL);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(mdd);
prect.p0.x = 0;
prect.p0.y = 0;
prect.p1.x = 0;
prect.p1.y = 0;
rc = ui_menu_dd_open(mdd, &prect, 0);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
ui_menu_dd_close(mdd);
ui_menu_bar_destroy(mbar);
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_bar_t *mbar = NULL;
ui_menu_dd_t *mdd = 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_bar_create(ui, window, &mbar);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(mbar);
rc = ui_menu_dd_create(mbar, "Test", &mdd, NULL);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(mdd);
prect.p0.x = 0;
prect.p0.y = 0;
prect.p1.x = 0;
prect.p1.y = 0;
open = ui_menu_dd_is_open(mdd);
PCUT_ASSERT_FALSE(open);
rc = ui_menu_dd_open(mdd, &prect, 0);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
open = ui_menu_dd_is_open(mdd);
PCUT_ASSERT_TRUE(open);
ui_menu_dd_close(mdd);
open = ui_menu_dd_is_open(mdd);
PCUT_ASSERT_FALSE(open);
ui_menu_bar_destroy(mbar);
ui_window_destroy(window);
ui_destroy(ui);
}
PCUT_EXPORT(menudd);
HelenOS homepage, sources at GitHub