summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChase Douglas <chase.douglas@canonical.com>2012-02-10 10:24:04 -0800
committerChase Douglas <chase.douglas@canonical.com>2012-02-10 13:20:48 -0800
commite5cd694ed1028b94fdbe10d76dbea1e03455f8fb (patch)
tree9a8baaa1eb22561f6720de144328457b003e18c7
parentc34cf307f9982b62c6e6dfa2687e1b16f527f2a4 (diff)
Transition eventcomm-test to new SynapticsHwState instantiation scheme
Signed-off-by: Chase Douglas <chase.douglas@canonical.com> Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net> Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r--test/Makefile.am1
-rw-r--r--test/eventcomm-test.c106
2 files changed, 72 insertions, 35 deletions
diff --git a/test/Makefile.am b/test/Makefile.am
index 87de1ec..6fbbd23 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -8,6 +8,7 @@ noinst_PROGRAMS = eventcomm-test
eventcomm_test_SOURCES = eventcomm-test.c\
$(top_srcdir)/src/eventcomm.c \
+ $(top_srcdir)/src/synproto.c \
$(fake_syms)
eventcomm_test_LDADD = $(MTDEV_LIBS)
diff --git a/test/eventcomm-test.c b/test/eventcomm-test.c
index c9d8888..920d6ec 100644
--- a/test/eventcomm-test.c
+++ b/test/eventcomm-test.c
@@ -54,10 +54,12 @@ create_pipe_fd(void)
}
static void
-reset_data(struct SynapticsHwState *hw, struct CommData *comm)
+reset_data(struct SynapticsHwState **hw, struct CommData *comm,
+ SynapticsPrivate *priv)
{
memset(comm, 0, sizeof(struct CommData));
- memset(hw, 0, sizeof(struct SynapticsHwState));
+ SynapticsHwStateFree(hw);
+ *hw = SynapticsHwStateAlloc(priv);
}
/**
@@ -74,12 +76,13 @@ write_event(int fd, struct input_event *ev, int n)
static void
test_buttons(int fd,
InputInfoPtr pInfo,
- struct SynapticsHwState *hw,
struct CommData *comm)
{
+ SynapticsPrivate *priv = (SynapticsPrivate *)pInfo->private;
+ struct SynapticsHwState *hw = NULL;
struct input_event ev = {{0, 0}, EV_KEY, 0, 0};
- reset_data(hw, comm);
+ reset_data(&hw, comm, priv);
#define _test_press_release(_code, field) \
ev.code = (_code); \
@@ -105,6 +108,8 @@ test_buttons(int fd,
_test_press_release(BTN_5, multi[5]);
_test_press_release(BTN_6, multi[6]);
_test_press_release(BTN_7, multi[7]);
+
+ SynapticsHwStateFree(&hw);
}
/**
@@ -117,7 +122,7 @@ test_read_hw_state(void)
{
InputInfoRec info = {0};
SynapticsPrivate private;
- struct SynapticsHwState hw = {0};
+ struct SynapticsHwState *hw = NULL;
struct CommData comm = {0};
struct input_event ev[] = {
@@ -138,52 +143,79 @@ test_read_hw_state(void)
private.proto_data = EventProtoDataAlloc();
/* just the syn event */
- reset_data(&hw, &comm);
+ reset_data(&hw, &comm, &private);
write(fd_write, &syn, sizeof(syn));
- EventReadHwState(&info, &comm, &hw);
- assert(hw.numFingers == 0);
+ EventReadHwState(&info, &comm, hw);
+ assert(hw->numFingers == 0);
/* one finger */
- reset_data(&hw, &comm);
+ reset_data(&hw, &comm, &private);
write_event(fd_write, &ev[0], 1);
- EventReadHwState(&info, &comm, &hw);
- assert(hw.numFingers == 1);
+ EventReadHwState(&info, &comm, hw);
+ assert(hw->numFingers == 1);
/* two fingers */
- reset_data(&hw, &comm);
+ reset_data(&hw, &comm, &private);
write_event(fd_write, &ev[1], 1);
- EventReadHwState(&info, &comm, &hw);
- assert(hw.numFingers == 2);
+ EventReadHwState(&info, &comm, hw);
+ assert(hw->numFingers == 2);
/* three fingers */
- reset_data(&hw, &comm);
+ reset_data(&hw, &comm, &private);
write_event(fd_write, &ev[2], 1);
- EventReadHwState(&info, &comm, &hw);
- assert(hw.numFingers == 3);
+ EventReadHwState(&info, &comm, hw);
+ assert(hw->numFingers == 3);
/* x/y data */
- reset_data(&hw, &comm);
+ reset_data(&hw, &comm, &private);
write_event(fd_write, &ev[3], 2);
- EventReadHwState(&info, &comm, &hw);
- assert(hw.x == ev[3].value);
- assert(hw.y == ev[4].value);
+ EventReadHwState(&info, &comm, hw);
+ assert(hw->x == ev[3].value);
+ assert(hw->y == ev[4].value);
/* pressure */
- reset_data(&hw, &comm);
+ reset_data(&hw, &comm, &private);
write_event(fd_write, &ev[5], 1);
- EventReadHwState(&info, &comm, &hw);
- assert(hw.z == ev[5].value);
+ EventReadHwState(&info, &comm, hw);
+ assert(hw->z == ev[5].value);
/* finger width */
- reset_data(&hw, &comm);
+ reset_data(&hw, &comm, &private);
write_event(fd_write, &ev[6], 1);
- EventReadHwState(&info, &comm, &hw);
- assert(hw.fingerWidth == ev[6].value);
+ EventReadHwState(&info, &comm, hw);
+ assert(hw->fingerWidth == ev[6].value);
/* the various buttons */
- test_buttons(fd_write, &info, &hw, &comm);
+ test_buttons(fd_write, &info, &comm);
free(private.proto_data);
+ SynapticsHwStateFree(&hw);
+}
+
+static Bool
+compare_hw_state(const struct SynapticsHwState *a,
+ const struct SynapticsHwState *b)
+{
+ #define COMPARE(x) \
+ if (a->x != b->x) return a->x - b->x
+
+ COMPARE(millis);
+ COMPARE(x);
+ COMPARE(y);
+ COMPARE(z);
+ COMPARE(numFingers);
+ COMPARE(fingerWidth);
+ COMPARE(left);
+ COMPARE(right);
+ COMPARE(up);
+ COMPARE(down);
+ if (memcmp(a->multi, b->multi, sizeof(a->multi)))
+ return memcmp(a->multi, b->multi, sizeof(a->multi));
+ COMPARE(middle);
+
+ #undef COMPARE
+
+ return 0;
}
/**
@@ -194,11 +226,11 @@ static void
test_ignore_hw_state(void)
{
int i;
- InputInfoRec info = {0};
+ InputInfoRec info = {0};
SynapticsPrivate private;
- struct SynapticsHwState hw = {0};
- struct SynapticsHwState hw_zero = {0};
- struct CommData comm = {0};
+ struct SynapticsHwState *hw = NULL;
+ struct SynapticsHwState *hw_zero = NULL;
+ struct CommData comm = {0};
int known_abs[] = {
ABS_X,
@@ -235,14 +267,16 @@ test_ignore_hw_state(void)
private.proto_data = EventProtoDataAlloc();
+ reset_data(&hw_zero, &comm, &private);
+
#define _assert_no_change(_type, _code) \
- reset_data(&hw, &comm); \
+ reset_data(&hw, &comm, &private); \
ev.type = _type; \
ev.code = _code; \
ev.value = 1; \
write_event(fd_write, &ev, 1); \
- EventReadHwState(&info, &comm, &hw); \
- assert(memcmp(&hw, &hw_zero, sizeof(hw)) == 0);
+ EventReadHwState(&info, &comm, hw); \
+ assert(compare_hw_state(hw, hw_zero) == 0);
for (i = ABS_X; i < ABS_MAX; i++)
@@ -279,6 +313,8 @@ test_ignore_hw_state(void)
}
free(private.proto_data);
+ SynapticsHwStateFree(&hw);
+ SynapticsHwStateFree(&hw_zero);
}
int main (int argc, char **argv)