2012-01-18 14:39:50 +01:00
|
|
|
#include <stdio.h>
|
2012-03-08 22:31:16 +01:00
|
|
|
#include <errno.h>
|
2014-10-14 00:24:47 +02:00
|
|
|
#include "../termo.h"
|
2012-01-18 14:39:50 +01:00
|
|
|
#include "taplib.h"
|
|
|
|
|
2014-09-28 05:56:13 +02:00
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
2012-01-18 14:39:50 +01:00
|
|
|
{
|
2014-09-28 05:56:13 +02:00
|
|
|
int fd[2];
|
2014-10-14 00:24:47 +02:00
|
|
|
termo_t *tk;
|
|
|
|
termo_key_t key;
|
2012-01-18 14:39:50 +01:00
|
|
|
|
2014-09-28 05:56:13 +02:00
|
|
|
plan_tests (21);
|
2012-01-18 14:39:50 +01:00
|
|
|
|
2014-10-14 21:19:11 +02:00
|
|
|
// We'll need a real filehandle we can write/read. pipe() can make us one
|
2014-09-28 05:56:13 +02:00
|
|
|
pipe (fd);
|
2012-01-18 14:39:50 +01:00
|
|
|
|
2014-10-14 21:19:11 +02:00
|
|
|
// Sanitise this just in case
|
2014-09-28 05:56:13 +02:00
|
|
|
putenv ("TERM=vt100");
|
2012-01-18 14:39:50 +01:00
|
|
|
|
2014-10-14 00:24:47 +02:00
|
|
|
tk = termo_new (fd[0], NULL, TERMO_FLAG_NOTERMIOS);
|
2012-01-18 14:39:50 +01:00
|
|
|
|
2014-10-14 00:24:47 +02:00
|
|
|
is_int (termo_get_buffer_remaining (tk), 256,
|
2014-09-28 05:56:13 +02:00
|
|
|
"buffer free initially 256");
|
2012-01-18 14:39:50 +01:00
|
|
|
|
2014-10-14 00:24:47 +02:00
|
|
|
is_int (termo_getkey (tk, &key), TERMO_RES_NONE,
|
2014-09-28 05:56:13 +02:00
|
|
|
"getkey yields RES_NONE when empty");
|
2012-01-18 14:39:50 +01:00
|
|
|
|
2014-09-28 05:56:13 +02:00
|
|
|
write (fd[1], "h", 1);
|
2012-01-18 14:39:50 +01:00
|
|
|
|
2014-10-14 00:24:47 +02:00
|
|
|
is_int (termo_getkey (tk, &key), TERMO_RES_NONE,
|
2014-09-28 05:56:13 +02:00
|
|
|
"getkey yields RES_NONE before advisereadable");
|
2012-01-18 14:39:50 +01:00
|
|
|
|
2014-10-14 00:24:47 +02:00
|
|
|
is_int (termo_advisereadable (tk), TERMO_RES_AGAIN,
|
2014-09-28 05:56:13 +02:00
|
|
|
"advisereadable yields RES_AGAIN after h");
|
2012-01-18 14:39:50 +01:00
|
|
|
|
2014-10-14 00:24:47 +02:00
|
|
|
is_int (termo_get_buffer_remaining (tk), 255,
|
2014-09-28 05:56:13 +02:00
|
|
|
"buffer free 255 after advisereadable");
|
2012-01-18 14:39:50 +01:00
|
|
|
|
2014-10-14 00:24:47 +02:00
|
|
|
is_int (termo_getkey (tk, &key), TERMO_RES_KEY,
|
2014-09-28 05:56:13 +02:00
|
|
|
"getkey yields RES_KEY after h");
|
2012-01-18 14:39:50 +01:00
|
|
|
|
2014-10-14 00:24:47 +02:00
|
|
|
is_int (key.type, TERMO_TYPE_KEY, "key.type after h");
|
2014-09-28 05:56:13 +02:00
|
|
|
is_int (key.code.codepoint, 'h', "key.code.codepoint after h");
|
|
|
|
is_int (key.modifiers, 0, "key.modifiers after h");
|
|
|
|
is_str (key.multibyte, "h", "key.multibyte after h");
|
2012-01-18 14:39:50 +01:00
|
|
|
|
2014-10-14 00:24:47 +02:00
|
|
|
is_int (termo_get_buffer_remaining (tk), 256,
|
2014-09-28 05:56:13 +02:00
|
|
|
"buffer free 256 after getkey");
|
2012-01-18 14:39:50 +01:00
|
|
|
|
2014-10-14 00:24:47 +02:00
|
|
|
is_int (termo_getkey (tk, &key), TERMO_RES_NONE,
|
2014-09-28 05:56:13 +02:00
|
|
|
"getkey yields RES_NONE a second time");
|
2012-01-18 14:39:50 +01:00
|
|
|
|
2014-09-28 05:56:13 +02:00
|
|
|
write (fd[1], "\033O", 2);
|
2014-10-14 00:24:47 +02:00
|
|
|
termo_advisereadable (tk);
|
2012-01-18 14:39:50 +01:00
|
|
|
|
2014-10-14 00:24:47 +02:00
|
|
|
is_int (termo_get_buffer_remaining (tk), 254,
|
2014-09-28 05:56:13 +02:00
|
|
|
"buffer free 254 after partial write");
|
2012-01-18 14:39:50 +01:00
|
|
|
|
2014-10-14 00:24:47 +02:00
|
|
|
is_int (termo_getkey (tk, &key), TERMO_RES_AGAIN,
|
2014-09-28 05:56:13 +02:00
|
|
|
"getkey yields RES_AGAIN after partial write");
|
2012-01-18 14:39:50 +01:00
|
|
|
|
2014-09-28 05:56:13 +02:00
|
|
|
write (fd[1], "C", 1);
|
2014-10-14 00:24:47 +02:00
|
|
|
termo_advisereadable (tk);
|
2012-01-18 14:39:50 +01:00
|
|
|
|
2014-10-14 00:24:47 +02:00
|
|
|
is_int (termo_getkey (tk, &key), TERMO_RES_KEY,
|
2014-09-28 05:56:13 +02:00
|
|
|
"getkey yields RES_KEY after Right completion");
|
2012-01-18 14:39:50 +01:00
|
|
|
|
2014-10-14 00:24:47 +02:00
|
|
|
is_int (key.type, TERMO_TYPE_KEYSYM, "key.type after Right");
|
|
|
|
is_int (key.code.sym, TERMO_SYM_RIGHT, "key.code.sym after Right");
|
2014-09-28 05:56:13 +02:00
|
|
|
is_int (key.modifiers, 0, "key.modifiers after Right");
|
2012-01-18 14:39:50 +01:00
|
|
|
|
2014-10-14 00:24:47 +02:00
|
|
|
is_int (termo_get_buffer_remaining (tk), 256,
|
2014-09-28 05:56:13 +02:00
|
|
|
"buffer free 256 after completion");
|
2012-01-18 14:39:50 +01:00
|
|
|
|
2014-10-14 00:24:47 +02:00
|
|
|
termo_stop (tk);
|
2012-03-08 22:31:16 +01:00
|
|
|
|
2014-10-14 00:24:47 +02:00
|
|
|
is_int (termo_getkey (tk, &key), TERMO_RES_ERROR,
|
|
|
|
"getkey yields RES_ERROR after termo_stop ()");
|
2014-09-28 05:56:13 +02:00
|
|
|
is_int (errno, EINVAL, "getkey error is EINVAL");
|
2012-03-08 22:31:16 +01:00
|
|
|
|
2014-10-14 00:24:47 +02:00
|
|
|
termo_destroy (tk);
|
2014-09-28 05:56:13 +02:00
|
|
|
return exit_status ();
|
2012-01-18 14:39:50 +01:00
|
|
|
}
|