summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2012-10-26 13:15:36 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2012-10-26 15:06:08 +1000
commite1e63462ecf4f215cd108507bbcab67516f55c51 (patch)
tree2a93925be77c8395130fa7b2b77491b0bacad125
parentae10e42fd4d43ba778a708788a68988daaf68877 (diff)
common: move shared parts out of InputDriverTest to new XITServerTest class
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r--tests/common/Makefile.am5
-rw-r--r--tests/common/input-driver-test.cpp68
-rw-r--r--tests/common/input-driver-test.h59
-rw-r--r--tests/common/xit-server-test.cpp79
-rw-r--r--tests/common/xit-server-test.h88
5 files changed, 182 insertions, 117 deletions
diff --git a/tests/common/Makefile.am b/tests/common/Makefile.am
index b258f8a..cabf378 100644
--- a/tests/common/Makefile.am
+++ b/tests/common/Makefile.am
@@ -22,7 +22,10 @@ GTEST_LDADDS = \
$(EVEMU_LIBS) \
$(XORG_GTEST_MAIN_LIBS)
-common_sources = $(top_srcdir)/tests/common/input-driver-test.cpp \
+common_sources = \
+ $(top_srcdir)/tests/common/xit-server-test.cpp \
+ $(top_srcdir)/tests/common/xit-server-test.h \
+ $(top_srcdir)/tests/common/input-driver-test.cpp \
$(top_srcdir)/tests/common/input-driver-test.h \
$(top_srcdir)/tests/common/xorg-conf.cpp \
$(top_srcdir)/tests/common/xorg-conf.h \
diff --git a/tests/common/input-driver-test.cpp b/tests/common/input-driver-test.cpp
index 7e16cc4..6d4d6a7 100644
--- a/tests/common/input-driver-test.cpp
+++ b/tests/common/input-driver-test.cpp
@@ -2,7 +2,6 @@
#include <config.h>
#endif
#include <stdexcept>
-#include <fstream>
#include <xorg/gtest/xorg-gtest.h>
#include <X11/extensions/XInput.h>
@@ -11,13 +10,6 @@
#include "input-driver-test.h"
#include "helpers.h"
-#define TEST_TIMEOUT 60
-
-static void sighandler_alarm(int signal)
-{
- FAIL() << "Test has timed out (" << __func__ << "). Adjust TEST_TIMEOUT (" << TEST_TIMEOUT << "s) if needed.";
-}
-
int InputDriverTest::RegisterXI2(int major, int minor)
{
int event_start;
@@ -38,16 +30,7 @@ int InputDriverTest::RegisterXI2(int major, int minor)
}
void InputDriverTest::StartServer() {
- /* No test takes longer than 60 seconds */
- alarm(60);
- signal(SIGALRM, sighandler_alarm);
-
- server.SetOption("-noreset", "");
- server.Start();
- xorg::testing::Test::SetDisplayString(server.GetDisplayString());
-
- ASSERT_NO_FATAL_FAILURE(xorg::testing::Test::SetUp());
-
+ XITServerTest::StartServer();
RegisterXI2();
}
@@ -60,58 +43,11 @@ void InputDriverTest::SetUpConfigAndLog(const std::string& param) {
server.SetOption("-config", config.GetPath());
}
-void InputDriverTest::SetUpEventListener() {
- failed = false;
-
- testing::TestEventListeners &listeners = ::testing::UnitTest::GetInstance()->listeners();
- listeners.Append(this);
-}
-
void InputDriverTest::SetUp() {
SetUp("");
}
void InputDriverTest::SetUp(const std::string &param) {
- SetUpEventListener();
SetUpConfigAndLog(param);
- StartServer();
-}
-
-void InputDriverTest::TearDown() {
- alarm(0);
- if (server.Pid() != -1) {
- if (!server.Terminate(3000))
- server.Kill(3000);
- EXPECT_EQ(server.GetState(), xorg::testing::Process::FINISHED_SUCCESS) << "Unclean server shutdown";
- failed = failed || (server.GetState() != xorg::testing::Process::FINISHED_SUCCESS);
-
- std::ifstream logfile(server.GetLogFilePath().c_str());
- std::string line;
- std::string bug_warn("BUG");
- if (logfile.is_open()) {
- while(getline(logfile, line)) {
- size_t found = line.find(bug_warn);
- bool error = (found != std::string::npos);
- EXPECT_FALSE(error) << "BUG warning found in log" << std::endl << line << std::endl;
- failed = failed || error;
- break;
- }
- }
- }
-
- if (!Failed()) {
- config.RemoveConfig();
- server.RemoveLogFile();
- }
-
- testing::TestEventListeners &listeners = ::testing::UnitTest::GetInstance()->listeners();
- listeners.Release(this);
-}
-
-void InputDriverTest::OnTestPartResult(const ::testing::TestPartResult &test_part_result) {
- failed = failed || test_part_result.failed();
-}
-
-bool InputDriverTest::Failed() {
- return failed;
+ XITServerTest::SetUp();
}
diff --git a/tests/common/input-driver-test.h b/tests/common/input-driver-test.h
index 0fa9282..9f32b5d 100644
--- a/tests/common/input-driver-test.h
+++ b/tests/common/input-driver-test.h
@@ -5,7 +5,8 @@
#define _INPUT_DRIVER_TEST_H_
#include <xorg/gtest/xorg-gtest.h>
-#include "xorg-conf.h"
+
+#include "xit-server-test.h"
/**
* A test fixture for testing input drivers. This class automates basic
@@ -14,8 +15,7 @@
* Do not instanciate this class directly, subclass it from the test case
* instead. For simple test cases, use SimpleInputDriverTest.
*/
-class InputDriverTest : public xorg::testing::Test,
- private ::testing::EmptyTestEventListener {
+class InputDriverTest : public XITServerTest {
protected:
/**
* Set up the config and log file. The param is used for both the
@@ -30,13 +30,7 @@ protected:
*
* @param param The param used as prefix for the config file and the log file and as input driver.
*/
- virtual void SetUpConfigAndLog(const std::string& param = "");
-
- /**
- * Set up an event listener that listens for test results. If any result
- * fails, Failed() will return true.
- */
- void SetUpEventListener();
+ virtual void SetUpConfigAndLog(const std::string& param);
/**
* Register for the given XI2 extension. Default is 2.0, will ASSERT if
@@ -47,19 +41,17 @@ protected:
virtual int RegisterXI2(int major = 2, int minor = 0);
/**
- * Starts the server and waits for connections. Once completed,
- * xorg::testing::Test::Display() will be set to the server's display
- * and that display will have registered for XI2.
- */
- virtual void StartServer();
-
- /**
* Default googletest entry point for setup-work during test fixtures.
* This implementation simply calls SetUp() with an empty string.
*/
virtual void SetUp();
/**
+ * Starts the server and registers for XI2.
+ */
+ virtual void StartServer();
+
+ /**
* Sets up an event listener to watch for test failures and calls
* SetUpConfigAndLog() for initalisation of the server config. Finally,
* starts the server.
@@ -70,42 +62,9 @@ protected:
virtual void SetUp(const std::string &param);
/**
- * Default googletest entry point for clean-up work after test
- * fixtures were run.
- */
- virtual void TearDown();
-
- /**
- * @return false if all tests succeeded, true if one failed
- */
- virtual bool Failed();
-
- /**
* Opcode for XI2 events
*/
int xi2_opcode;
-
- /**
- * The X server instance. This server is started with StartServer() but
- * may be started by child classes directly.
- */
- xorg::testing::XServer server;
-
- /**
- * The server configuration. SetUpConfigAndLog() by default works on
- * this configuration and the server started by StartServer() will then
- * use this configuration.
- */
- XOrgConfig config;
-
-private:
- bool failed;
-
- /**
- * Callback for test results. If any test fails, ::Failed() will return
- * false.
- */
- void OnTestPartResult(const ::testing::TestPartResult &test_part_result);
};
/**
diff --git a/tests/common/xit-server-test.cpp b/tests/common/xit-server-test.cpp
new file mode 100644
index 0000000..52a4a2e
--- /dev/null
+++ b/tests/common/xit-server-test.cpp
@@ -0,0 +1,79 @@
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <fstream>
+
+#include "xit-server-test.h"
+
+#define TEST_TIMEOUT 60
+
+void XITServerTest::SetUpEventListener() {
+ failed = false;
+
+ testing::TestEventListeners &listeners = ::testing::UnitTest::GetInstance()->listeners();
+ listeners.Append(this);
+}
+
+void XITServerTest::SetUp() {
+ SetUpEventListener();
+ SetUpConfigAndLog();
+ StartServer();
+}
+
+void XITServerTest::TearDown() {
+ alarm(0);
+ if (server.Pid() != -1) {
+ if (!server.Terminate(3000))
+ server.Kill(3000);
+ EXPECT_EQ(server.GetState(), xorg::testing::Process::FINISHED_SUCCESS) << "Unclean server shutdown";
+ failed = failed || (server.GetState() != xorg::testing::Process::FINISHED_SUCCESS);
+
+ std::ifstream logfile(server.GetLogFilePath().c_str());
+ std::string line;
+ std::string bug_warn("BUG");
+ if (logfile.is_open()) {
+ while(getline(logfile, line)) {
+ size_t found = line.find(bug_warn);
+ bool error = (found != std::string::npos);
+ EXPECT_FALSE(error) << "BUG warning found in log" << std::endl << line << std::endl;
+ failed = failed || error;
+ break;
+ }
+ }
+ }
+
+ if (!Failed()) {
+ config.RemoveConfig();
+ server.RemoveLogFile();
+ }
+
+ testing::TestEventListeners &listeners = ::testing::UnitTest::GetInstance()->listeners();
+ listeners.Release(this);
+}
+
+static void sighandler_alarm(int signal)
+{
+ FAIL() << "Test has timed out (" << __func__ << "). Adjust TEST_TIMEOUT (" << TEST_TIMEOUT << "s) if needed.";
+}
+
+void XITServerTest::StartServer() {
+ /* No test takes longer than 60 seconds */
+ alarm(60);
+ signal(SIGALRM, sighandler_alarm);
+
+ server.SetOption("-noreset", "");
+ server.Start();
+ xorg::testing::Test::SetDisplayString(server.GetDisplayString());
+
+ ASSERT_NO_FATAL_FAILURE(xorg::testing::Test::SetUp());
+}
+
+bool XITServerTest::Failed() {
+ return failed;
+}
+
+void XITServerTest::OnTestPartResult(const ::testing::TestPartResult &test_part_result) {
+ failed = failed || test_part_result.failed();
+}
+
diff --git a/tests/common/xit-server-test.h b/tests/common/xit-server-test.h
new file mode 100644
index 0000000..a2e7c50
--- /dev/null
+++ b/tests/common/xit-server-test.h
@@ -0,0 +1,88 @@
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifndef _XIT_SERVER_TEST_H_
+#define _XIT_SERVER_TEST_H_
+
+#include <xorg/gtest/xorg-gtest.h>
+
+#include "xorg-conf.h"
+
+/**
+ * Root class for XIT that require an X server to be started.
+ *
+ * Handles log/config file creation, automatic path names for those files,
+ * etc.
+ */
+class XITServerTest : public xorg::testing::Test,
+ private ::testing::EmptyTestEventListener {
+protected:
+ /**
+ * Set up an event listener that listens for test results. If any result
+ * fails, Failed() will return true.
+ */
+ void SetUpEventListener();
+
+ /**
+ * Set up the config and log file. The param is used for both the
+ * config file ("param.conf") and the log file ("Xorg-param.log").
+ * The default behavior of this function is to set up an xorg.conf with
+ * a single input device, using the param as the driver name.
+ *
+ * This function is called from SetUp(), before the server is started.
+ * Tests that need a different configuration but the same general
+ * behavior can override SetUpConfigAndLog() only and leave the rest of
+ * the behaviour intact.
+ *
+ * @param param The param used as prefix for the config file and the log file and as input driver.
+ */
+ virtual void SetUpConfigAndLog(const std::string& param = "") = 0;
+
+ /**
+ * Default googletest entry point for setup-work during test fixtures.
+ * This implementation simply calls SetUp() with an empty string.
+ */
+ virtual void SetUp();
+
+ /**
+ * Default googletest entry point for clean-up work after test
+ * fixtures were run.
+ */
+ virtual void TearDown();
+
+ /**
+ * Starts the server and waits for connections. Once completed,
+ * xorg::testing::Test::Display() will be set to the server's display.
+ */
+ virtual void StartServer();
+
+ /**
+ * @return false if all tests succeeded, true if one failed
+ */
+ virtual bool Failed();
+
+ /**
+ * The X server instance. This server is started with StartServer() but
+ * may be started by child classes directly.
+ */
+ xorg::testing::XServer server;
+
+ /**
+ * The server configuration. SetUpConfigAndLog() by default works on
+ * this configuration and the server started by StartServer() will then
+ * use this configuration.
+ */
+ XOrgConfig config;
+
+private:
+ bool failed;
+
+ /**
+ * Callback for test results. If any test fails, ::Failed() will return
+ * false.
+ */
+ void OnTestPartResult(const ::testing::TestPartResult &test_part_result);
+};
+
+#endif