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
- test_cb
#include <errno.h>
#include <pcut/pcut.h>
#include <tbarcfg/tbarcfg.h>
#include <stdbool.h>
#include <stdio.h>
PCUT_INIT;
PCUT_TEST_SUITE(tbarcfg);
typedef struct {
bool notified;
} tbarcfg_test_resp_t;
static void test_cb(void *);
PCUT_TEST(create_open_close)
{
errno_t rc;
tbarcfg_t *tbcfg;
char fname[L_tmpnam], *p;
p = tmpnam(fname);
PCUT_ASSERT_NOT_NULL(p);
rc = tbarcfg_create(fname, &tbcfg);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
tbarcfg_sync(tbcfg);
tbarcfg_close(tbcfg);
rc = tbarcfg_open(fname, &tbcfg);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
tbarcfg_close(tbcfg);
remove(fname);
}
PCUT_TEST(first_next)
{
errno_t rc;
tbarcfg_t *tbcfg;
char fname[L_tmpnam], *p;
smenu_entry_t *e1 = NULL, *e2 = NULL;
smenu_entry_t *e;
p = tmpnam(fname);
PCUT_ASSERT_NOT_NULL(p);
rc = tbarcfg_create(fname, &tbcfg);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = smenu_entry_create(tbcfg, "A", "a", false, &e1);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(e1);
rc = smenu_entry_create(tbcfg, "B", "b", false, &e2);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(e2);
rc = smenu_entry_create(tbcfg, "C", "c", false, NULL);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
e = tbarcfg_smenu_first(tbcfg);
PCUT_ASSERT_EQUALS(e1, e);
e = tbarcfg_smenu_next(e);
PCUT_ASSERT_EQUALS(e2, e);
e = tbarcfg_smenu_next(e);
PCUT_ASSERT_NOT_NULL(e);
e = tbarcfg_smenu_next(e);
PCUT_ASSERT_NULL(e);
tbarcfg_close(tbcfg);
remove(fname);
}
PCUT_TEST(last_prev)
{
errno_t rc;
tbarcfg_t *tbcfg;
char fname[L_tmpnam], *p;
smenu_entry_t *e1 = NULL, *e2 = NULL;
smenu_entry_t *e;
p = tmpnam(fname);
PCUT_ASSERT_NOT_NULL(p);
rc = tbarcfg_create(fname, &tbcfg);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = smenu_entry_create(tbcfg, "A", "a", false, &e1);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(e1);
rc = smenu_entry_create(tbcfg, "B", "b", false, &e2);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(e2);
e = tbarcfg_smenu_last(tbcfg);
PCUT_ASSERT_EQUALS(e2, e);
e = tbarcfg_smenu_prev(e);
PCUT_ASSERT_EQUALS(e1, e);
e = tbarcfg_smenu_prev(e);
PCUT_ASSERT_NULL(e);
tbarcfg_close(tbcfg);
remove(fname);
}
PCUT_TEST(separator)
{
errno_t rc;
tbarcfg_t *tbcfg;
char fname[L_tmpnam], *p;
const char *caption;
const char *cmd;
smenu_entry_t *e1 = NULL, *e2 = NULL;
smenu_entry_t *e;
p = tmpnam(fname);
PCUT_ASSERT_NOT_NULL(p);
rc = tbarcfg_create(fname, &tbcfg);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = smenu_entry_create(tbcfg, "A", "a", false, &e1);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(e1);
rc = smenu_entry_sep_create(tbcfg, &e2);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(e2);
PCUT_ASSERT_FALSE(smenu_entry_get_separator(e1));
PCUT_ASSERT_TRUE(smenu_entry_get_separator(e2));
tbarcfg_sync(tbcfg);
tbarcfg_close(tbcfg);
rc = tbarcfg_open(fname, &tbcfg);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
e = tbarcfg_smenu_first(tbcfg);
PCUT_ASSERT_NOT_NULL(e);
PCUT_ASSERT_FALSE(smenu_entry_get_separator(e));
caption = smenu_entry_get_caption(e);
PCUT_ASSERT_STR_EQUALS("A", caption);
cmd = smenu_entry_get_cmd(e);
PCUT_ASSERT_STR_EQUALS("a", cmd);
e = tbarcfg_smenu_next(e);
PCUT_ASSERT_TRUE(smenu_entry_get_separator(e));
tbarcfg_close(tbcfg);
remove(fname);
}
PCUT_TEST(get_caption_cmd_term)
{
errno_t rc;
tbarcfg_t *tbcfg;
char fname[L_tmpnam], *p;
smenu_entry_t *e;
const char *caption;
const char *cmd;
bool terminal;
p = tmpnam(fname);
PCUT_ASSERT_NOT_NULL(p);
rc = tbarcfg_create(fname, &tbcfg);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = smenu_entry_create(tbcfg, "A", "a", false, &e);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
caption = smenu_entry_get_caption(e);
PCUT_ASSERT_STR_EQUALS("A", caption);
cmd = smenu_entry_get_cmd(e);
PCUT_ASSERT_STR_EQUALS("a", cmd);
terminal = smenu_entry_get_terminal(e);
PCUT_ASSERT_FALSE(terminal);
tbarcfg_close(tbcfg);
remove(fname);
}
PCUT_TEST(set_caption_cmd_term)
{
errno_t rc;
tbarcfg_t *tbcfg;
char fname[L_tmpnam], *p;
smenu_entry_t *e;
const char *caption;
const char *cmd;
bool terminal;
p = tmpnam(fname);
PCUT_ASSERT_NOT_NULL(p);
rc = tbarcfg_create(fname, &tbcfg);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = smenu_entry_create(tbcfg, "A", "a", false, &e);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
caption = smenu_entry_get_caption(e);
PCUT_ASSERT_STR_EQUALS("A", caption);
cmd = smenu_entry_get_cmd(e);
PCUT_ASSERT_STR_EQUALS("a", cmd);
terminal = smenu_entry_get_terminal(e);
PCUT_ASSERT_FALSE(terminal);
rc = smenu_entry_set_caption(e, "B");
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = smenu_entry_set_cmd(e, "b");
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
smenu_entry_set_terminal(e, true);
rc = tbarcfg_sync(tbcfg);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
caption = smenu_entry_get_caption(e);
PCUT_ASSERT_STR_EQUALS("B", caption);
cmd = smenu_entry_get_cmd(e);
PCUT_ASSERT_STR_EQUALS("b", cmd);
terminal = smenu_entry_get_terminal(e);
PCUT_ASSERT_TRUE(terminal);
tbarcfg_sync(tbcfg);
tbarcfg_close(tbcfg);
rc = tbarcfg_open(fname, &tbcfg);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
e = tbarcfg_smenu_first(tbcfg);
PCUT_ASSERT_NOT_NULL(e);
caption = smenu_entry_get_caption(e);
PCUT_ASSERT_STR_EQUALS("B", caption);
cmd = smenu_entry_get_cmd(e);
PCUT_ASSERT_STR_EQUALS("b", cmd);
tbarcfg_close(tbcfg);
remove(fname);
}
PCUT_TEST(entry_create)
{
errno_t rc;
tbarcfg_t *tbcfg;
char fname[L_tmpnam], *p;
smenu_entry_t *e;
const char *caption;
const char *cmd;
bool terminal;
p = tmpnam(fname);
PCUT_ASSERT_NOT_NULL(p);
rc = tbarcfg_create(fname, &tbcfg);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = smenu_entry_create(tbcfg, "A", "a", false, &e);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(e);
caption = smenu_entry_get_caption(e);
PCUT_ASSERT_STR_EQUALS("A", caption);
cmd = smenu_entry_get_cmd(e);
PCUT_ASSERT_STR_EQUALS("a", cmd);
terminal = smenu_entry_get_terminal(e);
PCUT_ASSERT_FALSE(terminal);
smenu_entry_destroy(e);
rc = smenu_entry_create(tbcfg, "B", "b", true, &e);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_NOT_NULL(e);
caption = smenu_entry_get_caption(e);
PCUT_ASSERT_STR_EQUALS("B", caption);
cmd = smenu_entry_get_cmd(e);
PCUT_ASSERT_STR_EQUALS("b", cmd);
terminal = smenu_entry_get_terminal(e);
PCUT_ASSERT_TRUE(terminal);
smenu_entry_destroy(e);
tbarcfg_close(tbcfg);
remove(fname);
}
PCUT_TEST(entry_destroy)
{
errno_t rc;
tbarcfg_t *tbcfg;
char fname[L_tmpnam], *p;
smenu_entry_t *e, *f;
p = tmpnam(fname);
PCUT_ASSERT_NOT_NULL(p);
rc = tbarcfg_create(fname, &tbcfg);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = smenu_entry_create(tbcfg, "A", "a", false, &e);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
f = tbarcfg_smenu_first(tbcfg);
PCUT_ASSERT_EQUALS(e, f);
smenu_entry_destroy(e);
f = tbarcfg_smenu_first(tbcfg);
PCUT_ASSERT_NULL(f);
tbarcfg_close(tbcfg);
remove(fname);
}
PCUT_TEST(entry_move_up)
{
errno_t rc;
tbarcfg_t *tbcfg;
char fname[L_tmpnam], *p;
smenu_entry_t *e1, *e2, *e3;
smenu_entry_t *f;
const char *caption;
const char *cmd;
p = tmpnam(fname);
PCUT_ASSERT_NOT_NULL(p);
rc = tbarcfg_create(fname, &tbcfg);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = smenu_entry_create(tbcfg, "A", "a", false, &e1);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = smenu_entry_create(tbcfg, "B", "b", false, &e2);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = smenu_entry_create(tbcfg, "C", "c", false, &e3);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
f = tbarcfg_smenu_first(tbcfg);
PCUT_ASSERT_EQUALS(e1, f);
smenu_entry_move_up(e1);
f = tbarcfg_smenu_first(tbcfg);
PCUT_ASSERT_EQUALS(e1, f);
smenu_entry_move_up(e2);
f = tbarcfg_smenu_first(tbcfg);
PCUT_ASSERT_EQUALS(e2, f);
smenu_entry_move_up(e3);
f = tbarcfg_smenu_first(tbcfg);
PCUT_ASSERT_EQUALS(e2, f);
f = tbarcfg_smenu_next(f);
PCUT_ASSERT_EQUALS(e3, f);
f = tbarcfg_smenu_next(f);
PCUT_ASSERT_EQUALS(e1, f);
tbarcfg_sync(tbcfg);
tbarcfg_close(tbcfg);
rc = tbarcfg_open(fname, &tbcfg);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
f = tbarcfg_smenu_first(tbcfg);
PCUT_ASSERT_NOT_NULL(f);
caption = smenu_entry_get_caption(f);
PCUT_ASSERT_STR_EQUALS("B", caption);
cmd = smenu_entry_get_cmd(f);
PCUT_ASSERT_STR_EQUALS("b", cmd);
f = tbarcfg_smenu_next(f);
PCUT_ASSERT_NOT_NULL(f);
caption = smenu_entry_get_caption(f);
PCUT_ASSERT_STR_EQUALS("C", caption);
cmd = smenu_entry_get_cmd(f);
PCUT_ASSERT_STR_EQUALS("c", cmd);
f = tbarcfg_smenu_next(f);
PCUT_ASSERT_NOT_NULL(f);
caption = smenu_entry_get_caption(f);
PCUT_ASSERT_STR_EQUALS("A", caption);
cmd = smenu_entry_get_cmd(f);
PCUT_ASSERT_STR_EQUALS("a", cmd);
tbarcfg_close(tbcfg);
remove(fname);
}
PCUT_TEST(entry_move_down)
{
errno_t rc;
tbarcfg_t *tbcfg;
char fname[L_tmpnam], *p;
smenu_entry_t *e1, *e2, *e3;
smenu_entry_t *f;
const char *caption;
const char *cmd;
p = tmpnam(fname);
PCUT_ASSERT_NOT_NULL(p);
rc = tbarcfg_create(fname, &tbcfg);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = smenu_entry_create(tbcfg, "A", "a", false, &e1);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = smenu_entry_create(tbcfg, "B", "b", false, &e2);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = smenu_entry_create(tbcfg, "C", "c", false, &e3);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
f = tbarcfg_smenu_last(tbcfg);
PCUT_ASSERT_EQUALS(e3, f);
smenu_entry_move_down(e3);
f = tbarcfg_smenu_last(tbcfg);
PCUT_ASSERT_EQUALS(e3, f);
smenu_entry_move_down(e2);
f = tbarcfg_smenu_last(tbcfg);
PCUT_ASSERT_EQUALS(e2, f);
smenu_entry_move_down(e1);
f = tbarcfg_smenu_last(tbcfg);
PCUT_ASSERT_EQUALS(e2, f);
f = tbarcfg_smenu_prev(f);
PCUT_ASSERT_EQUALS(e1, f);
f = tbarcfg_smenu_prev(f);
PCUT_ASSERT_EQUALS(e3, f);
tbarcfg_sync(tbcfg);
tbarcfg_close(tbcfg);
rc = tbarcfg_open(fname, &tbcfg);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
f = tbarcfg_smenu_first(tbcfg);
PCUT_ASSERT_NOT_NULL(f);
caption = smenu_entry_get_caption(f);
PCUT_ASSERT_STR_EQUALS("C", caption);
cmd = smenu_entry_get_cmd(f);
PCUT_ASSERT_STR_EQUALS("c", cmd);
f = tbarcfg_smenu_next(f);
PCUT_ASSERT_NOT_NULL(f);
caption = smenu_entry_get_caption(f);
PCUT_ASSERT_STR_EQUALS("A", caption);
cmd = smenu_entry_get_cmd(f);
PCUT_ASSERT_STR_EQUALS("a", cmd);
f = tbarcfg_smenu_next(f);
PCUT_ASSERT_NOT_NULL(f);
caption = smenu_entry_get_caption(f);
PCUT_ASSERT_STR_EQUALS("B", caption);
cmd = smenu_entry_get_cmd(f);
PCUT_ASSERT_STR_EQUALS("b", cmd);
tbarcfg_close(tbcfg);
remove(fname);
}
PCUT_TEST(notify)
{
errno_t rc;
tbarcfg_listener_t *lst;
tbarcfg_test_resp_t test_resp;
test_resp.notified = false;
printf("create listener resp=%p\n", (void *)&test_resp);
rc = tbarcfg_listener_create(TBARCFG_NOTIFY_DEFAULT,
test_cb, &test_resp, &lst);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
rc = tbarcfg_notify(TBARCFG_NOTIFY_DEFAULT);
PCUT_ASSERT_ERRNO_VAL(EOK, rc);
PCUT_ASSERT_TRUE(test_resp.notified);
tbarcfg_listener_destroy(lst);
}
static void test_cb(void *arg)
{
tbarcfg_test_resp_t *resp = (tbarcfg_test_resp_t *)arg;
printf("test_cb: executing resp=%p\n", (void *)resp);
resp->notified = true;
}
PCUT_EXPORT(tbarcfg);
HelenOS homepage, sources at GitHub