summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2021-02-22 12:54:15 +1000
committerRan Benita <ran@unusedvar.com>2021-02-22 13:43:16 +0200
commit0abd430e85586cc37b900e3451b40f9dec4e2783 (patch)
tree22dba37ba4da7de151415678f67f9971cc3af64f /test
parentb4802b06428b417be453384eac6654eec2bba44a (diff)
downloadxorg-lib-libxkbcommon-0abd430e85586cc37b900e3451b40f9dec4e2783.tar.gz
test: add a keysym tester
A simple script that creates a new layout with the given keysym replacing TLDE. Then we compile a keymap and search for the keysym being assigned to TLDE and bail if that fails. The list of keysyms is manually maintained but we only need to add one or two to spot-check whenever the xorgproto is updated. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'test')
-rwxr-xr-xtest/test-keysym.py71
1 files changed, 71 insertions, 0 deletions
diff --git a/test/test-keysym.py b/test/test-keysym.py
new file mode 100755
index 0000000..d237f31
--- /dev/null
+++ b/test/test-keysym.py
@@ -0,0 +1,71 @@
+#!/usr/bin/env python3
+#
+# This script creates a custom layout, overriding the TDLE key with the first
+# argument given.
+
+import argparse
+import tempfile
+from pathlib import Path
+import subprocess
+import os
+import re
+import sys
+
+# Template to force our key to TLDE
+template = """
+default
+xkb_symbols "basic" {{
+ include "us(basic)"
+ replace key <TLDE> {{ [ {} ] }};
+}};
+"""
+
+parser = argparse.ArgumentParser(
+ description='Tool to verify whether a keysym is resolved'
+)
+parser.add_argument('keysym', type=str, help='XKB keysym')
+parser.add_argument('--tool', type=str, nargs=1,
+ default=['xkbcli', 'compile-keymap'],
+ help='Full path to the xkbcli-compile-keymap tool')
+args = parser.parse_args()
+
+with tempfile.TemporaryDirectory() as tmpdir:
+ symfile = Path(tmpdir) / "symbols" / "keytest"
+ symfile.parent.mkdir()
+ with symfile.open(mode='w') as f:
+ f.write(template.format(args.keysym))
+
+ try:
+ cmd = [
+ *args.tool,
+ '--layout', 'keytest',
+ ]
+
+ env = os.environ.copy()
+ env['XKB_CONFIG_EXTRA_PATH'] = tmpdir
+
+ result = subprocess.run(cmd, env=env, capture_output=True,
+ universal_newlines=True)
+ if result.returncode != 0:
+ print('ERROR: Failed to compile:')
+ print(result.stderr)
+ sys.exit(1)
+
+ # grep for TLDE actually being remapped
+ for l in result.stdout.split('\n'):
+ match = re.match(r'\s+key \<TLDE\>\s+{\s+\[\s+(?P<keysym>\w+)\s+\]\s+}', l)
+ if match:
+ if args.keysym == match.group('keysym'):
+ sys.exit(0)
+ elif match.group('keysym') == 'NoSymbol':
+ print('ERROR: key {} not resolved:'.format(args.keysym), l)
+ else:
+ print('ERROR: key {} mapped to wrong key:'.format(args.keysym), l)
+ sys.exit(1)
+
+ print(result.stdout)
+ print('ERROR: above keymap is missing key mapping for {}'.format(args.keysym))
+ sys.exit(1)
+ except FileNotFoundError as err:
+ print('ERROR: invalid or missing tool: {}'.format(err))
+ sys.exit(1)