From ae1c76ff830d146d41e88d6fba724c0a54bce868 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:45:20 +0200 Subject: Adding upstream version 1:43.6. Signed-off-by: Daniel Baumann --- tests/keyboard/meson.build | 33 +++++++ tests/keyboard/test-keyboard-shortcuts.c | 161 +++++++++++++++++++++++++++++++ tests/keyboard/test-keyboard.py | 46 +++++++++ 3 files changed, 240 insertions(+) create mode 100644 tests/keyboard/meson.build create mode 100644 tests/keyboard/test-keyboard-shortcuts.c create mode 100644 tests/keyboard/test-keyboard.py (limited to 'tests/keyboard') diff --git a/tests/keyboard/meson.build b/tests/keyboard/meson.build new file mode 100644 index 0000000..4b724b4 --- /dev/null +++ b/tests/keyboard/meson.build @@ -0,0 +1,33 @@ +test_units = [ + 'test-keyboard-shortcuts' +] + +env = [ + 'G_MESSAGES_DEBUG=all', + 'BUILDDIR=' + meson.current_build_dir(), + 'TOP_BUILDDIR=' + meson.build_root(), +# Disable ATK, this should not be required but it caused CI failures -- 2018-12-07 + 'NO_AT_BRIDGE=1' +] +cflags = [ + '-DTEST_SRCDIR="@0@"'.format(meson.current_source_dir()) +] +includes = [top_inc, include_directories('../../panels/keyboard')] + +foreach unit: test_units + exe = executable( + unit, + [unit + '.c'], + dependencies : common_deps, + include_directories : includes, + link_with : [keyboard_panel_lib], + c_args : cflags + ) +endforeach + +test( + 'test-keyboard', + find_program('test-keyboard.py'), + env : env, + timeout : 60 +) diff --git a/tests/keyboard/test-keyboard-shortcuts.c b/tests/keyboard/test-keyboard-shortcuts.c new file mode 100644 index 0000000..37d8613 --- /dev/null +++ b/tests/keyboard/test-keyboard-shortcuts.c @@ -0,0 +1,161 @@ +#include +#include +#include +#include +#include "keyboard-shortcuts.h" + +#define NUM_LAYOUTS 4 + +typedef struct _shortcut_test { + guint16 keycode; + GdkModifierType modifiers; + char *expected_results[NUM_LAYOUTS]; +} shortcut_test; + +/* keycodes taken from /usr/share/X11/xkb/keycodes/evdev */ +shortcut_test shortcut_tests[] = { + { + 24 /* first key after tab in first letter row */, + GDK_SHIFT_MASK | GDK_SUPER_MASK, + { + "q" /* us */, + "apostrophe" /* us+dvorak */, + "a" /* fr+azerty */, + "Cyrillic_shorti" /* ru */ + /* "q" would be valid, too */, + }, + }, + { + 13 /* fifth key in num row */, + GDK_SUPER_MASK, + { + "4" /* us */, + "4" /* us+dvorak */, + "4" /* fr+azerty */, + "4" /* ru */, + }, + }, + { + 13 /* fifth key in num row */, + GDK_SHIFT_MASK | GDK_SUPER_MASK, + { + "4" /* us */, + "4" /* us+dvorak */, + "4" /* fr+azerty */, + "4" /* ru */, + }, + }, + { + 65 /* space key */, + GDK_SHIFT_MASK | GDK_SUPER_MASK, + { + "space" /* us */, + "space" /* us+dvorak */, + "space" /* fr+azerty */, + "space" /* ru */, + }, + }, + { + 23 /* tab key */, + GDK_SHIFT_MASK | GDK_SUPER_MASK, + { + "Tab" /* us */, + "Tab" /* us+dvorak */, + "Tab" /* fr+azerty */, + "Tab" /* ru */, + }, + }, + { + 107 /* print screen/sysrq key */, + GDK_ALT_MASK, + { + "Print" /* us */, + "Print" /* us+dvorak */, + "Print" /* fr+azerty */, + "Print" /* ru */, + }, + }, +}; + +static void +test_event_translation (shortcut_test *shortcut_test) +{ + g_autofree char *translated_name = NULL; + guint keyval; + GdkModifierType modifiers; + + for (int group = 0; group < NUM_LAYOUTS; group++) + { + if (!shortcut_test->expected_results[group]) + continue; + + normalize_keyval_and_mask (shortcut_test->keycode, + shortcut_test->modifiers, + group, + &keyval, + &modifiers); + + translated_name = gtk_accelerator_name (keyval, modifiers); + + if (g_strcmp0 (translated_name, shortcut_test->expected_results[group]) != 0) + { + g_error ("Result for keycode %u with modifieres %u for " + "group %d doesn't match '%s' (got: '%s')", + shortcut_test->keycode, + shortcut_test->modifiers, + group, + shortcut_test->expected_results[group], + translated_name); + g_test_fail (); + } + } +} + +static void +set_keyboard_layouts (char *layouts, + char *variants, + char *options) +{ + GSubprocess *proc; + GError *error = NULL; + + proc = g_subprocess_new (G_SUBPROCESS_FLAGS_NONE, + &error, + "setxkbmap", + "-layout", layouts, + "-variant", variants, + "-option", options, + "-model", "pc105", + NULL); + + if (!proc || !g_subprocess_wait_check(proc, NULL, &error)) + { + g_critical ("Failed to set layout: %s", error->message); + exit (1); + } + + g_object_unref (proc); +} + +static void +run_shortcut_tests (void) +{ + set_keyboard_layouts ("us,us,fr,ru", ",dvorak,azerty,", ""); + + for (int i = 0; i < G_N_ELEMENTS(shortcut_tests); i++) + test_event_translation (&shortcut_tests[i]); +} + +int main (int argc, char **argv) +{ + g_setenv ("GSETTINGS_BACKEND", "memory", TRUE); + g_setenv ("GDK_BACKEND", "x11", TRUE); + g_setenv ("LC_ALL", "C", TRUE); + + gtk_test_init (&argc, &argv, NULL); + + g_test_add_func ("/keyboard/shortcut-translation", + run_shortcut_tests); + + return g_test_run (); +} diff --git a/tests/keyboard/test-keyboard.py b/tests/keyboard/test-keyboard.py new file mode 100644 index 0000000..f6295f2 --- /dev/null +++ b/tests/keyboard/test-keyboard.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python3 +# Copyright © 2018 Red Hat, Inc +# 2021 Sebastian Keller +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, see . +# +# Authors: Benjamin Berg +# Sebastian Keller + +import os +import sys +import unittest + +try: + import dbusmock +except ImportError: + sys.stderr.write('You need python-dbusmock (http://pypi.python.org/pypi/python-dbusmock) for this test suite.\n') + sys.exit(1) + +# Add the shared directory to the search path +sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'shared')) + +from gtest import GTest +from x11session import X11SessionTestCase + +BUILDDIR = os.environ.get('BUILDDIR', os.path.join(os.path.dirname(__file__))) + + +class PanelTestCase(X11SessionTestCase, GTest): + g_test_exe = os.path.join(BUILDDIR, 'test-keyboard-shortcuts') + + +if __name__ == '__main__': + # avoid writing to stderr + unittest.main(testRunner=unittest.TextTestRunner(stream=sys.stdout, verbosity=2)) -- cgit v1.2.3