diff options
author | Daniel Drake <dsd@laptop.org> | 2012-10-01 16:46:28 -0400 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2012-10-02 12:02:16 +1000 |
commit | 57ef69d16a55915a0ec7f25d04e2f23da5deb586 (patch) | |
tree | 4645c49c676cbd3394c79506ae18587ab64d2b3d | |
parent | df64f6d3c263b734891e04ab9306ec78d5b4b1ca (diff) |
server/xi2: add touchscreen mouse pointer emulation test
Add a test case based on the bug fixed by
http://lists.x.org/archives/xorg-devel/2012-September/033595.html
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r-- | tests/server/xi2.cpp | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/tests/server/xi2.cpp b/tests/server/xi2.cpp index 1e2832b..13cb469 100644 --- a/tests/server/xi2.cpp +++ b/tests/server/xi2.cpp @@ -33,6 +33,137 @@ protected: } }; +TEST_P(XInput2Test, XITouchscreenPointerEmulation) +{ + SCOPED_TRACE("\n" + "When an initial touch is made, any movement of the pointer\n" + "should be raised as if button 1 is being held. After the\n" + "touch is released, further movement should have button 1\n" + "released.\n"); + + XIEventMask mask; + mask.deviceid = XIAllDevices; + mask.mask_len = XIMaskLen(XI_HierarchyChanged); + 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_ButtonPress); + XISetMask(mask.mask, XI_ButtonRelease); + XISetMask(mask.mask, XI_Motion); + + ASSERT_EQ(Success, + XISelectEvents(Display(), DefaultRootWindow(Display()), &mask, + 1)); + + free(mask.mask); + + XFlush(Display()); + + std::auto_ptr<xorg::testing::evemu::Device> touch_device; + try { + touch_device = std::auto_ptr<xorg::testing::evemu::Device>( + new xorg::testing::evemu::Device( + RECORDINGS_DIR "tablets/N-Trig-MultiTouch.desc") + ); + } catch (std::runtime_error &error) { + std::cerr << "Failed to create evemu device, skipping test.\n"; + return; + } + + ASSERT_TRUE(xorg::testing::XServer::WaitForDevice(Display(), "N-Trig MultiTouch")); + + std::auto_ptr<xorg::testing::evemu::Device> mouse_device; + try { + mouse_device = std::auto_ptr<xorg::testing::evemu::Device>( + new xorg::testing::evemu::Device( + RECORDINGS_DIR "mice/PIXART-USB-OPTICAL-MOUSE.desc") + ); + } catch (std::runtime_error &error) { + std::cerr << "Failed to create evemu device, skipping test.\n"; + return; + } + + ASSERT_TRUE(xorg::testing::XServer::WaitForDevice(Display(), "PIXART USB OPTICAL MOUSE")); + + XEvent event; + XGenericEventCookie *xcookie; + XIDeviceEvent *device_event; + + + /* Move the mouse, check that the button is not pressed. */ + mouse_device->PlayOne(EV_REL, ABS_X, -1, 1); + ASSERT_TRUE(xorg::testing::XServer::WaitForEventOfType(Display(), + GenericEvent, + xi2_opcode, + XI_Motion)); + + ASSERT_EQ(Success, XNextEvent(Display(), &event)); + xcookie = &event.xcookie; + ASSERT_TRUE(XGetEventData(Display(), xcookie)); + + device_event = reinterpret_cast<XIDeviceEvent*>(xcookie->data); + ASSERT_FALSE(XIMaskIsSet(device_event->buttons.mask, 1)); + XFreeEventData(Display(), xcookie); + + + /* Touch the screen, wait for press event */ + touch_device->Play(RECORDINGS_DIR "tablets/N-Trig-MultiTouch.touch_1_begin.events"); + ASSERT_TRUE(xorg::testing::XServer::WaitForEventOfType(Display(), + GenericEvent, + xi2_opcode, + XI_ButtonPress)); + + ASSERT_EQ(Success, XNextEvent(Display(), &event)); + + + /* Move the mouse again, button 1 should now be pressed. */ + mouse_device->PlayOne(EV_REL, ABS_X, -1, 1); + ASSERT_TRUE(xorg::testing::XServer::WaitForEventOfType(Display(), + GenericEvent, + xi2_opcode, + XI_Motion)); + + ASSERT_EQ(Success, XNextEvent(Display(), &event)); + xcookie = &event.xcookie; + ASSERT_TRUE(XGetEventData(Display(), xcookie)); + + device_event = reinterpret_cast<XIDeviceEvent*>(xcookie->data); + ASSERT_TRUE(XIMaskIsSet(device_event->buttons.mask, 1)); + XFreeEventData(Display(), xcookie); + + + /* Release the screen, wait for release event */ + touch_device->Play(RECORDINGS_DIR "tablets/N-Trig-MultiTouch.touch_1_end.events"); + ASSERT_TRUE(xorg::testing::XServer::WaitForEventOfType(Display(), + GenericEvent, + xi2_opcode, + XI_ButtonRelease)); + + ASSERT_EQ(Success, XNextEvent(Display(), &event)); + + + /* Move the mouse again, button 1 should now be released. */ + mouse_device->PlayOne(EV_REL, ABS_X, -1, 1); + ASSERT_TRUE(xorg::testing::XServer::WaitForEventOfType(Display(), + GenericEvent, + xi2_opcode, + XI_Motion)); + + ASSERT_EQ(Success, XNextEvent(Display(), &event)); + xcookie = &event.xcookie; + ASSERT_TRUE(XGetEventData(Display(), xcookie)); + + device_event = reinterpret_cast<XIDeviceEvent*>(xcookie->data); + ASSERT_FALSE(XIMaskIsSet(device_event->buttons.mask, 1)); + XFreeEventData(Display(), xcookie); +} + TEST_P(XInput2Test, XIQueryPointerTouchscreen) { SCOPED_TRACE("\n" |