* DEALINGS IN THE SOFTWARE.
*/
-#include <assert.h>
-#include <stdbool.h>
-#include <stdio.h>
-#include <string.h>
+#include "config.h"
-#include "xkbcommon/xkbcommon.h"
-#include "rules.h"
+#include "test.h"
+#include "xkbcomp/xkbcomp-priv.h"
+#include "xkbcomp/rules.h"
struct test_data {
/* Rules file */
const char *options;
/* Expected output */
- const char *keymap;
const char *keycodes;
const char *types;
const char *compat;
bool should_fail;
};
-static inline bool
-streq(const char *s1, const char *s2)
-{
- if (s1 == NULL || s2 == NULL)
- return s1 == s2;
- return strcmp(s1, s2) == 0;
-}
-
static bool
test_rules(struct xkb_context *ctx, struct test_data *data)
{
const struct xkb_rule_names rmlvo = {
data->rules, data->model, data->layout, data->variant, data->options
};
- struct xkb_component_names *kccgst;
+ struct xkb_component_names kccgst;
fprintf(stderr, "\n\nChecking : %s\t%s\t%s\t%s\t%s\n", data->rules,
data->model, data->layout, data->variant, data->options);
if (data->should_fail)
- fprintf(stderr, "Expecting: NULL\n");
+ fprintf(stderr, "Expecting: FAILURE\n");
else
- fprintf(stderr, "Expecting: %s\t%s\t%s\t%s\t%s\n", data->keymap,
+ fprintf(stderr, "Expecting: %s\t%s\t%s\t%s\n",
data->keycodes, data->types, data->compat, data->symbols);
- kccgst = xkb_components_from_rules(ctx, &rmlvo);
- if (!kccgst) {
- fprintf(stderr, "Received: NULL\n");
+ if (!xkb_components_from_rules(ctx, &rmlvo, &kccgst)) {
+ fprintf(stderr, "Received : FAILURE\n");
return data->should_fail;
}
- fprintf(stderr, "Received : %s\t%s\t%s\t%s\t%s\n", kccgst->keymap,
- kccgst->keycodes, kccgst->types, kccgst->compat, kccgst->symbols);
+ fprintf(stderr, "Received : %s\t%s\t%s\t%s\n",
+ kccgst.keycodes, kccgst.types, kccgst.compat, kccgst.symbols);
- passed = streq(kccgst->keymap, data->keymap) &&
- streq(kccgst->keycodes, data->keycodes) &&
- streq(kccgst->types, data->types) &&
- streq(kccgst->compat, data->compat) &&
- streq(kccgst->symbols, data->symbols);
+ passed = streq(kccgst.keycodes, data->keycodes) &&
+ streq(kccgst.types, data->types) &&
+ streq(kccgst.compat, data->compat) &&
+ streq(kccgst.symbols, data->symbols);
- free(kccgst->keymap);
- free(kccgst->keycodes);
- free(kccgst->types);
- free(kccgst->compat);
- free(kccgst->symbols);
- free(kccgst);
+ free(kccgst.keycodes);
+ free(kccgst.types);
+ free(kccgst.compat);
+ free(kccgst.symbols);
return passed;
}
int
-main(void)
+main(int argc, char *argv[])
{
struct xkb_context *ctx;
- const char *srcdir = getenv("srcdir");
- char *path;
- ctx = xkb_context_new(XKB_CONTEXT_NO_DEFAULT_INCLUDES);
+ ctx = test_get_context(0);
assert(ctx);
- assert(asprintf(&path, "%s/test/data", srcdir ? srcdir : ".") > 0);
- assert(xkb_context_include_path_append(ctx, path));
- free(path);
-
struct test_data test1 = {
.rules = "simple",
.options = "my_option",
.keycodes = "my_keycodes", .types = "my_types",
- .compat = "my_compat+some:compat",
+ .compat = "my_compat|some:compat",
.symbols = "my_symbols+extra_variant",
};
assert(test_rules(ctx, &test1));
};
assert(test_rules(ctx, &test6));
+ struct test_data test7 = {
+ .rules = "multiple-options",
+
+ .model = "my_model", .layout = "my_layout", .variant = "my_variant",
+ .options = "option3,option1,colon:opt,option11",
+
+ .keycodes = "my_keycodes", .types = "my_types",
+ .compat = "my_compat+some:compat+group(bla)",
+ .symbols = "my_symbols+extra_variant+compose(foo)+keypad(bar)+altwin(menu)",
+ };
+ assert(test_rules(ctx, &test7));
+
xkb_context_unref(ctx);
return 0;
}