Commit fbafda2e authored by Peter Hutterer's avatar Peter Hutterer
Browse files

test: add SetDisplayString()



Don't rely on the environment alone, take the display string if it's been
set.
Signed-off-by: Peter Hutterer's avatarPeter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: default avatarChase Douglas <chase.douglas@canonical.com>
parent cbe0fc53
......@@ -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_;
......
......@@ -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;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment