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

xserver: move testing startup to the XServer object



No real functional changes, TestStartup() is called by XServer::Start()
before the process is started, so from the Environment's POV, everything
stays the same.
Signed-off-by: Peter Hutterer's avatarPeter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: default avatarChase Douglas <chase.douglas@canonical.com>
parent 59de5d4f
......@@ -151,6 +151,8 @@ class XServer : public xorg::testing::Process {
XServer(const XServer&);
XServer& operator=(const XServer&);
void TestStartup(void);
};
} // namespace testing
} // namespace xorg
......
......@@ -37,7 +37,6 @@
#include <csignal>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <stdexcept>
......@@ -106,41 +105,6 @@ void xorg::testing::Environment::SetUp() {
static char display_string[6];
snprintf(display_string, 6, ":%d", d_->display);
Display* test_display = XOpenDisplay(display_string);
if (test_display) {
XCloseDisplay(test_display);
std::string message;
message += "A server is already running on ";
message += display_string;
message += ".";
throw std::runtime_error(message);
}
/* The Xorg server won't start unless the log file and the old log file are
* writable. */
std::ofstream log_test;
log_test.open(d_->path_to_log_file.c_str(), std::ofstream::out);
log_test.close();
if (log_test.fail()) {
std::string message;
message += "X.org server log file ";
message += d_->path_to_log_file;
message += " is not writable.";
throw std::runtime_error(message);
}
std::string old_log_file = d_->path_to_log_file.c_str();
old_log_file += ".old";
log_test.open(old_log_file.c_str(), std::ofstream::out);
log_test.close();
if (log_test.fail()) {
std::string message;
message += "X.org old server log file ";
message += old_log_file;
message += " is not writable.";
throw std::runtime_error(message);
}
d_->server.SetDisplayNumber(d_->display);
d_->server.SetOption("-logfile", d_->path_to_log_file);
d_->server.SetOption("-config", d_->path_to_conf);
......
......@@ -42,6 +42,7 @@
#include <stdexcept>
#include <vector>
#include <map>
#include <fstream>
#include <X11/Xlib.h>
#include <X11/extensions/XInput2.h>
......@@ -247,7 +248,47 @@ void xorg::testing::XServer::WaitForConnections(void) {
throw std::runtime_error("Unable to open connection to dummy X server");
}
void xorg::testing::XServer::TestStartup(void) {
Display* test_display = XOpenDisplay(GetDisplayString().c_str());
if (test_display) {
XCloseDisplay(test_display);
std::string message;
message += "A server is already running on ";
message += GetDisplayString();
message += ".";
throw std::runtime_error(message);
}
/* The Xorg server won't start unless the log file and the old log file are
* writable. */
std::ofstream log_test;
log_test.open(d_->options["-logfile"].c_str(), std::ofstream::out);
log_test.close();
if (log_test.fail()) {
std::string message;
message += "X.org server log file ";
message += d_->options["-config"];
message += " is not writable.";
throw std::runtime_error(message);
}
std::string old_log_file = d_->options["-config"];
old_log_file += ".old";
log_test.open(old_log_file.c_str(), std::ofstream::out);
log_test.close();
if (log_test.fail()) {
std::string message;
message += "X.org old server log file ";
message += old_log_file;
message += " is not writable.";
throw std::runtime_error(message);
}
}
void xorg::testing::XServer::Start(const std::string &program) {
TestStartup();
std::vector<std::string> args;
std::map<std::string, std::string>::iterator it;
......
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