[PATCH xorg-gtest 15/16] test: add SetDisplayString()

Peter Hutterer peter.hutterer at who-t.net
Mon Jul 2 23:44:56 PDT 2012


Don't rely on the environment alone, take the display string if it's been
set.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 include/xorg/gtest/xorg-gtest-test.h |    7 +++++++
 src/test.cpp                         |    8 +++++++-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/include/xorg/gtest/xorg-gtest-test.h b/include/xorg/gtest/xorg-gtest-test.h
index 3b78a17..3338c80 100644
--- a/include/xorg/gtest/xorg-gtest-test.h
+++ b/include/xorg/gtest/xorg-gtest-test.h
@@ -88,6 +88,13 @@ class Test : public ::testing::Test {
    */
   ::Display* Display() const;
 
+  /**
+   * Set the display string used for XOpenDisplay()
+   *
+   * @param display The string representing the display connection, or NULL
+   */
+  void SetDisplayString(const char *display);
+
   /** @cond Implementation */
   struct Private;
   std::auto_ptr<Private> d_;
diff --git a/src/test.cpp b/src/test.cpp
index e3e65e4..499915b 100644
--- a/src/test.cpp
+++ b/src/test.cpp
@@ -33,16 +33,18 @@
 
 struct xorg::testing::Test::Private {
   ::Display* display;
+  const char *display_string;
 };
 
 xorg::testing::Test::Test() : d_(new Private) {
   d_->display = NULL;
+  d_->display_string = NULL;
 }
 
 xorg::testing::Test::~Test() {}
 
 void xorg::testing::Test::SetUp() {
-  d_->display = XOpenDisplay(NULL);
+  d_->display = XOpenDisplay(d_->display_string);
   if (!d_->display)
     throw std::runtime_error("Failed to open connection to display");
 }
@@ -56,3 +58,7 @@ void xorg::testing::Test::TearDown() {
 ::Display* xorg::testing::Test::Display() const {
   return d_->display;
 }
+
+void xorg::testing::Test::SetDisplayString(const char *display) {
+  d_->display_string = display;
+}
-- 
1.7.10.4



More information about the xorg-devel mailing list