[PATCH 03/10] test/integration: add basic checks for default core/xtest devices
Peter Hutterer
peter.hutterer at who-t.net
Mon Jul 2 23:59:20 PDT 2012
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
test/integration/Makefile.am | 2 +-
test/integration/input_drivers.cpp | 128 ++++++++++++++++++++++++++++++++++++
2 files changed, 129 insertions(+), 1 deletion(-)
create mode 100644 test/integration/input_drivers.cpp
diff --git a/test/integration/Makefile.am b/test/integration/Makefile.am
index 6109e23..4b02463 100644
--- a/test/integration/Makefile.am
+++ b/test/integration/Makefile.am
@@ -22,7 +22,7 @@ AM_CPPFLAGS = \
AM_CXXFLAGS = $(GTEST_CXXFLAGS) $(XORG_GTEST_CXXFLAGS)
-gtest_tests_SOURCES = xi2.cpp
+gtest_tests_SOURCES = xi2.cpp input_drivers.cpp
gtest_tests_LDADD = \
$(TEST_XINPUT_LIBS) \
$(TEST_X11_LIBS) \
diff --git a/test/integration/input_drivers.cpp b/test/integration/input_drivers.cpp
new file mode 100644
index 0000000..5b3060b
--- /dev/null
+++ b/test/integration/input_drivers.cpp
@@ -0,0 +1,128 @@
+#include <stdexcept>
+
+#include <xorg/gtest/xorg-gtest.h>
+
+#include <X11/extensions/XInput.h>
+#include <X11/extensions/XInput2.h>
+
+/**
+ * A test fixture for testing some input drivers
+ *
+ */
+class InputDriverTest : public xorg::testing::Test {
+protected:
+ virtual void SetUp()
+ {
+ ASSERT_NO_FATAL_FAILURE(xorg::testing::Test::SetUp());
+
+ int event_start;
+ int error_start;
+
+ ASSERT_TRUE(XQueryExtension(Display(), "XInputExtension", &xi2_opcode_,
+ &event_start, &error_start));
+
+ int major = 2;
+ int minor = 0;
+
+ ASSERT_EQ(Success, XIQueryVersion(Display(), &major, &minor));
+ }
+
+ int xi2_opcode_;
+};
+
+/* check default master devices */
+TEST_F(InputDriverTest, CoreDevices)
+{
+ int ndevices;
+ XIDeviceInfo *info;
+
+ info = XIQueryDevice(Display(), XIAllMasterDevices, &ndevices);
+ ASSERT_EQ(ndevices, 2);
+ ASSERT_EQ(strcmp(info[0].name, "Virtual core pointer"), 0);
+ ASSERT_EQ(info[0].deviceid, 2);
+ ASSERT_EQ(strcmp(info[1].name, "Virtual core keyboard"), 0);
+ ASSERT_EQ(info[1].deviceid, 3);
+
+ XIFreeDeviceInfo(info);
+}
+
+TEST_F(InputDriverTest, XTestDevices)
+{
+ int ndevices;
+ XIDeviceInfo *info;
+
+ info = XIQueryDevice(Display(), XIAllDevices, &ndevices);
+ ASSERT_GT(ndevices, 4);
+ ASSERT_EQ(strcmp(info[2].name, "Virtual core XTEST pointer"), 0);
+ ASSERT_EQ(info[2].deviceid, 4);
+ ASSERT_EQ(strcmp(info[3].name, "Virtual core XTEST keyboard"), 0);
+ ASSERT_EQ(info[3].deviceid, 5);
+
+ XIFreeDeviceInfo(info);
+}
+
+TEST_F(InputDriverTest, NewMaster)
+{
+ int ndevices;
+ XIDeviceInfo *info;
+
+ info = XIQueryDevice(Display(), XIAllMasterDevices, &ndevices);
+ XIFreeDeviceInfo(info);
+
+ ASSERT_EQ(ndevices, 2);
+
+ /* add a new master */
+ XIAnyHierarchyChangeInfo *any;
+ XIAddMasterInfo add;
+ add.type = XIAddMaster;
+ add.name = strdup("test");
+ add.send_core = 1;
+ add.enable = 1;
+
+ any = reinterpret_cast<XIAnyHierarchyChangeInfo*> (&add);
+ ASSERT_EQ(Success, XIChangeHierarchy(Display(), any, 1));
+ free(add.name);
+
+ int new_pointer_id;
+ info = XIQueryDevice(Display(), XIAllMasterDevices, &ndevices);
+ ASSERT_EQ(ndevices, 4);
+ ASSERT_EQ(strcmp(info[2].name, "test pointer"), 0);
+ ASSERT_EQ(strcmp(info[3].name, "test keyboard"), 0);
+ new_pointer_id = info[2].deviceid;
+ XIFreeDeviceInfo(info);
+
+ /* check for xtest devices */
+ bool xtest_ptr_found = false,
+ xtest_kbd_found = false;
+ info = XIQueryDevice(Display(), XIAllDevices, &ndevices);
+ while (ndevices-- && (!xtest_kbd_found || !xtest_ptr_found)) {
+ if (strcmp(info[ndevices].name, "test XTEST pointer") == 0)
+ xtest_ptr_found = true;
+ else if (strcmp(info[ndevices].name, "test XTEST keyboard") == 0)
+ xtest_kbd_found = true;
+ }
+ ASSERT_TRUE(xtest_ptr_found);
+ ASSERT_TRUE(xtest_kbd_found);
+ XIFreeDeviceInfo(info);
+
+ /* remove master again */
+ XIRemoveMasterInfo remove;
+ remove.type = XIRemoveMaster;
+ remove.deviceid = new_pointer_id;
+ remove.return_mode = XIFloating;
+ any = reinterpret_cast<XIAnyHierarchyChangeInfo*> (&remove);
+ ASSERT_EQ(Success, XIChangeHierarchy(Display(), any, 1));
+
+ info = XIQueryDevice(Display(), XIAllMasterDevices, &ndevices);
+ ASSERT_EQ(ndevices, 2);
+ XIFreeDeviceInfo(info);
+
+ /* XTEST devices disappear with master */
+ info = XIQueryDevice(Display(), XIAllDevices, &ndevices);
+ while (ndevices--) {
+ ASSERT_NE(strcmp(info[ndevices].name, "test XTEST pointer"), 0);
+ ASSERT_NE(strcmp(info[ndevices].name, "test XTEST keyboard"), 0);
+ }
+ XIFreeDeviceInfo(info);
+}
+
--
1.7.10.4
More information about the xorg-devel
mailing list