Branch
Hash :
c58c7df1
Author :
Date :
2025-06-17T21:05:08
Serialize multiple actions per level to VoidAction() in v1 format When using `XKB_KEYMAP_FORMAT_TEXT_V1`, multiple actions per level are now serialized using `VoidAction()`, in order to maintain compatibility with X11.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716
/*
* WARNING: This file is automatically generated by: {{ script }}
* Do not edit manually!
*/
/*
* Copyright © 2024-2025 Pierre Le Marre <dev@wismill.eu>
* SPDX-License-Identifier: MIT
*/
#include "config.h"
#include <assert.h>
#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include "test.h"
#include "utils.h"
{% if not compiler.is_default %}
#include "external_xkb_compilers.h"
{% endif %}
enum update_files {
NO_UPDATE = 0,
UPDATE_USING_TEST_INPUT,
UPDATE_USING_TEST_OUTPUT
};
#define GOLDEN_TESTS_OUTPUTS "keymaps/merge-modes/"
{% if compiler.is_default %}
/* xkbcommon buffer compiler */
static struct xkb_keymap *
compile_buffer(struct xkb_context *context, enum xkb_keymap_format format,
const char *buf, size_t len, void *private)
{
return test_compile_buffer(context, format, buf, len);
}
static bool
test_compile(struct xkb_context *ctx, const char* xkb_root,
const char *test_title,
const char *keymap_str, size_t keymap_len,
const char *path, bool update)
{
return test_compile_output(ctx, XKB_KEYMAP_FORMAT_TEXT_V2,
XKB_KEYMAP_USE_ORIGINAL_FORMAT, compile_buffer,
NULL, test_title, keymap_str, keymap_len,
path, !!update);
}
{% else %}
/* Third-party compiler: {{ compiler.name }} */
struct compile_buffer_{{ compiler.name }}_data {
const char* xkb_root;
};
static int
compile_buffer_{{ compiler.name }}(const char *buf, size_t len, void *private,
char* *out, size_t *out_size)
{
struct compile_buffer_{{ compiler.name }}_data *data = private;
{% if compiler.name == "xkbcomp" %}
/* Xorg xkbcomp */
return compile_with_xkbcomp(NULL, data->xkb_root, buf, len, out, out_size);
{% elif compiler.name == "kbvm" %}
/* kbvm */
return compile_with_kbvm(data->xkb_root, buf, len, out, out_size);
{% else %}
#error "Unsupported compiler: {{ compiler.name }}"
{% endif %}
}
static bool
test_compile(struct xkb_context *ctx, const char* xkb_root,
const char *test_title,
const char *keymap_str, size_t keymap_len,
const char *path, bool update)
{
struct compile_buffer_{{ compiler.name }}_data data = { .xkb_root = xkb_root };
return test_third_pary_compile_output(compile_buffer_{{ compiler.name}},
&data, test_title,
keymap_str, keymap_len,
path, !!update);
}
{% endif %}
struct keymap_test_data {
const char* title;
const char* file;
const char* keymap;
const char* expected;
};
{% if compiler.extended_syntax %}
static void
test_vmods(struct xkb_context *ctx, const char* xkb_root,
enum update_files update) {
#define BASE_VMODS \
"virtual_modifiers U1, U2, U3, U4, U5, U6;\n" \
"virtual_modifiers Z1=none, Z2=none, Z3=none, Z4=none, Z5=none, Z6=none;\n"\
"virtual_modifiers M1=0x1000, M2=0x2000, M3=0x3000, " \
"M4=0x4000, M5=0x5000, M6=0x6000;\n"
const struct keymap_test_data tests[] = {
/*
* Change virtual modifiers in same component
*/
{
.title = "same-component-include-default-augment",
.keymap =
"xkb_keymap {\n"
" xkb_types \"\" {\n"
" include \"merge_modes_vmods(base)|merge_modes_vmods(new)\"\n"
" };\n"
" xkb_compat \"\" { interpret.repeat= True; };\n"
"};",
.file = "same-component-include-default-augment",
},
{
.title = "same-component-include-default-override",
.keymap =
"xkb_keymap {\n"
" xkb_types \"\" {\n"
" include \"merge_modes_vmods(base)+merge_modes_vmods(new)\"\n"
" };\n"
" xkb_compat \"\" { interpret.repeat= True; };\n"
"};",
.file = "same-component-include-default-override",
},
/*
* Change virtual modifiers in another component
*/
{
.title = "other-component-direct",
.keymap =
"xkb_keymap {\n"
" xkb_types {\n"
BASE_VMODS
" };\n"
" xkb_compat \"\" {\n"
" augment virtual_modifiers U1, U2=none, U3=0x300000;\n"
" override virtual_modifiers U4, U5=none, U6=0x600000;\n"
" augment virtual_modifiers Z1, Z2=none, Z3=0x310000;\n"
" override virtual_modifiers Z4, Z5=none, Z6=0x610000;\n"
" augment virtual_modifiers M1, M2=none, M3=0x320000;\n"
" override virtual_modifiers M4, M5=none, M6=0x620000;\n"
" };\n"
"};",
.file = "other-component-direct",
},
{
.title = "other-component-include-default",
.keymap =
"xkb_keymap {\n"
" xkb_types \"\" {\n"
BASE_VMODS
" };\n"
" xkb_compat \"\" { include \"merge_modes_vmods(new)\" };\n"
"};",
.file = "same-component-include-default-override",
},
{
.title = "other-component-include-augment",
.keymap =
"xkb_keymap {\n"
" xkb_types \"\" {\n"
BASE_VMODS
" };\n"
" xkb_compat \"\" { augment \"merge_modes_vmods(new)\" };\n"
"};",
.file = "same-component-include-default-augment",
},
{
.title = "other-component-include-override",
.keymap =
"xkb_keymap {\n"
" xkb_types \"\" {\n"
BASE_VMODS
" };\n"
" xkb_compat \"\" { override \"merge_modes_vmods(new)\" };\n"
"};",
.file = "same-component-include-default-override",
},
{
.title = "other-component-include-replace",
.keymap =
"xkb_keymap {\n"
" xkb_types \"\" {\n"
BASE_VMODS
" };\n"
" xkb_compat \"\" { replace \"merge_modes_vmods(new)\" };\n"
"};",
.file = "same-component-include-default-override",
},
};
for (unsigned int k = 0; k < ARRAY_SIZE(tests); k++) {
const struct keymap_test_data* const test = &tests[k];
char title[1024] = { 0 };
snprintf(title, sizeof(title), "%s #%u: %s", __func__, k, test->title);
char path[PATH_MAX] = { 0 };
snprintf(path, sizeof(path),
GOLDEN_TESTS_OUTPUTS "vmods-%s{{ compiler.suffix }}.xkb",
test->file);
assert(test_compile(ctx, xkb_root, title,
test->keymap, strlen(test->keymap),
path, !!update));
}
}
{% endif %}
static void
test_compat(struct xkb_context *ctx, const char* xkb_root,
enum update_files update)
{
// Github Issue #566
const char keymap_str[] =
"xkb_keymap {\n"
" xkb_keycodes { <> = 8; };\n"
" xkb_compat {\n"
" interpret A { repeat = true; };\n"
" interpret A { repeat = true; };\n"
" interpret A { action = SetMods(mods=Mod1); };\n"
" interpret B { repeat = true; };\n"
" interpret B { repeat = true; };\n"
" augment interpret B { action = SetMods(mods=Mod1); };\n"
" interpret C { repeat = true; };\n"
" interpret C { repeat = true; };\n"
" override interpret C { action = SetMods(mods=Mod1); };\n"
" interpret D { repeat = true; };\n"
" interpret D { repeat = true; };\n"
" replace interpret D { action = SetMods(mods=Mod1); };\n"
"\n"
" indicator \"A\" { modifiers=Shift; };\n"
" indicator \"A\" { modifiers=Lock; };\n"
" indicator \"A\" { groups= Group1; };\n"
" indicator \"B\" { modifiers=Shift; };\n"
" indicator \"B\" { modifiers=Lock; };\n"
" augment indicator \"B\" { groups=Group1; };\n"
" indicator \"C\" { modifiers=Shift; };\n"
" indicator \"C\" { modifiers=Lock; };\n"
" override indicator \"C\" { groups=Group1; };\n"
" indicator \"D\" { modifiers=Shift; };\n"
" indicator \"D\" { modifiers=Lock; };\n"
" replace indicator \"D\" { groups=Group1; };\n"
" };\n"
" xkb_symbols { key <> { }; };\n"
"};\n";
assert(test_compile(ctx, xkb_root, "test_merge_mode: compat",
keymap_str, ARRAY_SIZE(keymap_str) - 1,
GOLDEN_TESTS_OUTPUTS "compat{{ compiler.suffix }}.xkb",
!!update));
}
static void
test_merge_modes(struct xkb_context *ctx, const char* xkb_root,
enum update_files update) {
const struct keymap_test_data tests[] = {
{% for group in tests %}
/*
* #{{ loop.index0 }}{{ " " + group.title if group.title else "" }}
*/
{% for test in group.tests %}
{
.title = "#{{ loop.index0 }} {{ test.title | escape_quotes }}",
.file = "{{ test.file | string | escape_quotes }}",
.keymap =
{%- for line in test.content.splitlines() +%}
"{{ line | escape_quotes }}\n"
{%- endfor %},
.expected =
{% for line in test.expected.splitlines() %}
"{{ line | escape_quotes }}\n"
{% endfor %}
},
{% endfor %}
{% endfor %}
};
for (unsigned int k = 0; k < ARRAY_SIZE(tests); k++) {
const struct keymap_test_data* const test = &tests[k];
char title[1024] = { 0 };
snprintf(title, sizeof(title), "%s #%u: %s", __func__, k, test->title);
char path[PATH_MAX] = { 0 };
{% if compiler.is_default %}
snprintf(path, sizeof(path), GOLDEN_TESTS_OUTPUTS "%s.xkb", test->file);
{% else %}
snprintf(path, sizeof(path),
GOLDEN_TESTS_OUTPUTS "%02u-%s{{ compiler.suffix }}.xkb",
k, test->file);
{% endif %}
const char* const keymap = (update == UPDATE_USING_TEST_INPUT)
? test->expected
: test->keymap;
assert(test_compile(ctx, xkb_root, title, keymap, strlen(keymap),
path, !!update));
}
}
static void
test_defaults(struct xkb_context *ctx, const char* xkb_root,
enum update_files update)
{
const struct keymap_test_data tests[] = {
{
.title = "plain",
.file = "plain",
.keymap =
"xkb_keymap {\n"
" xkb_keycodes {\n"
" <A> = 38;\n"
" <S> = 39;\n"
" <D> = 40;\n"
" <F> = 41;\n"
" <G> = 42;\n"
"\n"
" indicator 1 = \"A\";\n"
" indicator 2 = \"B\";\n"
" indicator 3 = \"C\";\n"
" };\n"
" xkb_types {\n"
" type \"ONE_LEVEL\" {\n"
" map[None] = 1;\n"
" };\n"
" type \"ALPHABETIC\" {\n"
" modifiers = Shift + Lock;\n"
" map[Shift] = 2;\n"
" map[Lock] = 2;\n"
" };\n"
" };\n"
" xkb_compat {\n"
" virtual_modifiers M1=0x1000, M2=0x2000, M3=0x4000, M4=0x8000;\n"
"\n"
" interpret.repeat= False;\n"
" // Effective: override\n"
" interpret.repeat= True;\n"
"\n"
" interpret.virtualmod = M1;\n"
" // Effective: override\n"
" interpret.virtualmod = M2;\n"
" // Ineffective: cannot augment previous value\n"
" augment interpret.virtualmod = M3;\n"
"\n"
" SetGroup.group = 1;\n"
" // Effective: override\n"
" SetGroup.group = 2;\n"
" // Ineffective: cannot augment previous value\n"
" augment SetGroup.group = 3;\n"
"\n"
"\n"
" // Effective: *override* every explicit field\n"
" interpret a {\n"
" virtualmod = M4;\n"
" action=SetGroup(group=1);\n"
" };\n"
" interpret A {\n"
" repeat = False;\n"
" virtualmod = M1;\n"
" action=SetMods(mods=M1);\n"
" };\n"
"\n"
"\n"
" // Effective: no previous interpret entry,\n"
" // so *override* every explicit field\n"
" augment interpret s {\n"
" repeat = False;\n"
" action=SetGroup();\n"
" };\n"
" // Only augment fields not set previously (explicit or implicit)\n"
" augment interpret s {\n"
" // Ineffective: cannot augment previous implicit value\n"
" virtualmod = M4;\n"
" // Ineffective: cannot augment previous explicit value\n"
" action=SetGroup(group=4);\n"
" // Effective: no previous value\n"
" useModMapMods=level1;\n"
" };\n"
" augment interpret S {\n"
" action=SetGroup(group=4);\n"
" };\n"
" interpret g {\n"
" virtualmod = M3;\n"
" repeat = False;"
" action = SetGroup(group=3);\n"
" };\n"
" indicator \"C\" {\n"
" modifiers = M3;\n"
" whichmodstate = locked;\n"
" };\n"
"\n"
"\n"
" indicator.modifiers = M1;\n"
" indicator.modifiers = M2;\n"
" augment indicator.modifiers = M3;\n"
" indicator.groups = All - 1;\n"
" indicator.controls = AudibleBell;\n"
"\n"
" indicator \"A\" {\n"
" modifiers = M4;\n"
" whichmodstate = base;\n"
" };\n"
" indicator \"A\" {\n"
" whichmodstate = locked;\n"
" whichgroupstate = locked;\n"
" controls = SlowKeys;\n"
" };\n"
" augment indicator \"B\" {\n"
" modifiers = M4;\n"
" whichmodstate = base;\n"
" };\n"
" augment indicator \"B\" {\n"
" groups = 4;\n"
" whichmodstate = locked;\n"
" whichgroupstate = locked;\n"
" };\n"
" };\n"
" xkb_symbols {\n"
" name[1] = \"xxx\";\n"
" name[1] = \"yyy\";\n"
" augment name[1] = \"zzz\";\n"
"\n"
" key <A> { [a, A] };\n"
" key <S> { [s, S] };\n"
" modifier_map Shift { <A> };\n"
" modifier_map Control { <S> };\n"
"\n"
" key <G> { type = \"ONE_LEVEL\", repeat=true, [g] };"
" modifier_map Mod3 { <G> };\n"
"\n"
" key.repeat = false;\n"
" key.vmods = M1;\n"
" key.vmods = M2;\n"
" augment key.vmods = M3;\n"
"\n"
" key <D> { vmods = M4, [d, D] };\n"
" augment key <F> { vmods = M4, [f, F] };\n"
" augment key <F> { vmods = M1, repeat = true };\n"
" };\n"
"};\n",
.expected =
"xkb_keymap {\n"
" xkb_keycodes {\n"
" <A> = 38;\n"
" <S> = 39;\n"
" <D> = 40;\n"
" <F> = 41;\n"
" indicator 1 = \"A\";\n"
" indicator 2 = \"B\";\n"
" indicator 3 = \"C\";\n"
" };\n"
" xkb_types {\n"
" type \"ONE_LEVEL\" {\n"
" map[None] = 1;\n"
" };\n"
" type \"ALPHABETIC\" {\n"
" modifiers = Shift + Lock;\n"
" map[Shift] = 2;\n"
" map[Lock] = 2;\n"
" };\n"
" };\n"
" xkb_compat {\n"
" virtual_modifiers M1=0x1000, M2=0x2000, M3=0x4000, M4=0x8000;\n"
"\n"
" interpret.repeat= True;\n"
" interpret.virtualmod = M2;\n"
" SetGroup.group = 2;\n"
"\n"
" interpret a {\n"
" virtualmod = M4;\n"
" action=SetGroup(group=1);\n"
" };\n"
" interpret A {\n"
" repeat = False;\n"
" virtualmod = M1;\n"
" action=SetMods(mods=M1);\n"
" };\n"
" interpret s {\n"
" repeat = False;\n"
" action=SetGroup(group=2);\n"
" useModMapMods=level1;\n"
" };\n"
" interpret S {\n"
" action=SetGroup(group=4);"
" };\n"
"\n"
" indicator.modifiers = M2;\n"
" indicator.groups = All - 1;\n"
" indicator.controls = AudibleBell;\n"
"\n"
" indicator \"A\" {\n"
" modifiers = M4;\n"
" whichmodstate = locked;\n"
" whichgroupstate = locked;\n"
" controls = SlowKeys;\n"
" };\n"
" indicator \"B\" {\n"
" modifiers = M4;\n"
" whichmodstate = base;\n"
" whichgroupstate = locked;\n"
" };\n"
" };\n"
" xkb_symbols {\n"
" name[1] = \"yyy\";\n"
"\n"
" key <A> { [a, A] };\n"
" key <S> { [s, S] };\n"
" modifier_map Shift { <A> };\n"
" modifier_map Control { <S> };\n"
"\n"
" key <D> { vmods = M4, repeat = false, [d, D] };\n"
" key <F> { vmods = M4, repeat = true , [f, F] };\n"
" key <G> { type = \"ONE_LEVEL\", repeat=true, vmods=M3, [g] };"
" };\n"
"};\n"
},
{
.title = "include",
.file = "include",
.keymap =
"xkb_keymap {\n"
" xkb_keycodes {\n"
" <A> = 38;\n"
" <S> = 39;\n"
" <D> = 40;\n"
" <F> = 41;\n"
" <G> = 42;\n"
"\n"
" indicator 1 = \"A\";\n"
" indicator 2 = \"B\";\n"
" indicator 3 = \"C\";\n"
" };\n"
" xkb_types {\n"
" type \"ONE_LEVEL\" {\n"
" map[None] = 1;\n"
" };\n"
" type \"ALPHABETIC\" {\n"
" modifiers = Shift + Lock;\n"
" map[Shift] = 2;\n"
" map[Lock] = 2;\n"
" };\n"
" };\n"
" xkb_compat {\n"
" virtual_modifiers M1,M2,M3;"
" interpret.virtualmod = M3;\n"
" indicator.modifiers = M3;\n"
" SetGroup.group = 3;\n"
"\n"
" include \"merge_modes_defaults\"\n"
"\n"
" interpret g {\n"
" action = SetGroup();\n"
" };\n"
" indicator \"C\" {\n"
" whichmodstate = locked;\n"
" };\n"
" };\n"
" xkb_symbols {\n"
" name[1] = \"XXX\";\n"
"\n"
" key.type = \"ONE_LEVEL\";"
"\n"
" include \"merge_modes_defaults\"\n"
"\n"
" key <G> { repeat = true, [g, G] };\n"
" modifier_map Mod3 { <G> };\n"
" };\n"
"};\n",
.expected =
"xkb_keymap {\n"
" xkb_keycodes {\n"
" <A> = 38;\n"
" <S> = 39;\n"
" <D> = 40;\n"
" <F> = 41;\n"
" indicator 1 = \"A\";\n"
" indicator 2 = \"B\";\n"
" indicator 3 = \"C\";\n"
" };\n"
" xkb_types {\n"
" type \"ONE_LEVEL\" {\n"
" map[None] = 1;\n"
" };\n"
" type \"ALPHABETIC\" {\n"
" modifiers = Shift + Lock;\n"
" map[Shift] = 2;\n"
" map[Lock] = 2;\n"
" };\n"
" };\n"
" xkb_compat {\n"
" virtual_modifiers M1=0x1000, M2=0x2000, M3=0x4000, M4=0x8000;\n"
"\n"
" interpret.repeat= True;\n"
" interpret.virtualmod = M2;\n"
" SetGroup.group = 2;\n"
"\n"
" interpret a {\n"
" virtualmod = M4;\n"
" action=SetGroup(group=1);\n"
" };\n"
" interpret A {\n"
" repeat = False;\n"
" virtualmod = M1;\n"
" action=SetMods(mods=M1);\n"
" };\n"
" interpret s {\n"
" repeat = False;\n"
" action=SetGroup(group=2);\n"
" useModMapMods=level1;\n"
" };\n"
" interpret S {\n"
" action=SetGroup(group=4);\n"
" };\n"
"\n"
" indicator.modifiers = M2;\n"
" indicator.groups = All - 1;\n"
" indicator.controls = AudibleBell;\n"
"\n"
" indicator \"A\" {\n"
" modifiers = M4;\n"
" whichmodstate = locked;\n"
" whichgroupstate = locked;\n"
" controls = SlowKeys;\n"
" };\n"
" indicator \"B\" {\n"
" modifiers = M4;\n"
" whichmodstate = base;\n"
" whichgroupstate = locked;\n"
" };\n"
" };\n"
" xkb_symbols {\n"
" name[1] = \"yyy\";\n"
"\n"
" key <A> { [a, A] };\n"
" key <S> { [s, S] };\n"
" modifier_map Shift { <A> };\n"
" modifier_map Control { <S> };\n"
"\n"
" key <D> { vmods = M4, repeat = false, [d, D] };\n"
" key <F> { vmods = M4, repeat = true , [f, F] };\n"
" key <G> { vmods = M3, [g] };\n"
" };\n"
"};\n"
}
};
for (unsigned int k = 0; k < ARRAY_SIZE(tests); k++) {
const struct keymap_test_data* const test = &tests[k];
char title[1024] = { 0 };
snprintf(title, sizeof(title), "%s #%u: %s", __func__, k, test->title);
char path[PATH_MAX] = { 0 };
snprintf(path, sizeof(path), GOLDEN_TESTS_OUTPUTS "defaults-%s{{ compiler.suffix }}.xkb",
test->file);
assert(test_compile(ctx, xkb_root, title,
test->keymap, strlen(test->keymap),
path, !!update));
}
}
int
main(int argc, char *argv[])
{
test_init();
/* Check if we run the tests or just update their outputs */
enum update_files update_output_files = NO_UPDATE;
if (argc > 1) {
if (streq(argv[1], "update")) {
/* Update files with *expected* results */
update_output_files = UPDATE_USING_TEST_INPUT;
} else if (streq(argv[1], "update-obtained")) {
/* Update files with *obtained* results */
update_output_files = UPDATE_USING_TEST_OUTPUT;
} else {
fprintf(stderr, "ERROR: unsupported argument: \"%s\".\n", argv[1]);
exit(EXIT_FAILURE);
}
}
struct xkb_context *ctx = test_get_context(CONTEXT_NO_FLAG);
assert(ctx);
char* xkb_root = test_get_path("");
assert(xkb_root);
{% if compiler.extended_syntax %}
test_vmods(ctx, xkb_root, update_output_files);
{% endif %}
test_compat(ctx, xkb_root, update_output_files);
test_merge_modes(ctx, xkb_root, update_output_files);
test_defaults(ctx, xkb_root, update_output_files);
free(xkb_root);
xkb_context_unref(ctx);
return EXIT_SUCCESS;
}