Skip to content

Commit

Permalink
test: improve debugging output for test_key_seq
Browse files Browse the repository at this point in the history
Print the op too to make it easier to find which part in a long test_key_seq
triggered an assertion and add some whitespace for nicer debugging output.
  • Loading branch information
whot committed Feb 14, 2024
1 parent c31d3b0 commit e9af069
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions test/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ test_key_seq_va(struct xkb_keymap *keymap, va_list ap)
xkb_keysym_t sym;
unsigned int nsyms, i;
char ksbuf[XKB_KEYSYM_NAME_MAX_SIZE];
const char *opstr = NULL;

fprintf(stderr, "----\n");

Expand All @@ -88,13 +89,22 @@ test_key_seq_va(struct xkb_keymap *keymap, va_list ap)
kc = va_arg(ap, int) + EVDEV_OFFSET;
op = va_arg(ap, int);

switch (op) {
case DOWN: opstr = "DOWN"; break;
case REPEAT: opstr = "REPEAT"; break;
case UP: opstr = "UP"; break;
case BOTH: opstr = "BOTH"; break;
case NEXT: opstr = "NEXT"; break;
case FINISH: opstr = "FINISH"; break;
}

nsyms = xkb_state_key_get_syms(state, kc, &syms);
if (nsyms == 1) {
sym = xkb_state_key_get_one_sym(state, kc);
syms = &sym;
}

fprintf(stderr, "got %u syms for keycode %u: [", nsyms, kc);
fprintf(stderr, "op %-6s got %u syms for keycode %3u: [", opstr, nsyms, kc);

if (op == DOWN || op == BOTH)
xkb_state_update_key(state, kc, XKB_KEY_DOWN);
Expand All @@ -108,15 +118,15 @@ test_key_seq_va(struct xkb_keymap *keymap, va_list ap)

if (keysym == FINISH || keysym == NEXT) {
xkb_keysym_get_name(syms[i], ksbuf, sizeof(ksbuf));
fprintf(stderr, "Did not expect keysym: %s.\n", ksbuf);
fprintf(stderr, " Did not expect keysym: %s.\n", ksbuf);
goto fail;
}

if (keysym != syms[i]) {
xkb_keysym_get_name(keysym, ksbuf, sizeof(ksbuf));
fprintf(stderr, "Expected keysym: %s. ", ksbuf);;
fprintf(stderr, " Expected keysym: %s. ", ksbuf);;
xkb_keysym_get_name(syms[i], ksbuf, sizeof(ksbuf));
fprintf(stderr, "Got keysym: %s.\n", ksbuf);;
fprintf(stderr, " Got keysym: %s.\n", ksbuf);;
goto fail;
}
}
Expand All @@ -125,7 +135,7 @@ test_key_seq_va(struct xkb_keymap *keymap, va_list ap)
keysym = va_arg(ap, int);
if (keysym != XKB_KEY_NoSymbol) {
xkb_keysym_get_name(keysym, ksbuf, sizeof(ksbuf));
fprintf(stderr, "Expected %s, but got no keysyms.\n", ksbuf);
fprintf(stderr, " Expected %s, but got no keysyms.\n", ksbuf);
goto fail;
}
}
Expand Down

0 comments on commit e9af069

Please sign in to comment.