awtk/tests/shortcut_test.cc

303 lines
6.4 KiB
C++
Raw Normal View History

2019-05-27 18:08:29 +08:00
#include "base/keys.h"
#include "base/shortcut.h"
#include "gtest/gtest.h"
TEST(ShortCut, ctrl) {
shortcut_t s1;
shortcut_t s2;
shortcut_init(&s1, TK_KEY_a);
s1.ctrl = TRUE;
s1.lctrl = TRUE;
s1.rctrl = TRUE;
2021-04-11 10:54:42 +08:00
shortcut_init_with_str(&s2, "ctrl_a");
2019-05-27 18:08:29 +08:00
ASSERT_EQ(shortcut_equal(&s1, &s2), TRUE);
s1.key = TK_KEY_HOME;
2021-04-11 10:54:42 +08:00
shortcut_init_with_str(&s2, "ctrl_home");
2019-05-27 18:08:29 +08:00
ASSERT_EQ(shortcut_equal(&s1, &s2), TRUE);
}
TEST(ShortCut, lctrl) {
shortcut_t s1;
shortcut_t s2;
shortcut_init(&s1, TK_KEY_a);
s1.lctrl = TRUE;
2021-04-11 10:54:42 +08:00
shortcut_init_with_str(&s2, "lctrl_a");
2019-05-27 18:08:29 +08:00
ASSERT_EQ(shortcut_equal(&s1, &s2), TRUE);
s1.key = TK_KEY_HOME;
2021-04-11 10:54:42 +08:00
shortcut_init_with_str(&s2, "lctrl_home");
2019-05-27 18:08:29 +08:00
ASSERT_EQ(shortcut_equal(&s1, &s2), TRUE);
}
TEST(ShortCut, rctrl) {
shortcut_t s1;
shortcut_t s2;
shortcut_init(&s1, TK_KEY_A);
s1.rctrl = TRUE;
2021-04-11 10:54:42 +08:00
shortcut_init_with_str(&s2, "rctrl_A");
2019-05-27 18:08:29 +08:00
ASSERT_EQ(shortcut_equal(&s1, &s2), TRUE);
s1.key = TK_KEY_HOME;
2021-04-11 10:54:42 +08:00
shortcut_init_with_str(&s2, "rctrl_HOME");
2019-05-27 18:08:29 +08:00
ASSERT_EQ(shortcut_equal(&s1, &s2), TRUE);
}
TEST(ShortCut, alt) {
shortcut_t s1;
shortcut_t s2;
shortcut_init(&s1, TK_KEY_a);
s1.alt = TRUE;
s1.lalt = TRUE;
s1.ralt = TRUE;
2021-04-11 10:54:42 +08:00
shortcut_init_with_str(&s2, "alt_a");
2019-05-27 18:08:29 +08:00
ASSERT_EQ(shortcut_equal(&s1, &s2), TRUE);
s1.key = TK_KEY_HOME;
2021-04-11 10:54:42 +08:00
shortcut_init_with_str(&s2, "alt_home");
2019-05-27 18:08:29 +08:00
ASSERT_EQ(shortcut_equal(&s1, &s2), TRUE);
}
TEST(ShortCut, lalt) {
shortcut_t s1;
shortcut_t s2;
shortcut_init(&s1, TK_KEY_a);
s1.lalt = TRUE;
2021-04-11 10:54:42 +08:00
shortcut_init_with_str(&s2, "lalt_a");
2019-05-27 18:08:29 +08:00
ASSERT_EQ(shortcut_equal(&s1, &s2), TRUE);
s1.key = TK_KEY_HOME;
2021-04-11 10:54:42 +08:00
shortcut_init_with_str(&s2, "lalt_home");
2019-05-27 18:08:29 +08:00
ASSERT_EQ(shortcut_equal(&s1, &s2), TRUE);
}
TEST(ShortCut, ralt) {
shortcut_t s1;
shortcut_t s2;
shortcut_init(&s1, TK_KEY_A);
s1.ralt = TRUE;
2021-04-11 10:54:42 +08:00
shortcut_init_with_str(&s2, "ralt_A");
2019-05-27 18:08:29 +08:00
ASSERT_EQ(shortcut_equal(&s1, &s2), TRUE);
s1.key = TK_KEY_HOME;
2021-04-11 10:54:42 +08:00
shortcut_init_with_str(&s2, "ralt_HOME");
2019-05-27 18:08:29 +08:00
ASSERT_EQ(shortcut_equal(&s1, &s2), TRUE);
}
TEST(ShortCut, shift) {
shortcut_t s1;
shortcut_t s2;
shortcut_init(&s1, TK_KEY_a);
s1.shift = TRUE;
s1.lshift = TRUE;
s1.rshift = TRUE;
2021-04-11 10:54:42 +08:00
shortcut_init_with_str(&s2, "shift_a");
2019-05-27 18:08:29 +08:00
ASSERT_EQ(shortcut_equal(&s1, &s2), TRUE);
s1.key = TK_KEY_HOME;
2021-04-11 10:54:42 +08:00
shortcut_init_with_str(&s2, "shift_home");
2019-05-27 18:08:29 +08:00
ASSERT_EQ(shortcut_equal(&s1, &s2), TRUE);
}
TEST(ShortCut, lshift) {
shortcut_t s1;
shortcut_t s2;
shortcut_init(&s1, TK_KEY_a);
s1.lshift = TRUE;
2021-04-11 10:54:42 +08:00
shortcut_init_with_str(&s2, "lshift_a");
2019-05-27 18:08:29 +08:00
ASSERT_EQ(shortcut_equal(&s1, &s2), TRUE);
s1.key = TK_KEY_HOME;
2021-04-11 10:54:42 +08:00
shortcut_init_with_str(&s2, "lshift_home");
2019-05-27 18:08:29 +08:00
ASSERT_EQ(shortcut_equal(&s1, &s2), TRUE);
}
TEST(ShortCut, rshift) {
shortcut_t s1;
shortcut_t s2;
shortcut_init(&s1, TK_KEY_A);
s1.rshift = TRUE;
2021-04-11 10:54:42 +08:00
shortcut_init_with_str(&s2, "rshift_A");
2019-05-27 18:08:29 +08:00
ASSERT_EQ(shortcut_equal(&s1, &s2), TRUE);
s1.key = TK_KEY_HOME;
2021-04-11 10:54:42 +08:00
shortcut_init_with_str(&s2, "rshift_HOME");
2019-05-27 18:08:29 +08:00
ASSERT_EQ(shortcut_equal(&s1, &s2), TRUE);
}
TEST(ShortCut, cmd) {
shortcut_t s1;
shortcut_t s2;
shortcut_init(&s1, TK_KEY_a);
s1.cmd = TRUE;
2021-04-11 10:54:42 +08:00
shortcut_init_with_str(&s2, "cmd_a");
2019-05-27 18:08:29 +08:00
ASSERT_EQ(shortcut_equal(&s1, &s2), TRUE);
s1.key = TK_KEY_HOME;
2021-04-11 10:54:42 +08:00
shortcut_init_with_str(&s2, "cmd_home");
2019-05-27 18:08:29 +08:00
ASSERT_EQ(shortcut_equal(&s1, &s2), TRUE);
}
TEST(ShortCut, menu) {
shortcut_t s1;
shortcut_t s2;
shortcut_init(&s1, TK_KEY_a);
s1.menu = TRUE;
2021-04-11 10:54:42 +08:00
shortcut_init_with_str(&s2, "menu_a");
2019-05-27 18:08:29 +08:00
ASSERT_EQ(shortcut_equal(&s1, &s2), TRUE);
s1.key = TK_KEY_HOME;
2021-04-11 10:54:42 +08:00
shortcut_init_with_str(&s2, "menu_home");
2019-05-27 18:08:29 +08:00
ASSERT_EQ(shortcut_equal(&s1, &s2), TRUE);
}
TEST(ShortCut, lshift_lctrl) {
shortcut_t s1;
shortcut_t s2;
shortcut_init(&s1, TK_KEY_a);
s1.lctrl = TRUE;
s1.lshift = TRUE;
2021-04-11 10:54:42 +08:00
shortcut_init_with_str(&s2, "lshift_lctrl_a");
2019-05-27 18:08:29 +08:00
ASSERT_EQ(shortcut_equal(&s1, &s2), TRUE);
s1.key = TK_KEY_HOME;
2021-04-11 10:54:42 +08:00
shortcut_init_with_str(&s2, "lshift_lctrl_home");
2019-05-27 18:08:29 +08:00
ASSERT_EQ(shortcut_equal(&s1, &s2), TRUE);
}
2019-05-28 14:26:01 +08:00
TEST(ShortCut, lctrl_match) {
shortcut_t event;
shortcut_t filter;
shortcut_init(&event, TK_KEY_a);
2019-08-07 11:51:40 +08:00
event.ctrl = TRUE;
2019-05-28 14:26:01 +08:00
event.lctrl = TRUE;
2021-04-11 10:54:42 +08:00
shortcut_init_with_str(&filter, "ctrl_a");
2019-05-28 14:26:01 +08:00
ASSERT_EQ(shortcut_match(&filter, &event), TRUE);
2021-04-11 10:54:42 +08:00
shortcut_init_with_str(&filter, "lctrl_a");
2019-05-28 14:26:01 +08:00
ASSERT_EQ(shortcut_match(&filter, &event), TRUE);
}
TEST(ShortCut, rctrl_match) {
shortcut_t event;
shortcut_t filter;
shortcut_init(&event, TK_KEY_a);
2019-08-07 11:51:40 +08:00
event.ctrl = TRUE;
2019-05-28 14:26:01 +08:00
event.rctrl = TRUE;
2021-04-11 10:54:42 +08:00
shortcut_init_with_str(&filter, "ctrl_a");
2019-05-28 14:26:01 +08:00
ASSERT_EQ(shortcut_match(&filter, &event), TRUE);
2021-04-11 10:54:42 +08:00
shortcut_init_with_str(&filter, "rctrl_a");
2019-05-28 14:26:01 +08:00
ASSERT_EQ(shortcut_match(&filter, &event), TRUE);
}
TEST(ShortCut, lalt_match) {
shortcut_t event;
shortcut_t filter;
shortcut_init(&event, TK_KEY_a);
2019-08-07 11:51:40 +08:00
event.alt = TRUE;
2019-05-28 14:26:01 +08:00
event.lalt = TRUE;
2021-04-11 10:54:42 +08:00
shortcut_init_with_str(&filter, "alt_a");
2019-05-28 14:26:01 +08:00
ASSERT_EQ(shortcut_match(&filter, &event), TRUE);
2021-04-11 10:54:42 +08:00
shortcut_init_with_str(&filter, "lalt_a");
2019-05-28 14:26:01 +08:00
ASSERT_EQ(shortcut_match(&filter, &event), TRUE);
}
TEST(ShortCut, ralt_match) {
shortcut_t event;
shortcut_t filter;
shortcut_init(&event, TK_KEY_a);
2019-08-07 11:51:40 +08:00
event.alt = TRUE;
2019-05-28 14:26:01 +08:00
event.ralt = TRUE;
2021-04-11 10:54:42 +08:00
shortcut_init_with_str(&filter, "alt_a");
2019-05-28 14:26:01 +08:00
ASSERT_EQ(shortcut_match(&filter, &event), TRUE);
2021-04-11 10:54:42 +08:00
shortcut_init_with_str(&filter, "ralt_a");
2019-05-28 14:26:01 +08:00
ASSERT_EQ(shortcut_match(&filter, &event), TRUE);
}
TEST(ShortCut, lshift_match) {
shortcut_t event;
shortcut_t filter;
shortcut_init(&event, TK_KEY_a);
2019-08-07 11:51:40 +08:00
event.shift = TRUE;
2019-05-28 14:26:01 +08:00
event.lshift = TRUE;
2021-04-11 10:54:42 +08:00
shortcut_init_with_str(&filter, "shift_a");
2019-05-28 14:26:01 +08:00
ASSERT_EQ(shortcut_match(&filter, &event), TRUE);
2021-04-11 10:54:42 +08:00
shortcut_init_with_str(&filter, "lshift_a");
2019-05-28 14:26:01 +08:00
ASSERT_EQ(shortcut_match(&filter, &event), TRUE);
}
TEST(ShortCut, rshift_match) {
shortcut_t event;
shortcut_t filter;
shortcut_init(&event, TK_KEY_a);
2019-08-07 11:51:40 +08:00
event.shift = TRUE;
2019-05-28 14:26:01 +08:00
event.rshift = TRUE;
2021-04-11 10:54:42 +08:00
shortcut_init_with_str(&filter, "shift_a");
2019-05-28 14:26:01 +08:00
ASSERT_EQ(shortcut_match(&filter, &event), TRUE);
2021-04-11 10:54:42 +08:00
shortcut_init_with_str(&filter, "rshift_a");
2019-05-28 14:26:01 +08:00
ASSERT_EQ(shortcut_match(&filter, &event), TRUE);
}
TEST(ShortCut, cmd_match) {
shortcut_t event;
shortcut_t filter;
shortcut_init(&event, TK_KEY_a);
event.cmd = TRUE;
2021-04-11 10:54:42 +08:00
shortcut_init_with_str(&filter, "cmd_a");
2019-05-28 14:26:01 +08:00
ASSERT_EQ(shortcut_match(&filter, &event), TRUE);
}
TEST(ShortCut, menu_match) {
shortcut_t event;
shortcut_t filter;
shortcut_init(&event, TK_KEY_a);
event.menu = TRUE;
2021-04-11 10:54:42 +08:00
shortcut_init_with_str(&filter, "menu_a");
2019-05-28 14:26:01 +08:00
ASSERT_EQ(shortcut_match(&filter, &event), TRUE);
}