[PATCH xorg-gtest 2/4] test: add SetDisplayString()

Peter Hutterer peter.hutterer at who-t.net
Tue Jul 10 18:51:08 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 |   10 ++++++++++
 src/test.cpp                         |   12 +++++++++++-
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/include/xorg/gtest/xorg-gtest-test.h b/include/xorg/gtest/xorg-gtest-test.h
index 3b78a17..a776693 100644
--- a/include/xorg/gtest/xorg-gtest-test.h
+++ b/include/xorg/gtest/xorg-gtest-test.h
@@ -88,6 +88,16 @@ class Test : public ::testing::Test {
    */
   ::Display* Display() const;
 
+  /**
+   * Set the display string used for XOpenDisplay() and thus affects
+   * Test::Display(). This function must be called before
+   * xorg::testing::Test::SetUp() to have any effect.
+   *
+   * @param display The string representing the display connection, or an
+   * empty string for NULL
+   */
+  void SetDisplayString(const std::string &display);
+
   /** @cond Implementation */
   struct Private;
   std::auto_ptr<Private> d_;
diff --git a/src/test.cpp b/src/test.cpp
index e3e65e4..94adf13 100644
--- a/src/test.cpp
+++ b/src/test.cpp
@@ -33,6 +33,7 @@
 
 struct xorg::testing::Test::Private {
   ::Display* display;
+  std::string display_string;
 };
 
 xorg::testing::Test::Test() : d_(new Private) {
@@ -42,7 +43,12 @@ xorg::testing::Test::Test() : d_(new Private) {
 xorg::testing::Test::~Test() {}
 
 void xorg::testing::Test::SetUp() {
-  d_->display = XOpenDisplay(NULL);
+  const char *dpy = NULL;
+
+  if (!d_->display_string.empty())
+    dpy = d_->display_string.c_str();
+
+  d_->display = XOpenDisplay(dpy);
   if (!d_->display)
     throw std::runtime_error("Failed to open connection to display");
 }
@@ -56,3 +62,7 @@ void xorg::testing::Test::TearDown() {
 ::Display* xorg::testing::Test::Display() const {
   return d_->display;
 }
+
+void xorg::testing::Test::SetDisplayString(const std::string &display) {
+  d_->display_string = display;
+}
-- 
1.7.10.4



More information about the xorg-devel mailing list