[PATCH xorg-gtest 06/11] xserver: add RemoveOption
Peter Hutterer
peter.hutterer at who-t.net
Mon Oct 29 18:38:28 PDT 2012
Allow removing an option from the command list too.
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
include/xorg/gtest/xorg-gtest-xserver.h | 10 ++++++++++
src/xserver.cpp | 4 ++++
test/.gitignore | 1 +
test/Makefile.am | 6 +++++-
test/xserver-test-helper.cpp | 19 +++++++++++++++++++
test/xserver-test.cpp | 12 ++++++++++++
6 files changed, 51 insertions(+), 1 deletion(-)
create mode 100644 test/xserver-test-helper.cpp
diff --git a/include/xorg/gtest/xorg-gtest-xserver.h b/include/xorg/gtest/xorg-gtest-xserver.h
index 4d3779c..8bf7996 100644
--- a/include/xorg/gtest/xorg-gtest-xserver.h
+++ b/include/xorg/gtest/xorg-gtest-xserver.h
@@ -204,6 +204,16 @@ class XServer : public xorg::testing::Process {
void SetOption(const std::string &key, const std::string &value = "");
/**
+ * Remove a previously set option.
+ *
+ * If an option was set through SetOption(), remove the option again. If
+ * the specified option has never been set, do nothing.
+ *
+ * @param [in] option Commandline option to remove
+ */
+ void RemoveOption(const std::string &option);
+
+ /**
* Wait for a specific device to be added to the server.
*
* @param [in] display The X display connection
diff --git a/src/xserver.cpp b/src/xserver.cpp
index 21fca15..c511fab 100644
--- a/src/xserver.cpp
+++ b/src/xserver.cpp
@@ -529,6 +529,10 @@ void xorg::testing::XServer::SetOption(const std::string &key, const std::string
d_->options[key] = value;
}
+void xorg::testing::XServer::RemoveOption(const std::string &option) {
+ d_->options.erase(option);
+}
+
const std::string& xorg::testing::XServer::GetLogFilePath() {
return d_->options["-logfile"];
}
diff --git a/test/.gitignore b/test/.gitignore
index 1d39462..e2b9a87 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -1,4 +1,5 @@
process-test
process-test-helper
xserver-test
+xserver-test-helper
device-test
diff --git a/test/Makefile.am b/test/Makefile.am
index 487c534..cab7cf7 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -30,7 +30,8 @@ test_programs = process-test \
device-test
noinst_PROGRAMS = $(test_programs) \
- process-test-helper
+ process-test-helper \
+ xserver-test-helper
noinst_DATA = PIXART-USB-OPTICAL-MOUSE.desc
GTEST_CPPFLAGS=-I$(top_srcdir)/gtest/include -I$(top_srcdir)/gtest
@@ -57,6 +58,9 @@ xserver_test_SOURCES = xserver-test.cpp
xserver_test_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/include
xserver_test_LDADD = $(tests_libraries)
+xserver_test_helper_SOURCES = xserver-test-helper.cpp
+xserver_test_helper_CPPFLAGS = $(AM_CPPFLAGS)
+
device_test_SOURCES = device-test.cpp
device_test_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/include
device_test_LDADD = $(tests_libraries)
diff --git a/test/xserver-test-helper.cpp b/test/xserver-test-helper.cpp
new file mode 100644
index 0000000..a52dd52
--- /dev/null
+++ b/test/xserver-test-helper.cpp
@@ -0,0 +1,19 @@
+#include <string.h>
+#include <stdlib.h>
+
+/**
+ * Test helper. Exists with failure if "-fail yes" is passed
+ */
+int main(int argc, char **argv) {
+
+ for (int i = 0; i < argc; i++) {
+ if (strcmp(argv[i], "-fail") == 0)
+ exit(1);
+
+ /* test passes "-fail yes" and we expect both to be removed */
+ if (strcmp(argv[i], "yes") == 0)
+ exit(1);
+ }
+
+ return 0;
+}
diff --git a/test/xserver-test.cpp b/test/xserver-test.cpp
index ed0de36..e41267d 100644
--- a/test/xserver-test.cpp
+++ b/test/xserver-test.cpp
@@ -274,6 +274,18 @@ TEST(XServer, KeepAlive)
ASSERT_EQ(errno, ESRCH);
}
+TEST(XServer, RemoveOption)
+{
+ XServer server;
+ server.SetOption("-fail", "yes");
+ server.Start(TEST_ROOT_DIR "/xserver-test-helper");
+ ASSERT_EQ(server.GetState(), Process::FINISHED_FAILURE);
+
+ server.RemoveOption("-fail");
+ server.Start(TEST_ROOT_DIR "/xserver-test-helper");
+ ASSERT_EQ(server.GetState(), Process::FINISHED_SUCCESS);
+}
+
int main(int argc, char *argv[]) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
--
1.7.11.7
More information about the xorg-devel
mailing list