Commit 89d366ba authored by Peter Hutterer's avatar Peter Hutterer Committed by Chase Douglas
Browse files

xserver: add GetVersion() to retrieve server version



For non-integrated tests, knowing the X server version is important.
Signed-off-by: Peter Hutterer's avatarPeter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: default avatarChase Douglas <chase.douglas@canonical.com>
Signed-off-by: default avatarChase Douglas <chase.douglas@canonical.com>
parent 9d2dd4e8
......@@ -132,6 +132,16 @@ class XServer : public xorg::testing::Process {
*/
const std::string& GetDisplayString(void);
/**
* Get the X server version as printed into the log file, usually in the
* form a.b.c[.d], with d being the optional part for release
* candidates.
*
* @return A string representing this server's version. If the server
* hasn't been started yet, GetVersion() returns an empty string.
*/
const std::string& GetVersion();
/**
* Set startup options for the server.
*
......
......@@ -60,6 +60,7 @@ struct xorg::testing::XServer::Private {
std::string display_string;
std::string path_to_server;
std::map<std::string, std::string> options;
std::string version;
};
xorg::testing::XServer::XServer() : d_(new Private) {
......@@ -286,6 +287,36 @@ void xorg::testing::XServer::TestStartup(void) {
}
const std::string& xorg::testing::XServer::GetVersion(void) {
if (Pid() == -1 || !d_->version.empty())
return d_->version;
std::ifstream logfile;
logfile.open(d_->options["-logfile"].c_str());
std::string prefix = "X.Org X Server ";
if (logfile.is_open()) {
std::string line;
while (getline(logfile, line)) {
size_t start = line.find(prefix);
if (start == line.npos)
continue;
line = line.substr(prefix.size());
/* RCs have the human-readable version after the version */
size_t end = line.find(" ");
if (end == line.npos)
end = line.size();
d_->version = line.substr(0, end);
break;
}
}
return d_->version;
}
void xorg::testing::XServer::Start(const std::string &program) {
TestStartup();
......
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