aboutsummaryrefslogtreecommitdiff
path: root/t/13cmpkey.c
blob: 90ff9e1a6268851cacdd8d6d0437b45e686b457b (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
#include "../termkey.h"
#include "taplib.h"

int main(int argc, char *argv[])
{
  TermKey   *tk;
  TermKeyKey key1, key2;

  plan_tests(10);

  tk = termkey_new(0, TERMKEY_FLAG_NOTERMIOS);

  key1.type = TERMKEY_TYPE_UNICODE;
  key1.code.codepoint = 'A';
  key1.modifiers = 0;

  is_int(termkey_keycmp(tk, &key1, &key1), 0, "cmpkey same structure");

  key2.type = TERMKEY_TYPE_UNICODE;
  key2.code.codepoint = 'A';
  key2.modifiers = 0;

  is_int(termkey_keycmp(tk, &key1, &key2), 0, "cmpkey identical structure");

  key2.modifiers = TERMKEY_KEYMOD_CTRL;

  ok(termkey_keycmp(tk, &key1, &key2) < 0, "cmpkey orders CTRL after nomod");
  ok(termkey_keycmp(tk, &key2, &key1) > 0, "cmpkey orders nomod before CTRL");

  key2.code.codepoint = 'B';
  key2.modifiers = 0;

  ok(termkey_keycmp(tk, &key1, &key2) < 0, "cmpkey orders 'B' after 'A'");
  ok(termkey_keycmp(tk, &key2, &key1) > 0, "cmpkey orders 'A' before 'B'");

  key1.modifiers = TERMKEY_KEYMOD_CTRL;

  ok(termkey_keycmp(tk, &key1, &key2) < 0, "cmpkey orders nomod 'B' after CTRL 'A'");
  ok(termkey_keycmp(tk, &key2, &key1) > 0, "cmpkey orders CTRL 'A' before nomod 'B'");

  key2.type = TERMKEY_TYPE_KEYSYM;
  key2.code.sym = TERMKEY_SYM_UP;

  ok(termkey_keycmp(tk, &key1, &key2) < 0, "cmpkey orders KEYSYM after UNICODE");
  ok(termkey_keycmp(tk, &key2, &key1) > 0, "cmpkey orders UNICODE before KEYSYM");

  termkey_destroy(tk);

  return exit_status();
}