Commit Graph

425 Commits (26b1a07659f4fb8081190a24d9774fd74dcb1e95)

Author SHA1 Message Date
Pierre Le Marre 26b1a07659 Test: Use a xvfb wrapper for x11 test
The x11 test is currently silently skipped in CI, because it requires a
running X server.

Create a xvfb wrapper to run the test. We do not use `xvfb-run`, because
it is a shell script and it causes valgrind to detect unrelated memory
issues in the shell (dash, bash).

Improve wrapper using a special ELF section

TODO: The wrapper is intended to be used with the x11comp test as well.
2023-09-18 16:07:09 +02:00
Pierre Le Marre a4c0852687 Improved tests related to keysyms
- Add a keymap test with decimal and hexadecimal keysyms.
- Reorganize code in `test/keysym.c` by parsing type: name, Unicode and
  hexadecimal.
- Add more tests for edge cases. In particular:
  - test decimal format (currently not supported);
  - test the Unicode and hexadecimal ranges more thoroughly;
  - test with wrong case without the XKB_KEYSYM_CASE_INSENSITIVE flag;
  - test surrounding spaces.
- Document the tests.
2023-07-14 09:22:24 +02:00
Pierre Le Marre 0d01a933bb Replace keycode numeric offset with EVDEV_OFFSET
Add a constant `EVDEV_OFFSET` to make the semantic of the offset clearer.
2023-07-04 10:59:19 +02:00
Pierre Le Marre fc25e0f0f7 Test(compose): fix assumption on environment variables
The test `test_from_locale` fails when there is a user-defined compose
file, e.g. ~/.XCompose.

Indeed, the function `xkb_compose_table_new_from_locale` use various
environment variables to determine the location of the compose file.

Ensure no environment variables but the required ones are set, in order
to have robust tests.
2023-06-28 07:52:04 +02:00
Pierre Le Marre 183761ac24 Do not interpret nor emit invalid Unicode encoding forms
Surrogates are invalid in both UTF-32 and UTF-8.
See https://www.unicode.org/versions/Unicode15.0.0/ch03.pdf#G28875
and https://www.unicode.org/versions/Unicode15.0.0/ch03.pdf#G31703
2023-05-13 22:02:46 +03:00
Peter Hutterer b06aedb8ba scanner: allow for a zero terminated string as keymap
As the documentation for xkb_keymap_new_from_buffer() states, the "input string
does not have to be zero-terminated". The actual implementation however failed
with "unrecognized token/syntax error" when it encountered a null byte.

Fix this by allowing a null byte at the last position of the buffer. Anything
else is likely a client error anyway.

