[PATCH xorg-gtest 11/11] test: add xserver test for logfile removal
Peter Hutterer
peter.hutterer at who-t.net
Wed Aug 15 23:36:44 PDT 2012
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
test/Makefile.am | 6 ++++-
test/xserver-test.cpp | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 67 insertions(+), 1 deletion(-)
create mode 100644 test/xserver-test.cpp
diff --git a/test/Makefile.am b/test/Makefile.am
index 44c1027..ed6416a 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -25,7 +25,7 @@
# SOFTWARE.
#
-noinst_PROGRAMS = process-test
+noinst_PROGRAMS = process-test xserver-test
AM_CPPFLAGS = $(GTEST_CPPFLAGS)
AM_CXXFLAGS = $(BASE_CXXFLAGS)
@@ -41,6 +41,10 @@ process_test_SOURCES = process-test.cpp
process_test_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/include
process_test_LDADD = $(tests_libraries)
+xserver_test_SOURCES = xserver-test.cpp
+xserver_test_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/include
+xserver_test_LDADD = $(tests_libraries)
+
check_LIBRARIES = libgtest.a libxorg-gtest.a
# build googletest as static lib
diff --git a/test/xserver-test.cpp b/test/xserver-test.cpp
new file mode 100644
index 0000000..ba6c462
--- /dev/null
+++ b/test/xserver-test.cpp
@@ -0,0 +1,62 @@
+#include <errno.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <fstream>
+
+#include <gtest/gtest.h>
+#include <xorg/gtest/xorg-gtest.h>
+
+using namespace xorg::testing;
+
+TEST(XServer, LogRemoval)
+{
+ SCOPED_TRACE("TESTCASE: X server startup and log file removal on success and error");
+ std::string logfile = "/tmp/xorg-testing-xserver_____________.log";
+
+ /* make sure a previous failed test didn't leave it around */
+ unlink(logfile.c_str());
+
+ XServer server;
+ server.SetOption("-logfile", logfile);
+ server.Start();
+ server.Terminate(3000);
+ server.RemoveLogFile();
+
+ std::ifstream file(logfile.c_str());
+ ASSERT_FALSE(file.good());
+ file.close();
+
+ server.SetOption("-doesnotexist", "");
+ server.Start();
+ while (server.GetState() == Process::RUNNING)
+ usleep(5000);
+
+ ASSERT_EQ(server.GetState(), Process::FINISHED_FAILURE);
+ file.open(logfile.c_str());
+ ASSERT_FALSE(file.good()); /* server didn't leave the file behind */
+
+ /* now create it */
+ std::ofstream f(logfile.c_str());
+ file.open(logfile.c_str());
+ ASSERT_TRUE(file.good());
+ file.close();
+
+ /* must not remove it now */
+ server.RemoveLogFile();
+
+ file.open(logfile.c_str());
+ ASSERT_TRUE(file.good()); /* server didn't remove it */
+ file.close();
+
+ server.RemoveLogFile(true);
+ file.open(logfile.c_str());
+ ASSERT_FALSE(file.good()); /* server did remove it */
+ file.close();
+}
+
+
+int main(int argc, char *argv[]) {
+ testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}
--
1.7.11.2
More information about the xorg-devel
mailing list