2009-04-10 13:33:31 -06:00
|
|
|
/*
|
2012-09-12 09:54:07 -06:00
|
|
|
* Copyright © 2009 Dan Nicholson
|
2012-07-17 03:20:15 -06:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
2012-09-12 09:54:07 -06:00
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
* Software.
|
2012-07-17 03:20:15 -06:00
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
2012-09-12 09:54:07 -06:00
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
2012-07-17 03:20:15 -06:00
|
|
|
*/
|
2009-04-10 13:33:31 -06:00
|
|
|
|
2012-07-12 07:15:08 -06:00
|
|
|
#include "test.h"
|
2010-10-19 19:57:59 -06:00
|
|
|
|
2012-03-30 17:44:39 -06:00
|
|
|
static int
|
2012-07-12 07:15:08 -06:00
|
|
|
test_file(struct xkb_context *ctx, const char *path_rel)
|
2009-04-10 13:33:31 -06:00
|
|
|
{
|
2012-07-12 07:15:08 -06:00
|
|
|
struct xkb_keymap *keymap = test_compile_file(ctx, path_rel);
|
2009-04-10 13:33:31 -06:00
|
|
|
|
2012-07-12 07:15:08 -06:00
|
|
|
if (!keymap)
|
2012-03-30 17:44:39 -06:00
|
|
|
return 0;
|
|
|
|
|
2012-09-21 05:44:17 -06:00
|
|
|
xkb_keymap_unref(keymap);
|
2012-03-30 17:44:39 -06:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(void)
|
|
|
|
{
|
2013-03-18 15:02:35 -06:00
|
|
|
struct xkb_context *ctx = test_get_context(0);
|
2012-03-30 17:44:39 -06:00
|
|
|
|
2012-07-12 07:15:08 -06:00
|
|
|
assert(test_file(ctx, "keymaps/basic.xkb"));
|
|
|
|
assert(test_file(ctx, "keymaps/comprehensive-plus-geom.xkb"));
|
types: don't use canonical/required types
Xkb required every keymap to have at least the four following canonical
types: ONE_LEVEL, TWO_LEVEL, ALPHABETIC, KEYPAD. This is specified in
e.g. the kbproto spec and XkbKeyTypesForCoreSymbols(3) man page.
If these types are not specified in the keymap, the code specifically
checks for them and adds them to the 4 first places in the types array,
such that they exist in every keymap. These are also the types (along
with some non-required 4-level ones) that are automatically assigned to
keys which do not explicitly declare a type (see FindAutomaticType in
symbols.c, this commit doesn't touch these heuristics, whcih are also not
very nice but necessary).
The xkeyboard-config does not rely on the builtin xkbcomp definitions of
these types and does specify them explicitly, in types/basic and
types/numpad, which are virtually always included.
This commit removes the special behavior:
- The code is ugly and makes keytypes.c harder to read.
- The code practically never gets run - everyone who uses
xkeyboard-config or a keymap based upon it (i.e. everyone) doesn't need
it. So it doesn't get tested.
- It mixes policy with implementation for not very good reasons, it
seems mostly for default compatibility with X11 core.
- And of course we don't need to remain compatible with Xkb ABI neither.
Instead, if we read a keymap with no types specified at all, we simply
assign all keys a default one-level type (like ONE_LEVEL), and issue
plenty of warnings to make it clear (with verbosity >= 3). Note that
this default can actually be changed from within the keymap, by writing
something like
type.modifier = Shift
type.whatever_field = value
in the top level of the xkb_types section. (This functionality is
completely unused as well today, BTW, but makes some sense).
This change means that if someone writes a keymap from scratch and
doesn't add say ALPHABETIC, then something like <AE11> = { [ q Q ]; }; will
ignore the second level. But as stated above this should never happen.
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-08-01 15:29:07 -06:00
|
|
|
assert(test_file(ctx, "keymaps/no-types.xkb"));
|
2012-03-30 17:44:39 -06:00
|
|
|
|
2012-07-23 12:21:03 -06:00
|
|
|
assert(!test_file(ctx, "keymaps/divide-by-zero.xkb"));
|
2012-08-05 03:03:51 -06:00
|
|
|
assert(!test_file(ctx, "keymaps/bad.xkb"));
|
|
|
|
assert(!test_file(ctx, "does not exist"));
|
2012-03-30 17:44:39 -06:00
|
|
|
|
2013-03-01 12:48:02 -07:00
|
|
|
/* Test response to invalid flags and formats. */
|
|
|
|
fclose(stdin);
|
|
|
|
assert(!xkb_keymap_new_from_file(ctx, NULL, XKB_KEYMAP_FORMAT_TEXT_V1, 0));
|
|
|
|
assert(!xkb_keymap_new_from_file(ctx, stdin, 0, 0));
|
|
|
|
assert(!xkb_keymap_new_from_file(ctx, stdin, XKB_KEYMAP_USE_ORIGINAL_FORMAT, 0));
|
|
|
|
assert(!xkb_keymap_new_from_file(ctx, stdin, 1234, 0));
|
|
|
|
assert(!xkb_keymap_new_from_file(ctx, stdin, XKB_KEYMAP_FORMAT_TEXT_V1, -1));
|
|
|
|
assert(!xkb_keymap_new_from_file(ctx, stdin, XKB_KEYMAP_FORMAT_TEXT_V1, 1234));
|
|
|
|
|
2012-07-12 07:15:08 -06:00
|
|
|
xkb_context_unref(ctx);
|
2012-02-15 09:37:31 -07:00
|
|
|
|
2009-04-10 13:33:31 -06:00
|
|
|
return 0;
|
|
|
|
}
|