summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2012-10-16 14:33:12 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2012-10-17 13:14:38 +1000
commitd35d47be00c3b266df6b7bcda2e45ab74b3956f1 (patch)
tree1243e47491d8f4bc1699557e0b3fb83cf205ed59 /include
parentef25a6b6f3f387a119ab9261f37479fe415702d4 (diff)
xserver: add default X IO error handler
Once a server is started, set the X IO error handler to throw an exception. This way our test cases will survive a server crash and googletest will just continue with the next test case instead of exiting the process completely. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'include')
-rw-r--r--include/xorg/gtest/xorg-gtest-xserver.h34
1 files changed, 34 insertions, 0 deletions
diff --git a/include/xorg/gtest/xorg-gtest-xserver.h b/include/xorg/gtest/xorg-gtest-xserver.h
index 8721b94..623e672 100644
--- a/include/xorg/gtest/xorg-gtest-xserver.h
+++ b/include/xorg/gtest/xorg-gtest-xserver.h
@@ -33,11 +33,29 @@
#include <gtest/gtest.h>
#include <xorg/gtest/xorg-gtest.h>
#include <X11/Xlib.h>
+#include <stdexcept>
namespace xorg {
namespace testing {
/**
+ * @class XIOError
+ *
+ * Exception thrown if the display connection encounters an IO error and
+ * calls the XIOErrorHandler function.
+ *
+ * This exception requires an XIOErrorHandler to be registered.
+ * XServer::Start() will register this error handler. For tests that do not
+ * use the provided XServer object, call XServer::RegisterXIOErrorHandler()
+ * instead.
+ */
+class XIOError : public std::runtime_error {
+public:
+ /** Create a new XIOError with the given message */
+ XIOError(const std::string& msg) : std::runtime_error(msg) {}
+};
+
+/**
* @class XServer xorg-gtest-xserver.h xorg/gtest/xorg-gtest-xserver.h
*
* Class representing the X server process.
@@ -55,6 +73,9 @@ namespace testing {
* std::cerr << "Problem killing server" << std::endl;
* }
* @endcode
+ *
+ * Once a XServer is started, a default XIOErrorHandler is installed and
+ * subsequent IO errors on the display connection will throw an XIOError.
*/
class XServer : public xorg::testing::Process {
public:
@@ -221,6 +242,19 @@ class XServer : public xorg::testing::Process {
*/
static bool WaitForEventOfType(::Display *display, int type, int extension, int evtype, time_t timeout = 1000);
+ /**
+ * Install a default XIOErrorHandler. That error handler will throw an
+ * xorg::testing::XIOError when encountered.
+ *
+ * This function is called automatically by XServer::Start(). Usually,
+ * you will not need to call this function unless your test does not
+ * instantiate and Start() an XServer object.
+ *
+ * This function will only install a new error handler if the currently
+ * installed XIOErrorHandler is not the default handler used by Xlib.
+ */
+ static void RegisterXIOErrorHandler();
+
private:
struct Private;
std::auto_ptr<Private> d_;