test: Add a basic mouse test device
authorPeter Hutterer <peter.hutterer@who-t.net>
Tue, 21 Jan 2014 05:18:09 +0000 (15:18 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Wed, 22 Jan 2014 01:23:00 +0000 (11:23 +1000)
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
test/Makefile.am
test/litest-mouse.c [new file with mode: 0644]
test/litest.c
test/litest.h

index 75b1412..82f5e53 100644 (file)
@@ -10,6 +10,7 @@ liblitest_la_SOURCES = \
        litest-int.h \
        litest-bcm5974.c \
        litest-keyboard.c \
+       litest-mouse.c \
        litest-synaptics.c \
        litest-trackpoint.c \
        litest.c
diff --git a/test/litest-mouse.c b/test/litest-mouse.c
new file mode 100644 (file)
index 0000000..2fde095
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * 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"
+
+static void litest_mouse_setup(void)
+{
+       struct litest_device *d = litest_create_device(LITEST_MOUSE);
+       litest_set_current_device(d);
+}
+
+static struct litest_device_interface interface = {
+};
+
+static void
+litest_create_mouse(struct litest_device *d)
+{
+       struct libevdev *dev;
+       int rc;
+
+       d->interface = &interface;
+       dev = libevdev_new();
+       ck_assert(dev != NULL);
+
+       libevdev_set_name(dev, "Lenovo Optical USB Mouse");
+       libevdev_set_id_bustype(dev, 0x3);
+       libevdev_set_id_vendor(dev, 0x17ef);
+       libevdev_set_id_product(dev, 0x6019);
+       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_MIDDLE, NULL);
+       libevdev_enable_event_code(dev, EV_REL, REL_X, NULL);
+       libevdev_enable_event_code(dev, EV_REL, REL_Y, NULL);
+       libevdev_enable_event_code(dev, EV_REL, REL_WHEEL, NULL);
+
+       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_mouse_device = {
+       .type = LITEST_MOUSE,
+       .features = LITEST_POINTER | LITEST_BUTTON | LITEST_WHEEL,
+       .shortname = "mouse",
+       .setup = litest_mouse_setup,
+       .teardown = litest_generic_device_teardown,
+       .create = litest_create_mouse,
+};
index 79d19a2..efab26c 100644 (file)
@@ -79,12 +79,14 @@ extern struct litest_test_device litest_keyboard_device;
 extern struct litest_test_device litest_synaptics_clickpad_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;
 
 struct litest_test_device* devices[] = {
        &litest_synaptics_clickpad_device,
        &litest_keyboard_device,
        &litest_trackpoint_device,
        &litest_bcm5974_device,
+       &litest_mouse_device,
        NULL,
 };
 
index 7de2d39..5dbc0da 100644 (file)
@@ -39,6 +39,7 @@ enum litest_device_type {
        LITEST_BCM5974,
        LITEST_KEYBOARD,
        LITEST_TRACKPOINT,
+       LITEST_MOUSE,
 };
 
 enum litest_device_feature {
@@ -49,6 +50,7 @@ enum litest_device_feature {
        LITEST_BUTTON = 1 << 2,
        LITEST_KEYS = 1 << 3,
        LITEST_POINTER = 1 << 4,
+       LITEST_WHEEL = 1 << 5,
 };
 
 struct litest_device {