[PATCH v5 4/5] Add test for touch end on device disable

Chase Douglas chase.douglas at canonical.com
Fri May 25 09:06:11 PDT 2012


When a device is disabled, all physically active touches must end.

Signed-off-by: Chase Douglas <chase.douglas at canonical.com>
Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
---
Changes since v4:
* Allocate XI event mask using mask length
* Skip test if evemu device creation fails

 test/integration/xi2.cpp |   78 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 78 insertions(+)

diff --git a/test/integration/xi2.cpp b/test/integration/xi2.cpp
index 896d34a..2429339 100644
--- a/test/integration/xi2.cpp
+++ b/test/integration/xi2.cpp
@@ -2,6 +2,7 @@
 
 #include <xorg/gtest/xorg-gtest.h>
 
+#include <X11/extensions/XInput.h>
 #include <X11/extensions/XInput2.h>
 
 namespace {
@@ -274,4 +275,81 @@ TEST_P(XInput2Test, XIQueryPointerTouchscreen)
     XFreeEventData(Display(), xcookie);
 }
 
+/**
+ * When a device is disabled, any physically active touches should end.
+ */
+TEST_P(XInput2Test, DisableDeviceEndTouches)
+{
+    /* This is an XInput 2.2 and later test only */
+    if (GetParam() < 2)
+        return;
+
+    XIEventMask mask;
+    mask.deviceid = XIAllDevices;
+    mask.mask_len = XIMaskLen(XI_TouchEnd);
+    mask.mask = reinterpret_cast<unsigned char*>(calloc(mask.mask_len, 1));
+    XISetMask(mask.mask, XI_HierarchyChanged);
+
+    ASSERT_EQ(Success,
+              XISelectEvents(Display(), DefaultRootWindow(Display()), &mask,
+                             1));
+
+    mask.deviceid = XIAllMasterDevices;
+    XIClearMask(mask.mask, XI_HierarchyChanged);
+    XISetMask(mask.mask, XI_TouchBegin);
+    XISetMask(mask.mask, XI_TouchUpdate);
+    XISetMask(mask.mask, XI_TouchEnd);
+
+    ASSERT_EQ(Success,
+              XISelectEvents(Display(), DefaultRootWindow(Display()), &mask,
+                             1));
+
+    free(mask.mask);
+
+    XFlush(Display());
+
+    std::auto_ptr<xorg::testing::evemu::Device> device;
+    try {
+      device = std::auto_ptr<xorg::testing::evemu::Device>(
+          new xorg::testing::evemu::Device(
+              TEST_ROOT_DIR "recordings/ntrig_dell_xt2/device.prop"));
+    } catch (std::runtime_error &error) {
+      std::cerr << "Failed to create evemu device, skipping test.\n";
+      return;
+    }
+
+    ASSERT_TRUE(WaitForDevice(Display(),
+                              "N-Trig MultiTouch (Virtual Test Device)"));
+
+    device->Play(
+        TEST_ROOT_DIR "recordings/ntrig_dell_xt2/touch_1_begin.record");
+
+    ASSERT_TRUE(WaitForEventOfType(Display(), GenericEvent, xi2_opcode_,
+                                   XI_TouchBegin));
+
+    XEvent event;
+    ASSERT_EQ(Success, XNextEvent(Display(), &event));
+
+    XGenericEventCookie *xcookie = &event.xcookie;
+    ASSERT_TRUE(XGetEventData(Display(), xcookie));
+
+    XIDeviceEvent *device_event =
+        reinterpret_cast<XIDeviceEvent*>(xcookie->data);
+
+    XDevice *xdevice = XOpenDevice(Display(), device_event->sourceid);
+    XFreeEventData(Display(), xcookie);
+    ASSERT_TRUE(xdevice != NULL);
+
+    XDeviceEnableControl enable_control;
+    enable_control.enable = false;
+    XDeviceControl *control = reinterpret_cast<XDeviceControl*>(&control);
+    ASSERT_TRUE(XChangeDeviceControl(Display(), xdevice, DEVICE_ENABLE,
+                                     control));
+    XCloseDevice(Display(), xdevice);
+    XFlush(Display());
+
+    ASSERT_TRUE(WaitForEventOfType(Display(), GenericEvent, xi2_opcode_,
+                                   XI_TouchEnd));
+}
+
 INSTANTIATE_TEST_CASE_P(, XInput2Test, ::testing::Range(0, 3));
-- 
1.7.9.5



More information about the xorg-devel mailing list