test/common.c

Branch


Log

Author Commit Date CI Message
Ran Benita bd79a960 2023-04-11T23:24:47 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>
Ran Benita f9858bf5 2022-09-24T10:27:51 test: move mkdir & mkdtemp calls to common place and fix them on MSVC Signed-off-by: Ran Benita <ran@unusedvar.com>
Peter Hutterer 41a7c975 2020-07-10T14:57:57 Add asprintf_safe helper function We only ever care about whether we error out or not, so let's wrap this into something more sane. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Peter Hutterer 314b6486 2020-06-24T08:30:50 test: drop some now-obsolete functions These were moved to tools/tools-common.c and now that all tools are switched over, they're no longer needed. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Peter Hutterer c09bf363 2020-06-23T14:01:48 test: untangle interactive-evdev from the test headers Move (sometimes duplicate) the required bits into new shared files tools-common.(c|h) that are compiled into the internal tools library. Rename the test_foo() functions to tools_foo() and in one case just copy the code of the keymap compile function to the tool. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Adrian Perez de Castro abb2f9d9 2019-08-05T15:44:33 MSVC: Provide implementations of test_{dis,en}able_stdin_echo This provides implementations of the test_enable_stdin_echo and test_disable_stdin_echo which do not require <termios.h>, which is not available on Windows.
Adrian Perez de Castro 5354dee2 2019-08-05T13:52:18 MSVC: Use <io.h> as an alternative for <unistd.h> Only the input/output functions from <unistd.h> options are used, so using <io.h> when building with MSVC should be enough. The inclusion of the header in context-priv.c does not seem to be needed (tested on GNU/Linux) and so it is removed. Signed-off-by: Ran Benita <ran@unusedvar.com>
Ran Benita da4a90c1 2019-12-28T13:49:40 Open files in binary mode This turns off some misfeatures on Windows, and does nothing on POSIX. Signed-off-by: Ran Benita <ran@unusedvar.com>
Ran Benita fe417d84 2019-12-28T13:40:38 test/common: avoid double // in path Signed-off-by: Ran Benita <ran@unusedvar.com>
Ran Benita eb23982c 2019-12-28T13:32:02 test/common: simplify test_get_path() Signed-off-by: Ran Benita <ran@unusedvar.com>
Ran Benita 40aab05e 2019-12-27T13:03:20 build: include config.h manually Previously we included it with an `-include` compiler directive. But that's not portable. And it's better to be explicit anyway. Every .c file should have `include "config.h"` first thing. Signed-off-by: Ran Benita <ran@unusedvar.com>
Peter Hutterer 31e561fc 2019-11-05T13:33:11 test: remove a superfluous string-is-null check A few lines above we check path_rel[0], so any null pointer will blow up before we get here. Found by coverity Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Peter Hutterer 96ef14ac 2019-11-05T13:22:49 test: fix a potential memory leak Found by coverity Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Ran Benita 45496c33 2019-10-19T00:37:48 test: fix printf("%s", NULL) in error path ../test/common.c: In function ‘test_get_path’: ../test/common.c:171:9: warning: ‘%s’ directive argument is null [-Wformat-overflow=] 171 | fprintf(stderr, "Failed to allocate path (%d chars) for %s\n", | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 172 | (int) path_len, path); | ~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Ran Benita <ran@unusedvar.com>
Peter Hutterer 878bc085 2018-08-20T16:46:19 test: allow for absolute paths to be resolved This makes it possible to check a keymap sitting elsewhere than in the test directory. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Ran Benita 4309735d 2017-07-31T11:24:28 build: use top_srcdir consistently Signed-off-by: Ran Benita <ran234@gmail.com>
Ran Benita a0a41332 2016-02-27T19:06:14 state: allow different modes for calculating consumed modifiers The current functions dealing with consumed modifiers use the traditional XKB definition of consumed modifiers (see description in the added documentation). However, for several users of the library (e.g. GTK) this definition is unsuitable or too eager. This is exacerbated by some less-than-ideal xkeyboard-config type definitions (CTRL+ALT seems to cause most grief...). So, because we - want to enable alternative interpretations, but - don't want to expose too much internal details, and - want to keep things simple for all library users, we add a high-level "mode" parameter which selects the desired interpretation. New ones can be added as long as they make some sense. All of the old consumed-modifiers functions keep using the traditional ("XKB") mode. I mark xkb_state_mod_mask_remove_consumed() and as deprecated without adding a *2 variant because I don't it is very useful (or used) in practice. Alternative modes are added in subsequent commits (this commit only adds a mode for the existing behavior). https://github.com/xkbcommon/libxkbcommon/issues/17 Signed-off-by: Ran Benita <ran234@gmail.com>
Ran Benita fc41d3d6 2016-05-05T15:41:13 test: use termios instead of system() for disabling terminal echo Takes care of GCC's annoyingly persistent warn_unused_result warnings. But it's better to avoid system() I suppose. Signed-off-by: Ran Benita <ran234@gmail.com>
Ran Benita 74482de6 2015-02-03T20:50:52 test/common: print keycode in decimal not hex Keycodes are usually written in decimal, so hex is hard to compare. Signed-off-by: Ran Benita <ran234@gmail.com>
Ran Benita 5cefa5c5 2014-01-29T13:46:42 test/interactive-evdev: add compose support To try, do e.g.: sudo ./test/interactive-evdev -l us -v intl -o compose:ralt -d Signed-off-by: Ran Benita <ran234@gmail.com>
Ran Benita 54174409 2014-03-27T17:42:20 state: fix consumed modifier calculation The current calculation is in short: entry ? (entry->mask & ~entry->preserve) : 0 This changes it be type->mask & ~(entry ? entry->preserve : 0) This is what Xlib does. While less intuitive, it is actually more correct, if you follow this deduction: - The key group's type->mask defines which modifiers the key even cares about. The others are completely irrelevant (and in fact they are masked out from all sided in the level calculation). Example: NumLock for an alphabetic key. - The type->mask, the mods which are not masked out, are *all* relevant (and in fact in the level calculation they must match *exactly* to the state). These mods affect which level is chosen for the key, whether they are active or not. - Because the type->mask mods are all relevant, they must be considered as consumed by the calculation *even if they are not active*. Therefore we use type->mask instead of entry->mask. The second change is what happens when no entry is found: return 0 or just take preserve to be 0? Let's consider an example, the basic type type "ALPHABETIC" { modifiers = Shift+Lock; map[Shift] = Level2; map[Lock] = Level2; level_name[Level1] = "Base"; level_name[Level2] = "Caps"; }; Suppose Shift+Lock is active - it doesn't match any entry, thus it gets to level 0. The first interpretation would take them both to be unconsumed, the second (new one) would take them both to be consumed. This seems much better: Caps is active, and Shift disables it, they both do something. This change also fixes a pretty lousy bug (since 0.3.2), where Shift appears to apparently *not* disable Caps. What actually happens is that Caps is not consumed (see above) but active, thus the implicit capitalization in get_one_sym() kicks in and capitalizes it anyway. Reported-by: Davinder Pal Singh Bhamra Signed-off-by: Ran Benita <ran234@gmail.com>
Ran Benita b973d71e 2014-03-21T23:00:17 state: add xkb_state_key_get_{utf8,utf32}() API functions These functions generally have the same effect as xkb_state_key_get_syms() + xkb_keysym_to_utf{8,32}(). So why add them? - They provide a slightly nicer interface, especially if the string is the only interest. - It makes the handling of multiple-keysyms-to-utf8 transparent. For the designated use-case of multiple-keysyms (unicode combining characters), this is a must. We also validate the UTF-8, which the user might not otherwise do. - We will need to apply some transformation on the resulting string which depend on the xkb_state. This is not possible with the xkb_keysym_* functions. With these functions, the existing xkb_keysym_to_utf{8,32}() are not expected to be used by a typical user; they are "raw" functions. Signed-off-by: Ran Benita <ran234@gmail.com>
Ran Benita 623602cb 2014-02-07T01:35:56 test: don't print control characters in interactive tests Signed-off-by: Ran Benita <ran234@gmail.com>
Ran Benita d63e0ab8 2013-07-30T13:38:51 test: rename test/interactive to interactive-evdev And share the key-printing functions. In preparation for adding more interactive-* variants. Signed-off-by: Ran Benita <ran234@gmail.com>
Ran Benita 31430670 2014-01-11T16:40:42 Fix some cppcheck warnings Someone was nice enough to run this for us: ftp://ftp.sunet.se/pub/Linux/distributions/Debian/debian/pool/main/libx/libxkbcommon/libxkbcommon_0.3.1.orig.tar.gz [libxkbcommon-0.3.1/src/keymap.c:86]: (style) The scope of the variable 'j' can be reduced. [libxkbcommon-0.3.1/src/keymap.c:87]: (style) The scope of the variable 'key' can be reduced. [libxkbcommon-0.3.1/src/keysym-utf.c:843]: (style) The scope of the variable 'mid' can be reduced. [libxkbcommon-0.3.1/src/state.c:992]: (style) The scope of the variable 'str' can be reduced. [libxkbcommon-0.3.1/src/xkbcomp/action.c:467]: (style) The scope of the variable 'absolute' can be reduced. [libxkbcommon-0.3.1/src/xkbcomp/rules.c:468]: (style) The scope of the variable 'consumed' can be reduced. [libxkbcommon-0.3.1/src/xkbcomp/rules.c:862]: (style) The scope of the variable 'mlvo' can be reduced. [libxkbcommon-0.3.1/src/xkbcomp/rules.c:863]: (style) The scope of the variable 'kccgst' can be reduced. [libxkbcommon-0.3.1/src/xkbcomp/rules.c:865]: (style) The scope of the variable 'match_type' can be reduced. [libxkbcommon-0.3.1/src/xkbcomp/symbols.c:753]: (style) The scope of the variable 'toAct' can be reduced. [libxkbcommon-0.3.1/src/xkbcomp/symbols.c:1573]: (style) The scope of the variable 'key' can be reduced. [libxkbcommon-0.3.1/test/common.c:80]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. [libxkbcommon-0.3.1/test/interactive.c:358]: (style) The scope of the variable 'nevs' can be reduced. [libxkbcommon-0.3.1/test/interactive.c:236]: (style) Checking if unsigned variable 'nsyms' is less than zero. [libxkbcommon-0.3.1/test/interactive.c:226]: (style) Unused variable: unicode Signed-off-by: Ran Benita <ran234@gmail.com>
Ran Benita 7f1b7a1c 2013-07-25T13:21:33 test/keyseq: add de(neo) Level{6,7,8} tests Signed-off-by: Ran Benita <ran234@gmail.com>
Pino Toscano ec9a02a2 2013-07-24T10:05:02 Get rid of the usage of PATH_MAX PATH_MAX is optional in POSIX, so avoid its unconditional usage allocating and freeing buffers as needed. To avoid too many malloc/free in the for loop in FindFileInXkbPath, a buffer is grown according to the size needed at each iteration.
David Herrmann 36f55c49 2013-03-11T12:53:39 keymap: add xkb_keymap_new_from_buffer() The current API doesn't allow the caller to create keymaps from mmap()'ed files. The problem is, xkb_keymap_new_from_string() requires a terminating 0 byte. However, there is no way to guarantee that when using mmap() so a user currently has to copy the whole file just to get the terminating zero byte (assuming they cannot use xkb_keymap_new_from_file()). This adds a new entry xkb_keymap_new_from_buffer() which takes a memory location and the buffer size in bytes. Internally, we depend on yy_scan_{string,byte}() helpers. According to flex documentation these already copy the input string because they are wrappers around yy_scan_buffer(). yy_scan_buffer() on the other hand has some insane requirements. The buffer must be writeable and the last two bytes must be ASCII-NUL. But the buffer may contain other 0 bytes just fine. Because we don't want these constraints in our public API, xkb_keymap_new_from_buffer() needs to create a copy of the input memory. But it then calls yy_scan_buffer() directly. Hence, we have the same number of buffer-copies as with *_from_string() but without the terminating 0 requirement. The explicit yy_scan_buffer() call is preferred over yy_scan_byte() so the buffer-copy operation is not hidden somewhere in flex. Maybe some day we no longer depend on flex and can have a zero-copy API. A user could mmap() a file and it would get parsed right from this buffer. But until then, we shouldn't expose this limitation in the API but instead provide an API that some day can work with zero-copy. Signed-off-by: David Herrmann <dh.herrmann@gmail.com> [ran: rebased on top of my branch] Conflicts: Makefile.am src/xkbcomp/xkbcomp.c
Daniel Stone 4d7600bd 2013-03-19T10:59:38 test: Add va_list variant of test_key_seq For use when chaining tests. Signed-off-by: Daniel Stone <daniel@fooishbar.org>
Daniel Stone 40c46ecd 2013-03-01T23:47:59 Allow NULL rmlvo for xkb_keymap_new_from_names Previously we allowed you to pass a names struct with five NULL members, but not just pass NULL for the struct itself. This was pretty dumb. :( Signed-off-by: Daniel Stone <daniel@fooishbar.org>
Daniel Stone 964b2a40 2013-03-19T10:29:49 test: Suppress RMLVO environment inheritance by default But add a flag to allow it for later usage. Signed-off-by: Daniel Stone <daniel@fooishbar.org>
Daniel Stone 54f95f49 2013-03-18T21:02:35 test: Add flags argument to test_get_context() Allowing overriding of environment suppression, at first. Signed-off-by: Daniel Stone <daniel@fooishbar.org>
Daniel Stone a1f203c0 2013-03-18T20:55:18 test: Move test_key_seq to common.c Signed-off-by: Daniel Stone <daniel@fooishbar.org>
Ran Benita fcd20290 2012-09-21T14:44:17 Don't use xkbcommon-compat names in internal code Signed-off-by: Ran Benita <ran234@gmail.com>
Ran Benita b2110705 2012-09-16T14:45:32 Organize src/ and test/ headers - Add context.h and move context-related functions from xkb-priv.h to it. - Move xkb_context definition back to context.c. - Add keysym.h and move keysym upper/lower/keypad from xkb-priv.h to it. - Rename xkb-priv.h to map.h since it only contains keymap-related definitions and declarations now. - Remove unnecessary includes and some and some other small cleanups. Signed-off-by: Ran Benita <ran234@gmail.com>
Daniel Stone b4b40d73 2012-09-12T16:54:07 Copyright updates With Dan Nicholson's permission (via email), update his copyright and license statements to the standard X.Org boilerplate MIT license, as both myself and Ran have been using. Clean up my copyright declarations (in some cases to correct ownership), and add copyright/license statements from myself and/or Ran where appropriate. Signed-off-by: Daniel Stone <daniel@fooishbar.org>
Ran Benita f3c4032f 2012-08-30T20:23:35 Set log level for tests through env, not directly This way the test logs have all the information, but we don't get eye bleed every time we run them manually. One can always use TESTS_ENVIRONMENT (we correctly use AM_TESTS_ENVIRONMENT now), or set the envvars from the shell. Signed-off-by: Ran Benita <ran234@gmail.com>
Ran Benita 8d7d9792 2012-08-28T00:42:59 log: replace "priority" by "level" everywhere Now that we don't use syslog, "level" does sound more commonplace. We should change it while there is still nobody using it. Also leave some space between the integers of the xkb_log_level enum values, if we ever need to shove more in between. Signed-off-by: Ran Benita <ran234@gmail.com>
Daniel Stone 5e276adb 2012-08-08T14:01:46 Add xkb_log_level enum rather than using syslog Instead of relying on people including syslog.h, add our own XKB_LOG_LEVEL_* defines. Signed-off-by: Daniel Stone <daniel@fooishbar.org>
Daniel Stone ba8458a9 2012-08-08T13:56:28 Increase log verbosity in tests Signed-off-by: Daniel Stone <daniel@fooishbar.org>
Daniel Stone 9308a460 2012-07-17T10:20:15 Run source tree through uncrustify .uncrustify.cfg committed for future reference also, but had to manually fix up a few things: it really likes justifying struct initialisers. Signed-off-by: Daniel Stone <daniel@fooishbar.org>
Daniel Stone 62deaeb5 2012-07-12T14:42:31 Import dataset into test/data/ Use a self-contained dataset instead of relying on a globally-installed set. Data taken from xkeyboard-config 2.5.1. Signed-off-by: Daniel Stone <daniel@fooishbar.org>
Daniel Stone 3e86ebca 2012-07-12T14:15:08 Add a library of common test functions Including creating a context (will come in useful soon), opening and reading files, and compiling keymaps. Signed-off-by: Daniel Stone <daniel@fooishbar.org>