test: add test for extracting the right slot values on startup
authorPeter Hutterer <peter.hutterer@who-t.net>
Wed, 3 Jul 2013 04:51:02 +0000 (14:51 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Wed, 3 Jul 2013 05:53:50 +0000 (15:53 +1000)
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
test/test-libevdev-has-event.c

index fe0b6f38de3056ba6cf9b2df88bba01a4c8e753f..0a20a6fd03e7b57e0cc3b42f5a69f7ebb2d9bee2 100644 (file)
@@ -25,6 +25,7 @@
 #include <errno.h>
 #include <unistd.h>
 #include <limits.h>
+#include <fcntl.h>
 
 #include "test-common.h"
 
@@ -228,6 +229,84 @@ START_TEST(test_input_props)
 }
 END_TEST
 
+START_TEST(test_slot_init_value)
+{
+       struct uinput_device *uidev;
+       struct libevdev *dev;
+       int rc;
+       const int nabs = 6;
+       struct input_absinfo abs[nabs];
+       int i;
+       int fd;
+
+       uidev = uinput_device_new("test device");
+       rc = uinput_device_set_event_bits(uidev,
+                       EV_ABS, ABS_X,
+                       EV_ABS, ABS_Y,
+                       EV_ABS, ABS_MT_SLOT,
+                       EV_ABS, ABS_MT_TRACKING_ID,
+                       EV_ABS, ABS_MT_POSITION_X,
+                       EV_ABS, ABS_MT_POSITION_Y,
+                       -1);
+       ck_assert_int_eq(rc, 0);
+
+       memset(abs, 0, sizeof(abs));
+       abs[0].value = ABS_X;
+       abs[0].maximum = 1000;
+       abs[1].value = ABS_MT_POSITION_X;
+       abs[1].maximum = 1000;
+
+       abs[2].value = ABS_Y;
+       abs[2].maximum = 1000;
+       abs[3].value = ABS_MT_POSITION_Y;
+       abs[3].maximum = 1000;
+
+       abs[4].value = ABS_MT_SLOT;
+       abs[4].maximum = 1;
+       abs[5].value = ABS_MT_TRACKING_ID;
+       abs[5].minimum = -1;
+       abs[5].maximum = 2;
+
+       for (i = 0; i < nabs; i++) {
+               rc = uinput_device_set_abs_bit(uidev, abs[i].value, &abs[i]);
+               ck_assert_int_eq(rc, 0);
+       }
+
+       rc = uinput_device_create(uidev);
+       ck_assert_msg(rc == 0, "Failed to create uinput device: %s", strerror(-rc));
+
+       fd = uinput_device_get_fd(uidev);
+       rc = fcntl(fd, F_SETFL, O_NONBLOCK);
+       ck_assert_msg(rc == 0, "fcntl failed: %s", strerror(errno));
+
+       uinput_device_event(uidev, EV_ABS, ABS_MT_SLOT, 0);
+       uinput_device_event(uidev, EV_ABS, ABS_X, 100);
+       uinput_device_event(uidev, EV_ABS, ABS_Y, 500);
+       uinput_device_event(uidev, EV_ABS, ABS_MT_POSITION_X, 100);
+       uinput_device_event(uidev, EV_ABS, ABS_MT_POSITION_Y, 500);
+       uinput_device_event(uidev, EV_ABS, ABS_MT_TRACKING_ID, 1);
+       uinput_device_event(uidev, EV_ABS, ABS_MT_SLOT, 1);
+       uinput_device_event(uidev, EV_ABS, ABS_X, 1);
+       uinput_device_event(uidev, EV_ABS, ABS_Y, 5);
+       uinput_device_event(uidev, EV_ABS, ABS_MT_POSITION_X, 1);
+       uinput_device_event(uidev, EV_ABS, ABS_MT_POSITION_Y, 5);
+       uinput_device_event(uidev, EV_ABS, ABS_MT_TRACKING_ID, 2);
+       uinput_device_event(uidev, EV_SYN, SYN_REPORT, 0);
+
+       rc = libevdev_new_from_fd(fd, &dev);
+       ck_assert_int_eq(rc, 0);
+
+       ck_assert_int_eq(libevdev_get_current_slot(dev), 1);
+       ck_assert_int_eq(libevdev_get_slot_value(dev, 0, ABS_MT_POSITION_X), 100);
+       ck_assert_int_eq(libevdev_get_slot_value(dev, 0, ABS_MT_POSITION_Y), 500);
+       ck_assert_int_eq(libevdev_get_slot_value(dev, 1, ABS_MT_POSITION_X), 1);
+       ck_assert_int_eq(libevdev_get_slot_value(dev, 1, ABS_MT_POSITION_Y), 5);
+
+       uinput_device_free(uidev);
+       libevdev_free(dev);
+}
+END_TEST
+
 START_TEST(test_no_slots)
 {
        struct uinput_device* uidev;
@@ -686,6 +765,7 @@ libevdev_has_event_test(void)
        tc = tcase_create("multitouch info");
        tcase_add_test(tc, test_no_slots);
        tcase_add_test(tc, test_slot_number);
+       tcase_add_test(tc, test_slot_init_value);
        suite_add_tcase(s, tc);
 
        tc = tcase_create("device info");