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
- test_dialog_bok
- test_dialog_bcancel
- test_dialog_close
#include <pcut/pcut.h>
#include <stdbool.h>
#include <ui/list.h>
#include <ui/pbutton.h>
#include <ui/ui.h>
#include <ui/selectdialog.h>
#include "../private/list.h"
#include "../private/selectdialog.h"
#include "../private/window.h"
PCUT_INIT;
PCUT_TEST_SUITE(select_dialog);
static void test_dialog_bok(ui_select_dialog_t *, void *, void *);
static void test_dialog_bcancel(ui_select_dialog_t *, void *);
static void test_dialog_close(ui_select_dialog_t *, void *);
static ui_select_dialog_cb_t test_select_dialog_cb = {
.bok = test_dialog_bok,
.bcancel = test_dialog_bcancel,
.close = test_dialog_close
};
static ui_select_dialog_cb_t dummy_select_dialog_cb = {
};
typedef struct {
bool bok;
const char *fname;
bool bcancel;
bool close;
} test_cb_resp_t;
PCUT_TEST(create_destroy)
{
errno_t rc;
ui_t *ui = NULL;
ui_select_dialog_params_t params;
ui_select_dialog_t *dialog = NULL;
rc = ui_create_disp(NULL, &ui);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
ui_select_dialog_params_init(¶ms);
params.caption = "Select one";
params.prompt = "Please select";
rc = ui_select_dialog_create(ui, ¶ms, &dialog);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(dialog);
ui_select_dialog_destroy(dialog);
ui_destroy(ui);
}
PCUT_TEST(destroy_null)
{
ui_select_dialog_destroy(NULL);
}
PCUT_TEST(bok_cb)
{
errno_t rc;
ui_t *ui = NULL;
ui_select_dialog_params_t params;
ui_select_dialog_t *dialog = NULL;
test_cb_resp_t resp;
rc = ui_create_disp(NULL, &ui);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
ui_select_dialog_params_init(¶ms);
params.caption = "Select one";
params.prompt = "Please select";
rc = ui_select_dialog_create(ui, ¶ms, &dialog);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(dialog);
ui_pbutton_clicked(dialog->bok);
ui_select_dialog_set_cb(dialog, &dummy_select_dialog_cb, NULL);
ui_pbutton_clicked(dialog->bok);
resp.bok = false;
ui_select_dialog_set_cb(dialog, &test_select_dialog_cb, &resp);
ui_pbutton_clicked(dialog->bok);
PCUT_ASSERT_TRUE(resp.bok);
ui_select_dialog_destroy(dialog);
ui_destroy(ui);
}
PCUT_TEST(bcancel_cb)
{
errno_t rc;
ui_t *ui = NULL;
ui_select_dialog_params_t params;
ui_select_dialog_t *dialog = NULL;
test_cb_resp_t resp;
rc = ui_create_disp(NULL, &ui);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
ui_select_dialog_params_init(¶ms);
params.caption = "Select one";
params.prompt = "Please select";
rc = ui_select_dialog_create(ui, ¶ms, &dialog);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(dialog);
ui_pbutton_clicked(dialog->bcancel);
ui_select_dialog_set_cb(dialog, &dummy_select_dialog_cb, NULL);
ui_pbutton_clicked(dialog->bcancel);
resp.bcancel = false;
ui_select_dialog_set_cb(dialog, &test_select_dialog_cb, &resp);
ui_pbutton_clicked(dialog->bcancel);
PCUT_ASSERT_TRUE(resp.bcancel);
ui_select_dialog_destroy(dialog);
ui_destroy(ui);
}
PCUT_TEST(lselect_cb)
{
errno_t rc;
ui_t *ui = NULL;
ui_list_entry_t *entry;
ui_select_dialog_params_t params;
ui_select_dialog_t *dialog = NULL;
ui_list_entry_attr_t attr;
test_cb_resp_t resp;
rc = ui_create_disp(NULL, &ui);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
ui_select_dialog_params_init(¶ms);
params.caption = "Select one";
params.prompt = "Please select";
rc = ui_select_dialog_create(ui, ¶ms, &dialog);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(dialog);
ui_list_entry_attr_init(&attr);
attr.caption = "Entry";
rc = ui_select_dialog_append(dialog, &attr);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
entry = ui_list_first(dialog->list);
ui_list_selected(entry);
ui_select_dialog_set_cb(dialog, &dummy_select_dialog_cb, NULL);
ui_list_selected(entry);
resp.bok = false;
ui_select_dialog_set_cb(dialog, &test_select_dialog_cb, &resp);
ui_list_selected(entry);
PCUT_ASSERT_TRUE(resp.bok);
ui_select_dialog_destroy(dialog);
ui_destroy(ui);
}
PCUT_TEST(close_cb)
{
errno_t rc;
ui_t *ui = NULL;
ui_select_dialog_params_t params;
ui_select_dialog_t *dialog = NULL;
test_cb_resp_t resp;
rc = ui_create_disp(NULL, &ui);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
ui_select_dialog_params_init(¶ms);
params.caption = "Select one";
params.prompt = "Please select";
rc = ui_select_dialog_create(ui, ¶ms, &dialog);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(dialog);
ui_window_send_close(dialog->window);
ui_select_dialog_set_cb(dialog, &dummy_select_dialog_cb, NULL);
ui_window_send_close(dialog->window);
resp.close = false;
ui_select_dialog_set_cb(dialog, &test_select_dialog_cb, &resp);
ui_window_send_close(dialog->window);
PCUT_ASSERT_TRUE(resp.close);
ui_select_dialog_destroy(dialog);
ui_destroy(ui);
}
PCUT_TEST(append)
{
errno_t rc;
ui_t *ui = NULL;
ui_select_dialog_params_t params;
ui_select_dialog_t *dialog = NULL;
ui_list_entry_attr_t attr;
rc = ui_create_disp(NULL, &ui);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
ui_select_dialog_params_init(¶ms);
params.caption = "Select one";
params.prompt = "Please select";
rc = ui_select_dialog_create(ui, ¶ms, &dialog);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(dialog);
PCUT_ASSERT_INT_EQUALS(0, dialog->list->entries_cnt);
ui_list_entry_attr_init(&attr);
attr.caption = "Entry";
rc = ui_select_dialog_append(dialog, &attr);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_INT_EQUALS(1, dialog->list->entries_cnt);
ui_select_dialog_destroy(dialog);
ui_destroy(ui);
}
PCUT_TEST(paint)
{
errno_t rc;
ui_t *ui = NULL;
ui_select_dialog_params_t params;
ui_select_dialog_t *dialog = NULL;
rc = ui_create_disp(NULL, &ui);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
ui_select_dialog_params_init(¶ms);
params.caption = "Select one";
params.prompt = "Please select";
rc = ui_select_dialog_create(ui, ¶ms, &dialog);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(dialog);
rc = ui_select_dialog_paint(dialog);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
ui_select_dialog_destroy(dialog);
ui_destroy(ui);
}
PCUT_TEST(list)
{
errno_t rc;
ui_t *ui = NULL;
ui_select_dialog_params_t params;
ui_select_dialog_t *dialog = NULL;
ui_list_t *list;
ui_list_entry_attr_t attr;
rc = ui_create_disp(NULL, &ui);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
ui_select_dialog_params_init(¶ms);
params.caption = "Select one";
params.prompt = "Please select";
rc = ui_select_dialog_create(ui, ¶ms, &dialog);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(dialog);
list = ui_select_dialog_list(dialog);
PCUT_ASSERT_NOT_NULL(list);
PCUT_ASSERT_INT_EQUALS(0, ui_list_entries_cnt(list));
ui_list_entry_attr_init(&attr);
attr.caption = "Entry";
rc = ui_select_dialog_append(dialog, &attr);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_INT_EQUALS(1, ui_list_entries_cnt(list));
ui_select_dialog_destroy(dialog);
ui_destroy(ui);
}
static void test_dialog_bok(ui_select_dialog_t *dialog, void *arg,
void *earg)
{
test_cb_resp_t *resp = (test_cb_resp_t *) arg;
resp->bok = true;
}
static void test_dialog_bcancel(ui_select_dialog_t *dialog, void *arg)
{
test_cb_resp_t *resp = (test_cb_resp_t *) arg;
resp->bcancel = true;
}
static void test_dialog_close(ui_select_dialog_t *dialog, void *arg)
{
test_cb_resp_t *resp = (test_cb_resp_t *) arg;
resp->close = true;
}
PCUT_EXPORT(select_dialog);
HelenOS homepage, sources at GitHub