summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2012-06-28 12:44:55 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2012-07-12 08:10:44 +1000
commitfbafda2e843e5d63a78fe9f4c03c0ff1096d7a1f (patch)
treec74fdff60b3db219a9cbb45f2e126d249a03e0d0
parentcbe0fc53d53de0559e0989bba9498c87c33502d7 (diff)
test: add SetDisplayString()
Don't rely on the environment alone, take the display string if it's been set. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Chase Douglas <chase.douglas@canonical.com>
-rw-r--r--include/xorg/gtest/xorg-gtest-test.h10
-rw-r--r--src/test.cpp12
2 files changed, 21 insertions, 1 deletions
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;
+}