2011-03-31 14:51:21 +02:00
|
|
|
#include "../termkey.h"
|
2011-03-31 13:47:09 +02:00
|
|
|
#include "taplib.h"
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
TermKey *tk;
|
|
|
|
TermKeyKey key;
|
|
|
|
|
2012-04-24 16:58:37 +02:00
|
|
|
plan_tests(31);
|
2011-03-31 13:47:09 +02:00
|
|
|
|
2012-01-26 13:55:34 +01:00
|
|
|
tk = termkey_new_abstract("vt100", 0);
|
2011-03-31 13:47:09 +02:00
|
|
|
|
2012-01-18 11:04:15 +01:00
|
|
|
is_int(termkey_get_buffer_remaining(tk), 256, "buffer free initially 256");
|
|
|
|
|
2011-03-31 13:47:09 +02:00
|
|
|
is_int(termkey_getkey(tk, &key), TERMKEY_RES_NONE, "getkey yields RES_NONE when empty");
|
|
|
|
|
2012-01-18 14:39:50 +01:00
|
|
|
is_int(termkey_push_bytes(tk, "h", 1), 1, "push_bytes returns 1");
|
2011-03-31 13:47:09 +02:00
|
|
|
|
2012-01-18 14:39:50 +01:00
|
|
|
is_int(termkey_get_buffer_remaining(tk), 255, "buffer free 255 after push_bytes");
|
2012-01-18 11:04:15 +01:00
|
|
|
|
2011-03-31 13:47:09 +02:00
|
|
|
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");
|
|
|
|
|
2012-01-18 11:04:15 +01:00
|
|
|
is_int(termkey_get_buffer_remaining(tk), 256, "buffer free 256 after getkey");
|
|
|
|
|
2011-03-31 13:47:09 +02:00
|
|
|
is_int(termkey_getkey(tk, &key), TERMKEY_RES_NONE, "getkey yields RES_NONE a second time");
|
|
|
|
|
2012-01-18 14:39:50 +01:00
|
|
|
termkey_push_bytes(tk, "\x01", 1);
|
2011-03-31 13:47:09 +02:00
|
|
|
|
|
|
|
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");
|
|
|
|
|
2012-01-18 17:36:10 +01:00
|
|
|
termkey_push_bytes(tk, "\033OA", 3);
|
2011-03-31 13:47:09 +02:00
|
|
|
|
|
|
|
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");
|
|
|
|
|
2012-01-18 17:36:10 +01:00
|
|
|
is_int(termkey_push_bytes(tk, "\033O", 2), 2, "push_bytes returns 2");
|
2012-01-18 11:04:15 +01:00
|
|
|
|
|
|
|
is_int(termkey_get_buffer_remaining(tk), 254, "buffer free 254 after partial write");
|
|
|
|
|
|
|
|
is_int(termkey_getkey(tk, &key), TERMKEY_RES_AGAIN, "getkey yields RES_AGAIN after partial write");
|
|
|
|
|
2012-01-18 14:39:50 +01:00
|
|
|
termkey_push_bytes(tk, "C", 1);
|
2012-01-18 11:04:15 +01:00
|
|
|
|
|
|
|
is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY after Right completion");
|
|
|
|
|
|
|
|
is_int(key.type, TERMKEY_TYPE_KEYSYM, "key.type after Right");
|
|
|
|
is_int(key.code.sym, TERMKEY_SYM_RIGHT, "key.code.sym after Right");
|
|
|
|
is_int(key.modifiers, 0, "key.modifiers after Right");
|
|
|
|
|
|
|
|
is_int(termkey_get_buffer_remaining(tk), 256, "buffer free 256 after completion");
|
|
|
|
|
2012-04-24 16:58:37 +02:00
|
|
|
termkey_push_bytes(tk, "\033[27;5u", 7);
|
|
|
|
|
|
|
|
is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY after Ctrl-Escape");
|
|
|
|
|
|
|
|
is_int(key.type, TERMKEY_TYPE_KEYSYM, "key.type after Ctrl-Escape");
|
|
|
|
is_int(key.code.sym, TERMKEY_SYM_ESCAPE, "key.code.sym after Ctrl-Escape");
|
|
|
|
is_int(key.modifiers, TERMKEY_KEYMOD_CTRL, "key.modifiers after Ctrl-Escape");
|
|
|
|
|
2011-03-31 13:47:09 +02:00
|
|
|
termkey_destroy(tk);
|
|
|
|
|
|
|
|
return exit_status();
|
|
|
|
}
|