X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=test%2Frules-file.c;h=d217ba960beef7f1cd2dcf1339d375e17839c673;hb=fe417d841e838adfd57f591ea27bd34a999eeb77;hp=8e301b2cbb206d0eb9c69e425c1341352e6e21b5;hpb=37f4384947939784d1eb4b29bb201974b14f95bb;p=platform%2Fupstream%2Flibxkbcommon.git diff --git a/test/rules-file.c b/test/rules-file.c index 8e301b2..d217ba9 100644 --- a/test/rules-file.c +++ b/test/rules-file.c @@ -21,13 +21,11 @@ * DEALINGS IN THE SOFTWARE. */ -#include -#include -#include -#include +#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 */ @@ -49,14 +47,6 @@ struct test_data { 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) { @@ -64,54 +54,46 @@ 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\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\n", - kccgst->keycodes, kccgst->types, kccgst->compat, kccgst->symbols); + kccgst.keycodes, kccgst.types, kccgst.compat, kccgst.symbols); - passed = 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->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", @@ -119,7 +101,7 @@ main(void) .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)); @@ -176,6 +158,18 @@ main(void) }; 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; }