2011-03-31 19:59:07 +02:00
|
|
|
#include "../termkey.h"
|
|
|
|
#include "taplib.h"
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
TermKey *tk;
|
|
|
|
TermKeyKey key;
|
|
|
|
|
2011-04-01 00:42:52 +02:00
|
|
|
plan_tests(57);
|
2011-03-31 19:59:07 +02:00
|
|
|
|
2014-09-28 03:51:45 +02:00
|
|
|
tk = termkey_new_abstract("vt100", "UTF-8", 0);
|
2011-03-31 19:59:07 +02:00
|
|
|
|
2012-01-18 14:39:50 +01:00
|
|
|
termkey_push_bytes(tk, "a", 1);
|
2011-03-31 19:59:07 +02:00
|
|
|
|
|
|
|
is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY low ASCII");
|
2014-09-28 03:51:45 +02:00
|
|
|
is_int(key.type, TERMKEY_TYPE_KEY, "key.type low ASCII");
|
|
|
|
is_int(key.code.codepoint, 'a', "key.code.codepoint low ASCII");
|
2011-03-31 19:59:07 +02:00
|
|
|
|
|
|
|
/* 2-byte UTF-8 range is U+0080 to U+07FF (0xDF 0xBF) */
|
|
|
|
/* However, we'd best avoid the C1 range, so we'll start at U+00A0 (0xC2 0xA0) */
|
|
|
|
|
2012-01-18 14:39:50 +01:00
|
|
|
termkey_push_bytes(tk, "\xC2\xA0", 2);
|
2011-03-31 19:59:07 +02:00
|
|
|
|
|
|
|
is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY UTF-8 2 low");
|
2014-09-28 03:51:45 +02:00
|
|
|
is_int(key.type, TERMKEY_TYPE_KEY, "key.type UTF-8 2 low");
|
|
|
|
is_int(key.code.codepoint, 0x00A0, "key.code.codepoint UTF-8 2 low");
|
2011-03-31 19:59:07 +02:00
|
|
|
|
2012-01-18 14:39:50 +01:00
|
|
|
termkey_push_bytes(tk, "\xDF\xBF", 2);
|
2011-03-31 19:59:07 +02:00
|
|
|
|
|
|
|
is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY UTF-8 2 high");
|
2014-09-28 03:51:45 +02:00
|
|
|
is_int(key.type, TERMKEY_TYPE_KEY, "key.type UTF-8 2 high");
|
|
|
|
is_int(key.code.codepoint, 0x07FF, "key.code.codepoint UTF-8 2 high");
|
2011-03-31 19:59:07 +02:00
|
|
|
|
|
|
|
/* 3-byte UTF-8 range is U+0800 (0xE0 0xA0 0x80) to U+FFFD (0xEF 0xBF 0xBD) */
|
|
|
|
|
2012-01-18 14:39:50 +01:00
|
|
|
termkey_push_bytes(tk, "\xE0\xA0\x80", 3);
|
2011-03-31 19:59:07 +02:00
|
|
|
|
|
|
|
is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY UTF-8 3 low");
|
2014-09-28 03:51:45 +02:00
|
|
|
is_int(key.type, TERMKEY_TYPE_KEY, "key.type UTF-8 3 low");
|
|
|
|
is_int(key.code.codepoint, 0x0800, "key.code.codepoint UTF-8 3 low");
|
2011-03-31 19:59:07 +02:00
|
|
|
|
2012-01-18 14:39:50 +01:00
|
|
|
termkey_push_bytes(tk, "\xEF\xBF\xBD", 3);
|
2011-03-31 19:59:07 +02:00
|
|
|
|
|
|
|
is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY UTF-8 3 high");
|
2014-09-28 03:51:45 +02:00
|
|
|
is_int(key.type, TERMKEY_TYPE_KEY, "key.type UTF-8 3 high");
|
|
|
|
is_int(key.code.codepoint, 0xFFFD, "key.code.codepoint UTF-8 3 high");
|
2011-03-31 19:59:07 +02:00
|
|
|
|
|
|
|
/* 4-byte UTF-8 range is U+10000 (0xF0 0x90 0x80 0x80) to U+10FFFF (0xF4 0x8F 0xBF 0xBF) */
|
|
|
|
|
2012-01-18 14:39:50 +01:00
|
|
|
termkey_push_bytes(tk, "\xF0\x90\x80\x80", 4);
|
2011-03-31 19:59:07 +02:00
|
|
|
|
|
|
|
is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY UTF-8 4 low");
|
2014-09-28 03:51:45 +02:00
|
|
|
is_int(key.type, TERMKEY_TYPE_KEY, "key.type UTF-8 4 low");
|
|
|
|
is_int(key.code.codepoint, 0x10000, "key.code.codepoint UTF-8 4 low");
|
2011-03-31 19:59:07 +02:00
|
|
|
|
2012-01-18 14:39:50 +01:00
|
|
|
termkey_push_bytes(tk, "\xF4\x8F\xBF\xBF", 4);
|
2011-03-31 19:59:07 +02:00
|
|
|
|
|
|
|
is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY UTF-8 4 high");
|
2014-09-28 03:51:45 +02:00
|
|
|
is_int(key.type, TERMKEY_TYPE_KEY, "key.type UTF-8 4 high");
|
|
|
|
is_int(key.code.codepoint, 0x10FFFF, "key.code.codepoint UTF-8 4 high");
|
2011-03-31 19:59:07 +02:00
|
|
|
|
2011-04-01 00:42:52 +02:00
|
|
|
/* Invalid continuations */
|
|
|
|
|
2012-01-18 14:39:50 +01:00
|
|
|
termkey_push_bytes(tk, "\xC2!", 2);
|
2011-04-01 00:42:52 +02:00
|
|
|
|
|
|
|
is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY UTF-8 2 invalid cont");
|
2014-03-05 02:11:45 +01:00
|
|
|
is_int(key.code.codepoint, 0xFFFD, "key.code.codepoint UTF-8 2 invalid cont");
|
2011-04-01 00:42:52 +02:00
|
|
|
is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY UTF-8 2 invalid after");
|
2014-03-05 02:11:45 +01:00
|
|
|
is_int(key.code.codepoint, '!', "key.code.codepoint UTF-8 2 invalid after");
|
2011-04-01 00:42:52 +02:00
|
|
|
|
2012-01-18 14:39:50 +01:00
|
|
|
termkey_push_bytes(tk, "\xE0!", 2);
|
2011-04-01 00:42:52 +02:00
|
|
|
|
|
|
|
is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY UTF-8 3 invalid cont");
|
2014-03-05 02:11:45 +01:00
|
|
|
is_int(key.code.codepoint, 0xFFFD, "key.code.codepoint UTF-8 3 invalid cont");
|
2011-04-01 00:42:52 +02:00
|
|
|
is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY UTF-8 3 invalid after");
|
2014-03-05 02:11:45 +01:00
|
|
|
is_int(key.code.codepoint, '!', "key.code.codepoint UTF-8 3 invalid after");
|
2011-04-01 00:42:52 +02:00
|
|
|
|
2012-01-18 14:39:50 +01:00
|
|
|
termkey_push_bytes(tk, "\xE0\xA0!", 3);
|
2011-04-01 00:42:52 +02:00
|
|
|
|
|
|
|
is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY UTF-8 3 invalid cont 2");
|
2014-03-05 02:11:45 +01:00
|
|
|
is_int(key.code.codepoint, 0xFFFD, "key.code.codepoint UTF-8 3 invalid cont 2");
|
2011-04-01 00:42:52 +02:00
|
|
|
is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY UTF-8 3 invalid after");
|
2014-03-05 02:11:45 +01:00
|
|
|
is_int(key.code.codepoint, '!', "key.code.codepoint UTF-8 3 invalid after");
|
2011-04-01 00:42:52 +02:00
|
|
|
|
2012-01-18 14:39:50 +01:00
|
|
|
termkey_push_bytes(tk, "\xF0!", 2);
|
2011-04-01 00:42:52 +02:00
|
|
|
|
|
|
|
is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY UTF-8 4 invalid cont");
|
2014-03-05 02:11:45 +01:00
|
|
|
is_int(key.code.codepoint, 0xFFFD, "key.code.codepoint UTF-8 4 invalid cont");
|
2011-04-01 00:42:52 +02:00
|
|
|
is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY UTF-8 4 invalid after");
|
2014-03-05 02:11:45 +01:00
|
|
|
is_int(key.code.codepoint, '!', "key.code.codepoint UTF-8 4 invalid after");
|
2011-04-01 00:42:52 +02:00
|
|
|
|
2012-01-18 14:39:50 +01:00
|
|
|
termkey_push_bytes(tk, "\xF0\x90!", 3);
|
2011-04-01 00:42:52 +02:00
|
|
|
|
|
|
|
is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY UTF-8 4 invalid cont 2");
|
2014-03-05 02:11:45 +01:00
|
|
|
is_int(key.code.codepoint, 0xFFFD, "key.code.codepoint UTF-8 4 invalid cont 2");
|
2011-04-01 00:42:52 +02:00
|
|
|
is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY UTF-8 4 invalid after");
|
2014-03-05 02:11:45 +01:00
|
|
|
is_int(key.code.codepoint, '!', "key.code.codepoint UTF-8 4 invalid after");
|
2011-04-01 00:42:52 +02:00
|
|
|
|
2012-01-18 14:39:50 +01:00
|
|
|
termkey_push_bytes(tk, "\xF0\x90\x80!", 4);
|
2011-04-01 00:42:52 +02:00
|
|
|
|
|
|
|
is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY UTF-8 4 invalid cont 3");
|
2014-03-05 02:11:45 +01:00
|
|
|
is_int(key.code.codepoint, 0xFFFD, "key.code.codepoint UTF-8 4 invalid cont 3");
|
2011-04-01 00:42:52 +02:00
|
|
|
is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY UTF-8 4 invalid after");
|
2014-03-05 02:11:45 +01:00
|
|
|
is_int(key.code.codepoint, '!', "key.code.codepoint UTF-8 4 invalid after");
|
2011-04-01 00:42:52 +02:00
|
|
|
|
|
|
|
/* Partials */
|
|
|
|
|
2012-01-18 14:39:50 +01:00
|
|
|
termkey_push_bytes(tk, "\xC2", 1);
|
2011-04-01 00:42:52 +02:00
|
|
|
is_int(termkey_getkey(tk, &key), TERMKEY_RES_AGAIN, "getkey yields RES_AGAIN UTF-8 2 partial");
|
|
|
|
|
2012-01-18 14:39:50 +01:00
|
|
|
termkey_push_bytes(tk, "\xA0", 1);
|
2011-04-01 00:42:52 +02:00
|
|
|
is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY UTF-8 2 partial");
|
2014-03-05 02:11:45 +01:00
|
|
|
is_int(key.code.codepoint, 0x00A0, "key.code.codepoint UTF-8 2 partial");
|
2011-04-01 00:42:52 +02:00
|
|
|
|
2012-01-18 14:39:50 +01:00
|
|
|
termkey_push_bytes(tk, "\xE0", 1);
|
2011-04-01 00:42:52 +02:00
|
|
|
is_int(termkey_getkey(tk, &key), TERMKEY_RES_AGAIN, "getkey yields RES_AGAIN UTF-8 3 partial");
|
|
|
|
|
2012-01-18 14:39:50 +01:00
|
|
|
termkey_push_bytes(tk, "\xA0", 1);
|
2011-04-01 00:42:52 +02:00
|
|
|
is_int(termkey_getkey(tk, &key), TERMKEY_RES_AGAIN, "getkey yields RES_AGAIN UTF-8 3 partial");
|
|
|
|
|
2012-01-18 14:39:50 +01:00
|
|
|
termkey_push_bytes(tk, "\x80", 1);
|
2011-04-01 00:42:52 +02:00
|
|
|
is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY UTF-8 3 partial");
|
2014-03-05 02:11:45 +01:00
|
|
|
is_int(key.code.codepoint, 0x0800, "key.code.codepoint UTF-8 3 partial");
|
2011-04-01 00:42:52 +02:00
|
|
|
|
2012-01-18 14:39:50 +01:00
|
|
|
termkey_push_bytes(tk, "\xF0", 1);
|
2011-04-01 00:42:52 +02:00
|
|
|
is_int(termkey_getkey(tk, &key), TERMKEY_RES_AGAIN, "getkey yields RES_AGAIN UTF-8 4 partial");
|
|
|
|
|
2012-01-18 14:39:50 +01:00
|
|
|
termkey_push_bytes(tk, "\x90", 1);
|
2011-04-01 00:42:52 +02:00
|
|
|
is_int(termkey_getkey(tk, &key), TERMKEY_RES_AGAIN, "getkey yields RES_AGAIN UTF-8 4 partial");
|
|
|
|
|
2012-01-18 14:39:50 +01:00
|
|
|
termkey_push_bytes(tk, "\x80", 1);
|
2011-04-01 00:42:52 +02:00
|
|
|
is_int(termkey_getkey(tk, &key), TERMKEY_RES_AGAIN, "getkey yields RES_AGAIN UTF-8 4 partial");
|
|
|
|
|
2012-01-18 14:39:50 +01:00
|
|
|
termkey_push_bytes(tk, "\x80", 1);
|
2011-04-01 00:42:52 +02:00
|
|
|
is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY UTF-8 4 partial");
|
2014-03-05 02:11:45 +01:00
|
|
|
is_int(key.code.codepoint, 0x10000, "key.code.codepoint UTF-8 4 partial");
|
2011-04-01 00:42:52 +02:00
|
|
|
|
2011-03-31 19:59:07 +02:00
|
|
|
termkey_destroy(tk);
|
|
|
|
|
|
|
|
return exit_status();
|
|
|
|
}
|