[PATCH xorg-gtest] xserver: add GetVersion() to retrieve server version
Peter Hutterer
peter.hutterer at who-t.net
Tue Aug 7 21:34:39 PDT 2012
For non-integrated tests, knowing the X server version is important.
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
I thought about decomposing this string into numbers, but really, strcmp()
will likely handle 90% of the cases we need
include/xorg/gtest/xorg-gtest-xserver.h | 10 ++++++++++
src/xserver.cpp | 31 +++++++++++++++++++++++++++++++
2 files changed, 41 insertions(+)
diff --git a/include/xorg/gtest/xorg-gtest-xserver.h b/include/xorg/gtest/xorg-gtest-xserver.h
index 71857d3..0776d36 100644
--- a/include/xorg/gtest/xorg-gtest-xserver.h
+++ b/include/xorg/gtest/xorg-gtest-xserver.h
@@ -133,6 +133,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.
*
* For arguments that do not take/need a value, use the empty string as
diff --git a/src/xserver.cpp b/src/xserver.cpp
index 2c551ff..08ff864 100644
--- a/src/xserver.cpp
+++ b/src/xserver.cpp
@@ -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();
--
1.7.10.4
More information about the xorg-devel
mailing list