aboutsummaryrefslogtreecommitdiff
path: root/t/02getkey.c
blob: 8b1881b8a765b1985a66eeb39b3a72f0cbedffa0 (plain)
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
#include <stdio.h>
#include "../termkey.h"
#include "taplib.h"

int main(int argc, char *argv[])
{
  int        fd[2];
  TermKey   *tk;
  TermKeyKey key;

  plan_tests(19);

  pipe(fd);

  /* Sanitise this just in case */
  putenv("TERM=vt100");

  tk = termkey_new(fd[0], TERMKEY_FLAG_NOTERMIOS);

  is_int(termkey_getkey(tk, &key), TERMKEY_RES_NONE, "getkey yields RES_NONE when empty");

  write(fd[1], "h", 1);

  is_int(termkey_getkey(tk, &key), TERMKEY_RES_NONE, "getkey yields RES_NONE before advisereadable");

  is_int(termkey_advisereadable(tk), TERMKEY_RES_AGAIN, "advisereadable yields RES_AGAIN after h");

  is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY after h");

  is_int(key.type,        TERMKEY_TYPE_UNICODE, "key.type after h");
  is_int(key.code.number, 'h',                  "key.code.number after h");
  is_int(key.modifiers,   0,                    "key.modifiers after h");
  is_str(key.utf8,        "h",                  "key.utf8 after h");

  is_int(termkey_getkey(tk, &key), TERMKEY_RES_NONE, "getkey yields RES_NONE a second time");

  write(fd[1], "\x01", 1);

  is_int(termkey_advisereadable(tk), TERMKEY_RES_AGAIN, "advisereadable yields RES_AGAIN after C-a");

  is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY after C-a");

  is_int(key.type,        TERMKEY_TYPE_UNICODE, "key.type after C-a");
  is_int(key.code.number, 'a',                  "key.code.number after C-a");
  is_int(key.modifiers,   TERMKEY_KEYMOD_CTRL,  "key.modifiers after C-a");

  write(fd[1], "\eOA", 3);

  is_int(termkey_advisereadable(tk), TERMKEY_RES_AGAIN, "advisereadable yields RES_AGAIN after Up");

  is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY after Up");

  is_int(key.type,        TERMKEY_TYPE_KEYSYM,  "key.type after Up");
  is_int(key.code.sym,    TERMKEY_SYM_UP,       "key.code.sym after Up");
  is_int(key.modifiers,   0,                    "key.modifiers after Up");

  termkey_destroy(tk);

  return exit_status();
}