summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2011-03-20 11:02:45 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2011-04-04 09:39:19 +1000
commitbe52f449c148028ee912aa12ea9a91ed28590a9e (patch)
tree9cfd6ace276d1c99a107013d3d4a58f096aa1bf6 /test
parent9290ce357b5063e8170f28282711718794a3c2d0 (diff)
test: Add some tests for HW state changes.
Includes basic finger counting test, some button tests and axis tests. These tests simply check that the HW state changes reflect the events pumped in. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'test')
-rw-r--r--test/Makefile.am1
-rw-r--r--test/eventcomm-test.c153
2 files changed, 154 insertions, 0 deletions
diff --git a/test/Makefile.am b/test/Makefile.am
index 763ed54..16502ee 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -6,6 +6,7 @@ if BUILD_EVENTCOMM
noinst_PROGRAMS = eventcomm-test
eventcomm_test_SOURCES = eventcomm-test.c\
+ $(top_srcdir)/src/eventcomm.c \
$(fake_syms)
endif
diff --git a/test/eventcomm-test.c b/test/eventcomm-test.c
index ac24640..7faf638 100644
--- a/test/eventcomm-test.c
+++ b/test/eventcomm-test.c
@@ -31,7 +31,160 @@
#include <stdio.h>
#include <assert.h>
+#include "synaptics.h"
+#include "synapticsstr.h"
+#include "eventcomm.h"
+
+int fd_read, fd_write;
+
+/* A syn event, always handy to have */
+struct input_event syn = { {0, 0}, EV_SYN, SYN_REPORT, 0 };
+
+static void
+create_pipe_fd(void)
+{
+ int pipefd[2];
+
+ assert(pipe(pipefd) != -1);
+
+ fd_read = pipefd[0];
+ fd_write = pipefd[1];
+}
+
+static void
+reset_data(struct SynapticsHwState *hw, struct CommData *comm)
+{
+ memset(comm, 0, sizeof(struct CommData));
+ memset(hw, 0, sizeof(struct SynapticsHwState));
+}
+
+/**
+ * Write n input events to fd, followed by the syn event.
+ */
+static void
+write_event(int fd, struct input_event *ev, int n)
+{
+ write(fd, ev, sizeof(struct input_event) * n);
+ write(fd, &syn, sizeof(syn));
+}
+
+
+static void
+test_buttons(int fd,
+ InputInfoPtr pInfo,
+ struct SynapticsHwState *hw,
+ struct CommData *comm)
+{
+ struct input_event ev = {{0, 0}, EV_KEY, 0, 0};
+
+ reset_data(hw, comm);
+
+#define _test_press_release(_code, field) \
+ ev.code = (_code); \
+ ev.value = 1; \
+ write_event(fd, &ev, 1); \
+ EventReadHwState(pInfo, comm, hw); \
+ assert(hw->field == 1); \
+ ev.value = 0; /* button release */ \
+ write_event(fd_write, &ev, 1); \
+ EventReadHwState(pInfo, comm, hw); \
+ assert(hw->field == 0);
+
+ _test_press_release(BTN_LEFT, left);
+ _test_press_release(BTN_RIGHT, right);
+ _test_press_release(BTN_MIDDLE, middle);
+ _test_press_release(BTN_FORWARD, up);
+ _test_press_release(BTN_BACK, down);
+ _test_press_release(BTN_0, multi[0]);
+ _test_press_release(BTN_1, multi[1]);
+ _test_press_release(BTN_2, multi[2]);
+ _test_press_release(BTN_3, multi[3]);
+ _test_press_release(BTN_4, multi[4]);
+ _test_press_release(BTN_5, multi[5]);
+ _test_press_release(BTN_6, multi[6]);
+ _test_press_release(BTN_7, multi[7]);
+}
+
+/**
+ * This test checks that the recognised event fields set the right hardware
+ * state. It's a fairly limited test and does not check whether any of the
+ * others change the HW state at all.
+ */
+static void
+test_read_hw_state(void)
+{
+ InputInfoRec info = {0};
+ SynapticsPrivate private;
+ struct SynapticsHwState hw = {0};
+ struct CommData comm = {0};
+
+ struct input_event ev[] = {
+ { {0, 0}, EV_KEY, BTN_TOOL_FINGER, 1 },
+ { {0, 0}, EV_KEY, BTN_TOOL_DOUBLETAP, 1 },
+ { {0, 0}, EV_KEY, BTN_TOOL_TRIPLETAP, 1 },
+ { {0, 0}, EV_ABS, ABS_X, 42 },
+ { {0, 0}, EV_ABS, ABS_Y, 21 },
+ { {0, 0}, EV_ABS, ABS_PRESSURE, 56 },
+ { {0, 0}, EV_ABS, ABS_TOOL_WIDTH, 204 },
+ };
+
+ memset(&private, 0, sizeof(private));
+
+ info.private = &private;
+ info.fd = fd_read;
+
+
+ /* just the syn event */
+ reset_data(&hw, &comm);
+ write(fd_write, &syn, sizeof(syn));
+ EventReadHwState(&info, &comm, &hw);
+ assert(hw.numFingers == 0);
+
+ /* one finger */
+ reset_data(&hw, &comm);
+ write_event(fd_write, &ev[0], 1);
+ EventReadHwState(&info, &comm, &hw);
+ assert(hw.numFingers == 1);
+
+ /* two fingers */
+ reset_data(&hw, &comm);
+ write_event(fd_write, &ev[1], 1);
+ EventReadHwState(&info, &comm, &hw);
+ assert(hw.numFingers == 2);
+
+ /* three fingers */
+ reset_data(&hw, &comm);
+ write_event(fd_write, &ev[2], 1);
+ EventReadHwState(&info, &comm, &hw);
+ assert(hw.numFingers == 3);
+
+ /* x/y data */
+ reset_data(&hw, &comm);
+ write_event(fd_write, &ev[3], 2);
+ EventReadHwState(&info, &comm, &hw);
+ assert(hw.x == ev[3].value);
+ assert(hw.y == ev[4].value);
+
+ /* pressure */
+ reset_data(&hw, &comm);
+ write_event(fd_write, &ev[5], 1);
+ EventReadHwState(&info, &comm, &hw);
+ assert(hw.z == ev[5].value);
+
+ /* finger width */
+ reset_data(&hw, &comm);
+ write_event(fd_write, &ev[6], 1);
+ EventReadHwState(&info, &comm, &hw);
+ assert(hw.fingerWidth == ev[6].value);
+
+ /* the various buttons */
+ test_buttons(fd_write, &info, &hw, &comm);
+}
+
int main (int argc, char **argv)
{
+ create_pipe_fd();
+
+ test_read_hw_state();
return 0;
}