test: add framework for a single-touch synaptics device
authorPeter Hutterer <peter.hutterer@who-t.net>
Mon, 24 Mar 2014 05:25:32 +0000 (15:25 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Tue, 25 Mar 2014 01:06:09 +0000 (11:06 +1000)
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
test/Makefile.am
test/litest-int.h
test/litest-synaptics-st.c [new file with mode: 0644]
test/litest.c
test/litest.h
test/touchpad.c

index 7bf02d1..b59d4a9 100644 (file)
@@ -12,6 +12,7 @@ liblitest_la_SOURCES = \
        litest-keyboard.c \
        litest-mouse.c \
        litest-synaptics.c \
+       litest-synaptics-st.c \
        litest-trackpoint.c \
        litest-wacom-touch.c \
        litest-generic-highres-touch.c \
index dd48d16..b515b6c 100644 (file)
@@ -41,6 +41,7 @@ struct litest_test_device {
 struct litest_device_interface {
        void (*touch_down)(struct litest_device *d, unsigned int slot, int x, int y);
        void (*touch_move)(struct litest_device *d, unsigned int slot, int x, int y);
+       void (*touch_up)(struct litest_device *d, unsigned int slot);
 
        int min[2];
        int max[2];
diff --git a/test/litest-synaptics-st.c b/test/litest-synaptics-st.c
new file mode 100644 (file)
index 0000000..2c7d371
--- /dev/null
@@ -0,0 +1,142 @@
+/*
+ * Copyright © 2013 Red Hat, Inc.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission.  The copyright holders make no representations
+ * about the suitability of this software for any purpose.  It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "litest.h"
+#include "litest-int.h"
+#include "libinput-util.h"
+
+void litest_synaptics_touchpad_setup(void)
+{
+       struct litest_device *d = litest_create_device(LITEST_SYNAPTICS_TOUCHPAD);
+       litest_set_current_device(d);
+}
+
+void
+litest_synaptics_touchpad_touch_down(struct litest_device *d,
+                                    unsigned int slot,
+                                    int x, int y)
+{
+       struct input_event *ev;
+       struct input_event down[] = {
+               { .type = EV_KEY, .code = BTN_TOUCH, .value = 1 },
+               { .type = EV_ABS, .code = ABS_X, .value = x  },
+               { .type = EV_ABS, .code = ABS_Y, .value = y },
+               { .type = EV_ABS, .code = ABS_PRESSURE, .value = 30  },
+               { .type = EV_ABS, .code = ABS_TOOL_WIDTH, .value = 7  },
+               { .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
+       };
+
+       down[1].value = litest_scale(d, ABS_X, x);
+       down[2].value = litest_scale(d, ABS_Y, y);
+
+       ARRAY_FOR_EACH(down, ev)
+               litest_event(d, ev->type, ev->code, ev->value);
+}
+
+void
+litest_synaptics_touchpad_move(struct litest_device *d,
+                              unsigned int slot,
+                              int x, int y)
+{
+       struct input_event *ev;
+       struct input_event move[] = {
+               { .type = EV_ABS, .code = ABS_X, .value = x  },
+               { .type = EV_ABS, .code = ABS_Y, .value = y },
+               { .type = EV_KEY, .code = BTN_TOUCH, .value = 1 },
+               { .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
+       };
+
+       move[0].value = litest_scale(d, ABS_X, x);
+       move[1].value = litest_scale(d, ABS_Y, y);
+
+       ARRAY_FOR_EACH(move, ev)
+               litest_event(d, ev->type, ev->code, ev->value);
+}
+
+void
+litest_synaptics_touchpad_up(struct litest_device *d, unsigned int slot)
+{
+       struct input_event *ev;
+       struct input_event up[] = {
+               { .type = EV_KEY, .code = BTN_TOUCH, .value = 0 },
+               { .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
+       };
+
+       ARRAY_FOR_EACH(up, ev)
+               litest_event(d, ev->type, ev->code, ev->value);
+}
+
+static struct litest_device_interface interface = {
+       .touch_down = litest_synaptics_touchpad_touch_down,
+       .touch_move = litest_synaptics_touchpad_move,
+       .touch_up = litest_synaptics_touchpad_up,
+};
+
+void
+litest_create_synaptics_touchpad(struct litest_device *d)
+{
+       struct libevdev *dev;
+       struct input_absinfo abs[] = {
+               { ABS_X, 1472, 5472, 75 },
+               { ABS_Y, 1408, 4448, 129 },
+               { ABS_PRESSURE, 0, 255, 0 },
+               { ABS_TOOL_WIDTH, 0, 15, 0 },
+       };
+       struct input_absinfo *a;
+       int rc;
+
+       d->interface = &interface;
+
+       dev = libevdev_new();
+       ck_assert(dev != NULL);
+
+       libevdev_set_name(dev, "SynPS/2 Synaptics TouchPad");
+       libevdev_set_id_bustype(dev, 0x11);
+       libevdev_set_id_vendor(dev, 0x2);
+       libevdev_set_id_product(dev, 0x7);
+       libevdev_enable_event_code(dev, EV_KEY, BTN_LEFT, NULL);
+       libevdev_enable_event_code(dev, EV_KEY, BTN_RIGHT, NULL);
+       libevdev_enable_event_code(dev, EV_KEY, BTN_TOOL_FINGER, NULL);
+       libevdev_enable_event_code(dev, EV_KEY, BTN_TOUCH, NULL);
+
+       ARRAY_FOR_EACH(abs, a)
+               libevdev_enable_event_code(dev, EV_ABS, a->value, a);
+
+       rc = libevdev_uinput_create_from_device(dev,
+                                               LIBEVDEV_UINPUT_OPEN_MANAGED,
+                                               &d->uinput);
+       ck_assert_int_eq(rc, 0);
+       libevdev_free(dev);
+}
+
+struct litest_test_device litest_synaptics_touchpad_device = {
+       .type = LITEST_SYNAPTICS_TOUCHPAD,
+       .features = LITEST_TOUCHPAD | LITEST_BUTTON | LITEST_SINGLE_TOUCH,
+       .shortname = "synaptics ST",
+       .setup = litest_synaptics_touchpad_setup,
+       .teardown = litest_generic_device_teardown,
+       .create = litest_create_synaptics_touchpad,
+};
index 78a0472..9241623 100644 (file)
@@ -77,6 +77,7 @@ void litest_generic_device_teardown(void)
 
 extern struct litest_test_device litest_keyboard_device;
 extern struct litest_test_device litest_synaptics_clickpad_device;
+extern struct litest_test_device litest_synaptics_touchpad_device;
 extern struct litest_test_device litest_trackpoint_device;
 extern struct litest_test_device litest_bcm5974_device;
 extern struct litest_test_device litest_mouse_device;
@@ -85,6 +86,7 @@ extern struct litest_test_device litest_generic_highres_touch_device;
 
 struct litest_test_device* devices[] = {
        &litest_synaptics_clickpad_device,
+       &litest_synaptics_touchpad_device,
        &litest_keyboard_device,
        &litest_trackpoint_device,
        &litest_bcm5974_device,
@@ -423,8 +425,12 @@ litest_touch_up(struct litest_device *d, unsigned int slot)
                { .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
        };
 
-       ARRAY_FOR_EACH(up, ev)
-               litest_event(d, ev->type, ev->code, ev->value);
+       if (d->interface->touch_up) {
+               d->interface->touch_up(d, slot);
+       } else {
+               ARRAY_FOR_EACH(up, ev)
+                       litest_event(d, ev->type, ev->code, ev->value);
+       }
 }
 
 void
index 9cc0ff5..9f0f614 100644 (file)
@@ -36,6 +36,7 @@
 enum litest_device_type {
        LITEST_NO_DEVICE = -1,
        LITEST_SYNAPTICS_CLICKPAD,
+       LITEST_SYNAPTICS_TOUCHPAD,
        LITEST_BCM5974,
        LITEST_KEYBOARD,
        LITEST_TRACKPOINT,
@@ -54,6 +55,7 @@ enum litest_device_feature {
        LITEST_POINTER = 1 << 4,
        LITEST_WHEEL = 1 << 5,
        LITEST_TOUCH = 1 << 6,
+       LITEST_SINGLE_TOUCH = 1 << 7,
 };
 
 struct litest_device {
index d32a296..f4d7839 100644 (file)
@@ -356,18 +356,18 @@ END_TEST
 int main(int argc, char **argv) {
 
        litest_add("touchpad:motion", touchpad_1fg_motion, LITEST_TOUCHPAD, LITEST_ANY);
-       litest_add("touchpad:motion", touchpad_2fg_no_motion, LITEST_TOUCHPAD, LITEST_ANY);
+       litest_add("touchpad:motion", touchpad_2fg_no_motion, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
 
        litest_add("touchpad:tap", touchpad_1fg_tap, LITEST_TOUCHPAD, LITEST_ANY);
        litest_add("touchpad:tap", touchpad_1fg_tap_n_drag, LITEST_TOUCHPAD, LITEST_ANY);
-       litest_add("touchpad:tap", touchpad_2fg_tap, LITEST_TOUCHPAD, LITEST_ANY);
+       litest_add("touchpad:tap", touchpad_2fg_tap, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
 
        litest_add("touchpad:clickfinger", touchpad_1fg_clickfinger, LITEST_TOUCHPAD, LITEST_ANY);
-       litest_add("touchpad:clickfinger", touchpad_2fg_clickfinger, LITEST_TOUCHPAD, LITEST_ANY);
+       litest_add("touchpad:clickfinger", touchpad_2fg_clickfinger, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
 
        litest_add("touchpad:click", touchpad_btn_left, LITEST_TOUCHPAD, LITEST_CLICKPAD);
        litest_add("touchpad:click", clickpad_btn_left, LITEST_CLICKPAD, LITEST_ANY);
-       litest_add("touchpad:click", clickpad_click_n_drag, LITEST_CLICKPAD, LITEST_ANY);
+       litest_add("touchpad:click", clickpad_click_n_drag, LITEST_CLICKPAD, LITEST_SINGLE_TOUCH);
 
        return litest_run(argc, argv);
 }