Respect DISPLAY environment variable in XWindows tests

XWindowsScreenTests was failing under Gentoo's package manager. I have
also addressed this in XWindowsScreenSaverTests, which is currently
unused.
This commit is contained in:
James Le Cuirot 2020-08-22 11:46:25 +01:00
parent bd1db368b3
commit fa46480c35
No known key found for this signature in database
GPG Key ID: 1226415D00DD3137
2 changed files with 14 additions and 2 deletions

View File

@ -23,6 +23,7 @@
#include "platform/XWindowsScreenSaver.h" #include "platform/XWindowsScreenSaver.h"
#include "test/global/gtest.h" #include "test/global/gtest.h"
#include <cstdlib>
#include <X11/Xlib.h> #include <X11/Xlib.h>
using ::testing::_; using ::testing::_;
@ -30,7 +31,12 @@ using ::testing::_;
// TODO: not working on build machine for some reason // TODO: not working on build machine for some reason
TEST(CXWindowsScreenSaverTests, activate_defaultScreen_todo) TEST(CXWindowsScreenSaverTests, activate_defaultScreen_todo)
{ {
Display* display = XOpenDisplay(":0.0"); const char* displayName = std::getenv("DISPLAY");
if (displayName == NULL) {
displayName = ":0.0";
}
Display* display = XOpenDisplay(displayName);
Window window = DefaultRootWindow(display); Window window = DefaultRootWindow(display);
MockEventQueue eventQueue; MockEventQueue eventQueue;
EXPECT_CALL(eventQueue, removeHandler(_, _)).Times(1); EXPECT_CALL(eventQueue, removeHandler(_, _)).Times(1);

View File

@ -20,16 +20,22 @@
#include "platform/XWindowsScreen.h" #include "platform/XWindowsScreen.h"
#include "test/global/gtest.h" #include "test/global/gtest.h"
#include <cstdlib>
using ::testing::_; using ::testing::_;
TEST(CXWindowsScreenTests, fakeMouseMove_nonPrimary_getCursorPosValuesCorrect) TEST(CXWindowsScreenTests, fakeMouseMove_nonPrimary_getCursorPosValuesCorrect)
{ {
const char* displayName = std::getenv("DISPLAY");
if (displayName == NULL) {
displayName = ":0.0";
}
MockEventQueue eventQueue; MockEventQueue eventQueue;
EXPECT_CALL(eventQueue, adoptHandler(_, _, _)).Times(2); EXPECT_CALL(eventQueue, adoptHandler(_, _, _)).Times(2);
EXPECT_CALL(eventQueue, adoptBuffer(_)).Times(2); EXPECT_CALL(eventQueue, adoptBuffer(_)).Times(2);
EXPECT_CALL(eventQueue, removeHandler(_, _)).Times(2); EXPECT_CALL(eventQueue, removeHandler(_, _)).Times(2);
XWindowsScreen screen(new XWindowsImpl(), ":0.0", false, false, 0, &eventQueue); XWindowsScreen screen(new XWindowsImpl(), displayName, false, false, 0, &eventQueue);
screen.fakeMouseMove(10, 20); screen.fakeMouseMove(10, 20);