[PATCH 08/10] test/integration: add behaviour tests for AutoAddDevices off

Peter Hutterer peter.hutterer at who-t.net
Mon Jul 2 23:59:25 PDT 2012


Check if the default mouse/keyboard sections are added if AutoAddDevices is
disabled.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 test/integration/Makefile.am               |    5 +-
 test/integration/xorg-conf-input-tests.cpp |  111 ++++++++++++++++++++++++++++
 2 files changed, 115 insertions(+), 1 deletion(-)
 create mode 100644 test/integration/xorg-conf-input-tests.cpp

diff --git a/test/integration/Makefile.am b/test/integration/Makefile.am
index eefcbe5..b646e54 100644
--- a/test/integration/Makefile.am
+++ b/test/integration/Makefile.am
@@ -5,7 +5,7 @@ include $(top_srcdir)/test/integration/Makefile-xorg-gtest.am
 noinst_LIBRARIES = $(XORG_GTEST_BUILD_LIBS)
 
 if ENABLE_XORG_GTEST_INPUT_TESTS
-integration_tests += xi2-gtest input-driver-gtest
+integration_tests += xi2-gtest input-driver-gtest xorg-conf-input-gtest
 endif
 endif
 
@@ -34,3 +34,6 @@ xi2_gtest_LDADD = $(GTEST_LDADDS)
 
 input_driver_gtest_SOURCES = input_drivers.cpp
 input_driver_gtest_LDADD = $(GTEST_LDADDS)
+
+xorg_conf_input_gtest_SOURCES = xorg-conf-input-tests.cpp
+xorg_conf_input_gtest_LDADD = $(GTEST_LDADDS)
diff --git a/test/integration/xorg-conf-input-tests.cpp b/test/integration/xorg-conf-input-tests.cpp
new file mode 100644
index 0000000..1a9871e
--- /dev/null
+++ b/test/integration/xorg-conf-input-tests.cpp
@@ -0,0 +1,111 @@
+#include <stdexcept>
+#include <fstream>
+
+#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 XOrgConfigInputTest : public xorg::testing::Test {
+protected:
+    void WriteConfig(const char *param) {
+        std::stringstream s;
+        s << "/tmp/" << param << ".conf";
+        config_file = s.str();
+
+        std::ofstream conffile(config_file.c_str());
+        conffile.exceptions(std::ofstream::failbit | std::ofstream::badbit);
+
+        std::string driver(param);
+
+        conffile << ""
+"            Section \"ServerLayout\""
+"                Identifier \"Dummy layout\""
+"                Screen 0 \"Dummy screen\" 0 0"
+"                Option \"AutoAddDevices\" \"off\""
+"            EndSection"
+""
+"            Section \"Screen\""
+"                Identifier \"Dummy screen\""
+"                Device \"Dummy video device\""
+"            EndSection"
+""
+"            Section \"Device\""
+"                Identifier \"Dummy video device\""
+"                Driver \"dummy\""
+"            EndSection";
+        server.SetOption("-config", config_file);
+    }
+
+    void StartServer() {
+        server.Start();
+        server.WaitForConnections();
+        xorg::testing::Test::SetDisplayString(server.GetDisplayString());
+
+        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));
+    }
+
+    virtual void SetUp()
+    {
+        WriteConfig("default-input-drivers");
+        StartServer();
+    }
+
+    virtual void TearDown()
+    {
+        if (server.Pid() != -1)
+            if (!server.Terminate())
+                server.Kill();
+
+        if (config_file.size())
+            unlink(config_file.c_str());
+    }
+
+    int xi2_opcode_;
+    std::string config_file;
+    xorg::testing::XServer server;
+};
+
+/**
+ * Test the behaviour of the server if AutoAddDevices if off and no input
+ * devices are present - server should create default core devices.
+ */
+TEST_F(XOrgConfigInputTest, DefaultDevices)
+{
+    const char *param;
+    int ndevices;
+    XIDeviceInfo *info;
+
+    info = XIQueryDevice(Display(), XIAllDevices, &ndevices);
+    /* VCP, VCK, 2 test devices, forced mouse/keyboard */
+    ASSERT_EQ(ndevices, 6) << "This test may fail if you do not have "
+        "the mouse/keyboard drivers installed";
+
+    bool ptr_found = false, kbd_found = false;
+    while(ndevices-- && (!ptr_found || !kbd_found)) {
+        if (strcmp(info[ndevices].name, "<default pointer>") == 0)
+            ptr_found = true;
+        else if (strcmp(info[ndevices].name, "<default keyboard>") == 0)
+            kbd_found = true;
+    }
+
+    ASSERT_EQ(ptr_found, true);
+    ASSERT_EQ(kbd_found, true);
+
+    XIFreeDeviceInfo(info);
+}
-- 
1.7.10.4



More information about the xorg-devel mailing list