diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2012-10-29 09:01:41 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2012-11-07 13:14:08 +1000 |
commit | 07dabf1d9044fb819a0728a3095bda065e794e0c (patch) | |
tree | 382536e4fe5e693b83d0601633a8daf7bc2a40f0 | |
parent | b80a12ca704a79931b3bca12b881c738bd94eeaa (diff) |
xserver: add RemoveOption
Allow removing an option from the command list too.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r-- | include/xorg/gtest/xorg-gtest-xserver.h | 10 | ||||
-rw-r--r-- | src/xserver.cpp | 4 | ||||
-rw-r--r-- | test/.gitignore | 1 | ||||
-rw-r--r-- | test/Makefile.am | 6 | ||||
-rw-r--r-- | test/xserver-test-helper.cpp | 19 | ||||
-rw-r--r-- | test/xserver-test.cpp | 12 |
6 files changed, 51 insertions, 1 deletions
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(); |