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

Peter Hutterer peter.hutterer at who-t.net
Wed Jul 11 14:55:40 PDT 2012


On Wed, Jul 11, 2012 at 12:38:27PM -0700, Chase Douglas wrote:
> On 07/10/2012 06:51 PM, Peter Hutterer wrote:
> >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;
> >+}
> >
> 
> No objections. I'm curious to find out what you plan to use this for
> :). It's probably in one of your new tests that I've yet to review.

it's largely a way to get around the env setting to force a
specific display. so instead of setenv() this now becomes
test->SetDisplayString(...).

it's not that big a change, it just takes the env redirection out.

> Reviewed-by: Chase Douglas <chase.douglas at canonical.com>

thanks.

Cheers,
  Peter


More information about the xorg-devel mailing list