Fixes #307
2023-05-05 09:57:23 +10:00
Wismill 5b5b67f28c
Add support for modmap None (#291)
Unlike current xkbcommon, X11’s xkbcomp allows to remove entries in
the modifiers’ map using “modifier_map None { … }”.

“None” is translated to the special value “XkbNoModifier” defined in
“X11/extensions/XKB.h”. Then it relies on the fact that in "CopyModMapDef",
the following code:

    1U << entry->modifier

ends up being zero when “entry->modifier” is “XkbNoModifier” (i.e. 0xFF).
Indeed, it relies on the overflow behaviour of the left shift, which in
practice resolves to use only the 5 low bits of the shift amount, i.e.
0x1F here. Then the result of “1U << 0xFF” is cast to “char”, i.e. 0.

This is a good trick but too magical, so in libxkbcommon we will use
an explicit test against our new constant XKB_MOD_NONE.
2023-05-01 23:30:41 +03:00
Ran Benita bd79a960f5 Possible fix for non-MSVC windows compilers
`_MSC_VER` is specific to MSVC, but there can be other compilers targeting
windows. Hopefully they do define `_WIN32`, so let's use that.

Refs: https://github.com/xkbcommon/libxkbcommon/issues/305
Signed-off-by: Ran Benita <ran@unusedvar.com>
2023-04-11 23:29:25 +03:00
Ran Benita f9858bf5b9 test: move mkdir & mkdtemp calls to common place and fix them on MSVC
Signed-off-by: Ran Benita <ran@unusedvar.com>
2022-09-24 12:31:53 +03:00
Ran Benita 4d8293901b utils: move some MSVC compat stuff to common place
Signed-off-by: Ran Benita <ran@unusedvar.com>
2022-09-24 12:31:53 +03:00
Sam Lantinga 2536713070 Remove bogus euro sign entry from keysymtab
Not sure what it's doing here, but converting "€" to a keysym
doesn't work with this entry. 0x13a4 doesn't appear in
xkbcommon-keysyms.h. 0x20ac is the keysym documented in the
header (and it's the last entry in the table).

It's been in the table since it was introduced in e0524296d2
("Add API for getting unicode representation of a keysym").

Co-authored-by: Simon Ser <contact@emersion.fr>
2022-05-15 10:26:44 +03:00
Weng Xuetian b064b60984 Do not clear sibling entries when override.
lokid and hikid actually stores the sibling to current node, which
should not be cleared when override. This would break the sequence with
a common prefix when override another.

Fix #286

Signed-off-by: Weng Xuetian <wengxt@gmail.com>
2022-05-15 10:07:57 +03:00
Peter Hutterer 1c8ef9e0a5 test: add test for variant inheritance of ISO 639/3166 codes
See efa9962432
2022-02-04 12:30:27 +02:00
M Hickford efa9962432
Variants should inherit iso639, iso3166 and brief from parent layout if omitted (#266) 2022-01-24 11:16:08 +10:00
Peter Hutterer 9b05825e53 registry: skip over invalid ISO639 or ISO3166 entries
If the XML file is somehow off, don't load entries that are against the spec.
2022-01-24 10:44:31 +10:00
Peter Hutterer 34ef11d9c9 test: show the tool exit status on failure
We already do so for the non-successful cases, let's do this here too so we know
whether it was a signal or a normal exit.
2022-01-24 07:56:47 +10:00
Ran Benita 8507af731a test/tool-option-parsing: don't depend on build prefix
Fixes: https://github.com/xkbcommon/libxkbcommon/issues/244
Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-05-22 20:11:10 +03:00
Ran Benita 98f07da895 test/compose: add tests for xkb_compose_table_new_from_locale lookup
Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-05-22 20:07:06 +03:00
Ran Benita 5b1b2f7546 test/compose: clean up after a setenv
Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-05-22 20:00:24 +03:00
Ran Benita e2465c2a69 tests/data: add files needed to fully test compose
Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-05-22 19:58:40 +03:00
Ran Benita 09ac27f744 ignore: remove no longer relevant gitignore files
These were relevant for the autoconf build but now we're meson only.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-05-22 19:51:02 +03:00
Isaac Freund 68dddd4132 keysym: fix underflow in binary searches
This is hit when passing an empty string and XKB_KEYSYM_CASE_INSENSITIVE
to xkb_keysym_from_name currently if `(lo + hi) / 2` is 0 and `cmp < 0`,
causing mid to underflow and the the array access into name_to_keysym on
the next iteration of the loop to be out of bounds .

We *would* use ssize_t here as it is the appropriate type, but windows
unfortunately does not define it.
2021-04-25 12:25:58 +03:00
Peter Hutterer 1557668364 test: allow skipping errors in certain conditions
Add a skipError test function that can analyse rc, stdout, stderr to skip a test
even when we expect an error. We use that to skip if we couldn't find a keyboard
in the interactive-evdev test.

Fixes #235

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-04-22 10:02:46 +10:00
Peter Hutterer f60bdb1680 test: add extra info to the layout-tester --help output
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-04-20 10:30:17 +03:00
Peter Hutterer be520ef91c test: print the layout-tester progress bar to stdout by default
tqdm prints to stderr by default but we're using that for failed keymap
compiles (which are the ones that really matter). Plus, whether we're using tqdm
is dependent on isatty(sys.stdout) anyway.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-04-20 10:30:17 +03:00
Peter Hutterer efa5805032 test: add an LVO argument to the XKB layout tester
Slightly easier to debug if we can have it only parse one single layout.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-04-20 10:30:17 +03:00
Peter Hutterer a955dca3d5 test: print the compiled keymaps to a given directory
With --keymap-output-dir, the given directory will contain a list of files named
after the layout + variant ('us', 'us(euro)', ...) that contain the keymaps for
each variant + option combination compiled.

This is still a lot, but better to sift through hundreds of keymaps than tens of
thousands.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-04-20 10:30:17 +03:00
Peter Hutterer 1cae250052 test: rework the output for the xkeyboard-config layout tester
The previous output is largely unusable. The result in the CI test runs is a 6GB
file with every compiled keymap in it and while we can grep for ERROR, it's not
particularly useful.

Let's change this and print out YAML instead - that can be machine-processed.
This patch adds a new parent class that prints itself in YAML format,
the tool invocations are child classes of that class. The result looks like this:

Example output:
- rmlvo: ["evdev", "pc105", "us", "haw", "grp:rwin_switch"]
  cmd: "xkbcli-compile-keymap --verbose --rules evdev --model pc105 --layout us --variant haw --options grp:rwin_switch"
  status: 0
- rmlvo: ["evdev", "pc105", "us", "foo", ""]
  cmd: "xkbcli-compile-keymap --verbose --rules evdev --model pc105 --layout us --variant foo"
  status: 1
  error: "failed to compile keymap"

Special status codes are: 99 for "unrecognized keysym" and 90 for "Cannot open
display" in the setxkbmap case.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-04-20 10:30:17 +03:00
Peter Hutterer 44e8d4b044 test: add proper --verbose handling to the xkeyboard-config tester
Instead of defaulting to verbose on/off depending on isatty, make it an
argument instead.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-04-20 10:30:17 +03:00
Ran Benita 8cd688c063 keysym: avoid strtoul in xkb_keysym_from_name
Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-04-01 22:24:05 +03:00
Ran Benita 1c0e28ad26 keysym: properly handle overflow in 0x keysym names
Relatedly, strtoul allows a lot of unwanted stuff (spaces, +/- sign,
thousand seperators), we really ought not use it. But that's for another
time.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2021-03-30 19:17:29 +03:00
Peter Hutterer d172652753 test: move an assert up to before the strlen() use
../../../test/keysym.c:80:24: warning: Null pointer passed to 1st parameter
expecting 'nonnull' [core.NonNullParamChecker]
  (unsigned) strlen(expected));

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-03-30 01:37:55 +03:00
Peter Hutterer 694b8f7127 test: fix missing va_end in case of test failures
Found by coverity

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-03-19 23:44:30 +02:00
Peter Hutterer 0abd430e85 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>
2021-02-22 13:43:16 +02:00
Peter Hutterer 069777f47f test: fix interactive evdev test invocation
rmlvos is the parent list which then fails during a list join because, well,
it's a list of lists.

Fixes #206

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-01-23 18:57:23 +02:00
Peter Hutterer d5e3695ea2 test: fill in srcdir/builddir when not set in the environment
Makes this test easier to run from the commandline. Where either of top_srcdir
or top_builddir isn't set, fill them in from the CWD or fail otherwise.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-01-23 18:57:23 +02:00
Ran Benita fbf087ea94 keymap-dump: follow xkbcomp in printing affect=both in pointer actions
It is equivalent to nothing but good to match up.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2020-11-23 20:03:17 +02:00
Ran Benita 95f8ff8355 test/data: update host.xkb to match keymap-dump style
This is needed for fixing the x11comp test.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2020-11-23 18:35:27 +02:00
Peter Hutterer 6268ba1c77 test: catch unrecognized keysyms in the xkeyboard-config test
Prompted by
https://gitlab.freedesktop.org/xkeyboard-config/xkeyboard-config/-/merge_requests/127

We run the keymap tool with --verbose which will print the messages from the
compiler to the log file as well. And then we can search for the warning
regarding an unrecognized keysym and fail our test based on that.
2020-10-20 11:02:03 +10:00
Peter Hutterer afdc9ceee7 xkbcomp: where a keysym cannot be resolved, set it to NoSymbol
Where resolve_keysym fails we warn but use the otherwise uninitialized variable
as our keysym. That later ends up in the keymap as random garbage hex value.

Simplest test case, set this in the 'us' keymap:
    key <TLDE>               {      [        xyz ] };

And without this patch we get random garbage:
./build/xkbcli-compile-keymap --layout us | grep TLDE:
    key <TLDE>               {      [      0x018a5cf0 ] };

With this patch, we now get NoSymbol:
./build/xkbcli-compile-keymap --layout us | grep TLDE:
    key <TLDE>               {      [        NoSymbol ] };
2020-10-20 09:23:50 +10:00
Ran Benita 6178924f28 test/tool-option-parsing: skip testing of disabled tools
Signed-off-by: Ran Benita <ran@unusedvar.com>
2020-09-08 09:45:34 +03:00
Ran Benita c621319e53 test/tool-option-parsing: switch from pytest to unittest
For me, installing pytest for libxkbcommon is a bit problematic, so I
end up skipping it which is not great.

Switch to unittest which is built in to Python. It's not as nice as
pytest but good enough in this case.

Note: I was too lazy to switch the plain asserts to unittest
assertions...

Signed-off-by: Ran Benita <ran@unusedvar.com>
2020-09-08 09:45:34 +03:00
Ran Benita c8f309a2de test/tool-option-parsing: keep isolated by using our own test data
Make it possible to run the test on all machines.

Signed-off-by: Ran Benita <ran@unusedvar.com>
2020-09-07 22:06:22 +03:00
Peter Hutterer 13745014c3 test: include unstd.h in the registry test to cut down the MacOS warnings
mkdtmp, rmdir and unlink are in unstd.h on MacOS. Since including that it
doesn't hurt us on Linux, let's do it without ifdefs.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-09-07 22:01:57 +03:00
Ran Benita 534e54f621 test/data: add rule registry files
Signed-off-by: Ran Benita <ran@unusedvar.com>
2020-09-07 11:47:34 +03:00
Ran Benita 1c3521993d test/data: sync from xkeyboard-config 2.30
Signed-off-by: Ran Benita <ran@unusedvar.com>
2020-09-07 11:36:49 +03:00
Ran Benita 461d727830 test/data: change quartz.xkb from CRLF to LF
Signed-off-by: Ran Benita <ran@unusedvar.com>
2020-09-07 11:19:45 +03:00
Peter Hutterer 850ba7e636 test: fix the xkbcli --version test
Fixes https://github.com/xkbcommon/libxkbcommon/issues/185

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-09-07 11:15:08 +10:00
Peter Hutterer d7b39f6ffb Add /etc/xkb as extra lookup path for system data files
This completes the usual triplet of configuration locations available for most
processes:
- vendor-provided data files in /usr/share/X11/xkb
- system-specific data files in /etc/xkb
- user-specific data files in $XDG_CONFIG_HOME/xkb

The default lookup order user, system, vendor, just like everything else that
uses these conventions.

For include directives in rules files, the '%E' resolves to that path.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-08-30 21:49:41 +03:00
Peter Hutterer 9b9c5f2094 test: fix the xkeyboard-config test
'xkbcli compile-keymap' doesn't work unless we ninja install first. But for a
test that's to be run from the test directory, that's not a useful option so
let's call the binary directly. The script adds the meson builddir to the PATH
anyway.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-07-29 08:33:26 +10:00