From 4d91771cac6fcba8278eb154f799fe20beae45ef Mon Sep 17 00:00:00 2001 From: matt335672 <30179339+matt335672@users.noreply.github.com> Date: Thu, 23 May 2024 19:59:36 +0100 Subject: [PATCH] Add basic keymap loading test --- tests/xrdp/Makefile.am | 3 + tests/xrdp/test_xrdp.h | 1 + tests/xrdp/test_xrdp_keymap.c | 103 ++++++++++++++++++++++++++++++++++ tests/xrdp/test_xrdp_main.c | 1 + 4 files changed, 108 insertions(+) create mode 100644 tests/xrdp/test_xrdp_keymap.c diff --git a/tests/xrdp/Makefile.am b/tests/xrdp/Makefile.am index 245e34df..dda40df1 100644 --- a/tests/xrdp/Makefile.am +++ b/tests/xrdp/Makefile.am @@ -1,8 +1,10 @@ AM_CPPFLAGS = \ + -DXRDP_TOP_SRCDIR=\"$(top_srcdir)\" \ -I$(top_builddir) \ -I$(top_srcdir)/xrdp \ -I$(top_srcdir)/libxrdp \ -I$(top_srcdir)/common \ + -I$(top_srcdir)/third_party/tomlc99 \ $(IMLIB2_CFLAGS) LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) \ @@ -27,6 +29,7 @@ test_xrdp_SOURCES = \ test_xrdp.h \ test_xrdp_main.c \ test_xrdp_egfx.c \ + test_xrdp_keymap.c \ test_xrdp_region.c \ test_bitmap_load.c diff --git a/tests/xrdp/test_xrdp.h b/tests/xrdp/test_xrdp.h index 58d33578..ab1a8c94 100644 --- a/tests/xrdp/test_xrdp.h +++ b/tests/xrdp/test_xrdp.h @@ -4,6 +4,7 @@ #include Suite *make_suite_test_bitmap_load(void); +Suite *make_suite_test_keymap_load(void); Suite *make_suite_egfx_base_functions(void); Suite *make_suite_region(void); diff --git a/tests/xrdp/test_xrdp_keymap.c b/tests/xrdp/test_xrdp_keymap.c new file mode 100644 index 00000000..60e1b6a8 --- /dev/null +++ b/tests/xrdp/test_xrdp_keymap.c @@ -0,0 +1,103 @@ +#if defined(HAVE_CONFIG_H) +#include "config_ac.h" +#endif + +#include // For NoSymbol +#include + +#include "test_xrdp.h" + +#include "xrdp.h" + +START_TEST(test_keymap_load__basic_load) +{ + struct xrdp_keymap km; + const struct xrdp_key_info *ki; + + // Set the memory area to non-zero values + memset(&km, 0x7f, sizeof(km)); + + // Japanese qwerty layout (see https://kbdlayout.info/kbdjpn) + // for OADG 109A + // + // The Kanji shift-state is not supported by the file format + km_load_file(XRDP_TOP_SRCDIR "/instfiles/km-00000411.toml", &km); + + ki = &km.keys_noshift[0x59]; // Unmapped scancode + ck_assert_int_eq(ki->sym, NoSymbol); + ck_assert_int_eq(ki->chr, 0); + + /* qwerty */ + ki = &km.keys_noshift[0x10]; + ck_assert_int_eq(ki->sym, XK_q); + ck_assert_int_eq(ki->chr, 'q'); + ki = &km.keys_noshift[0x11]; + ck_assert_int_eq(ki->sym, XK_w); + ck_assert_int_eq(ki->chr, 'w'); + ki = &km.keys_noshift[0x12]; + ck_assert_int_eq(ki->sym, XK_e); + ck_assert_int_eq(ki->chr, 'e'); + ki = &km.keys_noshift[0x13]; + ck_assert_int_eq(ki->sym, XK_r); + ck_assert_int_eq(ki->chr, 'r'); + ki = &km.keys_noshift[0x14]; + ck_assert_int_eq(ki->sym, XK_t); + ck_assert_int_eq(ki->chr, 't'); + ki = &km.keys_noshift[0x15]; + ck_assert_int_eq(ki->sym, XK_y); + ck_assert_int_eq(ki->chr, 'y'); + + /* QWERTY */ + ki = &km.keys_shift[0x10]; + ck_assert_int_eq(ki->sym, XK_Q); + ck_assert_int_eq(ki->chr, 'Q'); + ki = &km.keys_shift[0x11]; + ck_assert_int_eq(ki->sym, XK_W); + ck_assert_int_eq(ki->chr, 'W'); + ki = &km.keys_shift[0x12]; + ck_assert_int_eq(ki->sym, XK_E); + ck_assert_int_eq(ki->chr, 'E'); + ki = &km.keys_shift[0x13]; + ck_assert_int_eq(ki->sym, XK_R); + ck_assert_int_eq(ki->chr, 'R'); + ki = &km.keys_shift[0x14]; + ck_assert_int_eq(ki->sym, XK_T); + ck_assert_int_eq(ki->chr, 'T'); + ki = &km.keys_shift[0x15]; + ck_assert_int_eq(ki->sym, XK_Y); + ck_assert_int_eq(ki->chr, 'Y'); + + /* right-shift and 4 keys to left */ + ki = &km.keys_noshift[0x33]; // OEM Comma + ck_assert_int_eq(ki->sym, XK_comma); + ck_assert_int_eq(ki->chr, ','); + ki = &km.keys_noshift[0x34]; // OEM Period + ck_assert_int_eq(ki->sym, XK_period); + ck_assert_int_eq(ki->chr, '.'); + ki = &km.keys_noshift[0x35]; // OEM 2 + ck_assert_int_eq(ki->sym, XK_slash); + ck_assert_int_eq(ki->chr, '/'); + ki = &km.keys_noshift[0x73]; // ABNT C + ck_assert_int_eq(ki->sym, XK_backslash); + ck_assert_int_eq(ki->chr, '\\'); + ki = &km.keys_noshift[0x36]; // Right shift + ck_assert_int_eq(ki->sym, XK_Shift_R); + ck_assert_int_eq(ki->chr, 0); +} +END_TEST + +/******************************************************************************/ +Suite * +make_suite_test_keymap_load(void) +{ + Suite *s; + TCase *tc_keymap_load; + + s = suite_create("KeymapLoad"); + + tc_keymap_load = tcase_create("xrdp_keymap_load"); + tcase_add_test(tc_keymap_load, test_keymap_load__basic_load); + + suite_add_tcase(s, tc_keymap_load); + return s; +} diff --git a/tests/xrdp/test_xrdp_main.c b/tests/xrdp/test_xrdp_main.c index 017ef102..9236e59d 100644 --- a/tests/xrdp/test_xrdp_main.c +++ b/tests/xrdp/test_xrdp_main.c @@ -55,6 +55,7 @@ int main (void) setvbuf(stdout, NULL, _IONBF, 0); sr = srunner_create (make_suite_test_bitmap_load()); + srunner_add_suite(sr, make_suite_test_keymap_load()); srunner_add_suite(sr, make_suite_egfx_base_functions()); srunner_add_suite(sr, make_suite_region());