aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul LeoNerd Evans <leonerd@leonerd.org.uk>2012-04-05 17:57:13 +0100
committerPaul LeoNerd Evans <leonerd@leonerd.org.uk>2012-04-05 17:57:13 +0100
commit5f942e9e3ef9a70beb31e8539dd60a5a3cc0c7a2 (patch)
treea5b4bb621112084b1f1d32996f854f746654b3e1
parenta29d9f0f3c23bfe28c29aa216fd9c5ef809b8246 (diff)
downloadtermo-5f942e9e3ef9a70beb31e8539dd60a5a3cc0c7a2.tar.gz
termo-5f942e9e3ef9a70beb31e8539dd60a5a3cc0c7a2.tar.xz
termo-5f942e9e3ef9a70beb31e8539dd60a5a3cc0c7a2.zip
Added a unit test for mouse report events
-rw-r--r--t/30mouse.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/t/30mouse.c b/t/30mouse.c
new file mode 100644
index 0000000..d543d22
--- /dev/null
+++ b/t/30mouse.c
@@ -0,0 +1,61 @@
+#include "../termkey.h"
+#include "taplib.h"
+
+int main(int argc, char *argv[])
+{
+ TermKey *tk;
+ TermKeyKey key;
+ TermKeyMouseEvent ev;
+ int button, line, col;
+ char buffer[32];
+ size_t len;
+
+ plan_tests(20);
+
+ /* vt100 doesn't have a mouse, we need xterm */
+ tk = termkey_new_abstract("xterm", 0);
+
+ termkey_push_bytes(tk, "\e[M !!", 6);
+
+ is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY for mouse press");
+
+ is_int(key.type, TERMKEY_TYPE_MOUSE, "key.type for mouse press");
+
+ is_int(termkey_interpret_mouse(tk, &key, &ev, &button, &line, &col), TERMKEY_RES_KEY, "interpret_mouse yields RES_KEY");
+
+ is_int(ev, TERMKEY_MOUSE_PRESS, "mouse event for press");
+ is_int(button, 1, "mouse button for press");
+ is_int(line, 1, "mouse line for press");
+ is_int(col, 1, "mouse column for press");
+
+ len = termkey_strfkey(tk, buffer, sizeof buffer, &key, 0);
+ is_int(len, 13, "string length for press");
+ is_str(buffer, "MousePress(1)", "string buffer for press");
+
+ len = termkey_strfkey(tk, buffer, sizeof buffer, &key, TERMKEY_FORMAT_MOUSE_POS);
+ is_int(len, 21, "string length for press");
+ is_str(buffer, "MousePress(1) @ (1,1)", "string buffer for press");
+
+ termkey_push_bytes(tk, "\e[M@\"!", 6);
+
+ termkey_getkey(tk, &key);
+ is_int(termkey_interpret_mouse(tk, &key, &ev, &button, &line, &col), TERMKEY_RES_KEY, "interpret_mouse yields RES_KEY");
+
+ is_int(ev, TERMKEY_MOUSE_DRAG, "mouse event for drag");
+ is_int(button, 1, "mouse button for drag");
+ is_int(line, 1, "mouse line for drag");
+ is_int(col, 2, "mouse column for drag");
+
+ termkey_push_bytes(tk, "\e[M##!", 6);
+
+ termkey_getkey(tk, &key);
+ is_int(termkey_interpret_mouse(tk, &key, &ev, &button, &line, &col), TERMKEY_RES_KEY, "interpret_mouse yields RES_KEY");
+
+ is_int(ev, TERMKEY_MOUSE_RELEASE, "mouse event for release");
+ is_int(line, 1, "mouse line for release");
+ is_int(col, 3, "mouse column for release");
+
+ termkey_destroy(tk);
+
+ return exit_status();
+}