| 1 |
/* |
| 2 |
* Copyright © 2012 Ran Benita <[email protected]> |
| 3 |
* Copyright © 2019 Red Hat, Inc. |
| 4 |
* SPDX-License-Identifier: MIT |
| 5 |
*/ |
| 6 |
|
| 7 |
#include "config.h" |
| 8 |
#include "test-config.h" |
| 9 |
|
| 10 |
#include "xkbcommon/xkbcommon.h" |
| 11 |
#include "test.h" |
| 12 |
#include "utils.h" |
| 13 |
#include "xkbcomp/rules.h" |
| 14 |
|
| 15 |
struct test_data { |
| 16 |
/* Rules file */ |
| 17 |
const char *rules; |
| 18 |
|
| 19 |
/* Input */ |
| 20 |
const char *model; |
| 21 |
const char *layout; |
| 22 |
const char *variant; |
| 23 |
const char *options; |
| 24 |
|
| 25 |
/* Expected output */ |
| 26 |
const char *keycodes; |
| 27 |
const char *types; |
| 28 |
const char *compat; |
| 29 |
const char *symbols; |
| 30 |
const char *geometry; |
| 31 |
|
| 32 |
/* Or set this if xkb_components_from_rules() should fail. */ |
| 33 |
bool should_fail; |
| 34 |
}; |
| 35 |
|
| 36 |
static bool |
| 37 |
test_rules(struct xkb_context *ctx, struct test_data *data) |
| 38 |
{ |
| 39 |
fprintf(stderr, "\n\nChecking : %s\t%s\t%s\t%s\t%s\n", data->rules, |
| 40 |
data->model, data->layout, data->variant, data->options); |
| 41 |
|
| 42 |
if (data->should_fail) |
| 43 |
fprintf(stderr, "Expecting: FAILURE\n"); |
| 44 |
else |
| 45 |
fprintf(stderr, "Expecting: %s\t%s\t%s\t%s\n", |
| 46 |
data->keycodes, data->types, data->compat, data->symbols); |
| 47 |
|
| 48 |
const struct xkb_rule_names rmlvo = { |
| 49 |
data->rules, data->model, data->layout, data->variant, data->options |
| 50 |
}; |
| 51 |
struct xkb_component_names kccgst; |
| 52 |
if (xkb_components_names_from_rules(ctx, &rmlvo, NULL, &kccgst)) { |
| 53 |
fprintf(stderr, "Received : %s\t%s\t%s\t%s\n", |
| 54 |
kccgst.keycodes, kccgst.types, kccgst.compatibility, |
| 55 |
kccgst.symbols); |
| 56 |
} else { |
| 57 |
fprintf(stderr, "Received : FAILURE\n"); |
| 58 |
return data->should_fail; |
| 59 |
} |
| 60 |
|
| 61 |
const bool passed = streq_not_null(kccgst.keycodes, data->keycodes) && |
| 62 |
streq_not_null(kccgst.types, data->types) && |
| 63 |
streq_not_null(kccgst.compatibility, data->compat) && |
| 64 |
streq_not_null(kccgst.symbols, data->symbols) && |
| 65 |
streq_null(kccgst.geometry, data->geometry); |
| 66 |
|
| 67 |
free(kccgst.keycodes); |
| 68 |
free(kccgst.types); |
| 69 |
free(kccgst.compatibility); |
| 70 |
free(kccgst.symbols); |
| 71 |
free(kccgst.geometry); |
| 72 |
|
| 73 |
return passed; |
| 74 |
} |
| 75 |
|
| 76 |
int |
| 77 |
main(int argc, char *argv[]) |
| 78 |
{ |
| 79 |
struct xkb_context *ctx; |
| 80 |
|
| 81 |
test_init(); |
| 82 |
|
| 83 |
setenv("XKB_CONFIG_ROOT", TEST_XKB_CONFIG_ROOT, 1); |
| 84 |
|
| 85 |
ctx = test_get_context(0); |
| 86 |
assert(ctx); |
| 87 |
|
| 88 |
struct test_data test1 = { |
| 89 |
.rules = "inc-src-simple", |
| 90 |
|
| 91 |
.model = "my_model", .layout = "my_layout", .variant = "", .options = "", |
| 92 |
|
| 93 |
.keycodes = "my_keycodes", .types = "default_types", |
| 94 |
.compat = "default_compat", .symbols = "my_symbols", |
| 95 |
}; |
| 96 |
assert(test_rules(ctx, &test1)); |
| 97 |
|
| 98 |
struct test_data test2 = { |
| 99 |
.rules = "inc-src-nested", |
| 100 |
|
| 101 |
.model = "my_model", .layout = "my_layout", .variant = "", .options = "", |
| 102 |
|
| 103 |
.keycodes = "my_keycodes", .types = "default_types", |
| 104 |
.compat = "default_compat", .symbols = "my_symbols", |
| 105 |
}; |
| 106 |
assert(test_rules(ctx, &test2)); |
| 107 |
|
| 108 |
struct test_data test3 = { |
| 109 |
.rules = "inc-src-looped", |
| 110 |
|
| 111 |
.model = "my_model", .layout = "my_layout", .variant = "", .options = "", |
| 112 |
|
| 113 |
.should_fail = true, |
| 114 |
}; |
| 115 |
assert(test_rules(ctx, &test3)); |
| 116 |
|
| 117 |
struct test_data test4 = { |
| 118 |
.rules = "inc-src-before-after", |
| 119 |
|
| 120 |
.model = "before_model", .layout = "my_layout", .variant = "", .options = "", |
| 121 |
|
| 122 |
.keycodes = "my_keycodes", .types = "default_types", |
| 123 |
.compat = "default_compat", .symbols = "default_symbols", |
| 124 |
}; |
| 125 |
assert(test_rules(ctx, &test4)); |
| 126 |
|
| 127 |
struct test_data test5 = { |
| 128 |
.rules = "inc-src-options", |
| 129 |
|
| 130 |
.model = "my_model", .layout = "my_layout", .variant = "my_variant", |
| 131 |
.options = "option11,my_option,colon:opt,option111", |
| 132 |
|
| 133 |
.keycodes = "my_keycodes", .types = "default_types", |
| 134 |
.compat = "default_compat+substring+group(bla)|some:compat", |
| 135 |
.symbols = "my_symbols+extra_variant+altwin(menu)", |
| 136 |
}; |
| 137 |
assert(test_rules(ctx, &test5)); |
| 138 |
|
| 139 |
struct test_data test6 = { |
| 140 |
.rules = "inc-src-loop-twice", |
| 141 |
|
| 142 |
.model = "my_model", .layout = "my_layout", .variant = "", .options = "", |
| 143 |
|
| 144 |
.keycodes = "my_keycodes", .types = "default_types", |
| 145 |
.compat = "default_compat", .symbols = "my_symbols", |
| 146 |
}; |
| 147 |
assert(test_rules(ctx, &test6)); |
| 148 |
|
| 149 |
struct test_data test7 = { |
| 150 |
.rules = "inc-no-newline", |
| 151 |
.should_fail = true, |
| 152 |
}; |
| 153 |
assert(test_rules(ctx, &test7)); |
| 154 |
|
| 155 |
struct test_data test8 = { |
| 156 |
.rules = "inc-src-relative-path", |
| 157 |
|
| 158 |
.model = "my_model", .layout = "my_layout", .variant = "", .options = "", |
| 159 |
|
| 160 |
.keycodes = "my_keycodes", .types = "default_types", |
| 161 |
.compat = "default_compat", .symbols = "my_symbols", |
| 162 |
}; |
| 163 |
assert(test_rules(ctx, &test8)); |
| 164 |
|
| 165 |
xkb_context_unref(ctx); |
| 166 |
return 0; |
| 167 |
} |