[PATCH xorg-gtest v2 4/8] xserver: move starting the process into the XServer object

Peter Hutterer peter.hutterer at who-t.net
Tue Jul 10 20:28:44 PDT 2012


Changes from hardcoded vararg call to requiring the caller to set up options
for logfile, config, etc. beforehand. The display string is automatically
added to the command line.

If no binary is given by the caller, the previously set binary path is used.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
Changes to v1:
- have one Start() call only handling with/without binary
- changes to accommodate for Process::Start(vector<std::string>) instead of
  previous const char *

 include/xorg/gtest/xorg-gtest-xserver.h |    8 ++++++++
 src/environment.cpp                     |    7 +------
 src/xserver.cpp                         |   19 +++++++++++++++++++
 3 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/include/xorg/gtest/xorg-gtest-xserver.h b/include/xorg/gtest/xorg-gtest-xserver.h
index 1ba2a0f..0b7e7a0 100644
--- a/include/xorg/gtest/xorg-gtest-xserver.h
+++ b/include/xorg/gtest/xorg-gtest-xserver.h
@@ -47,6 +47,14 @@ class XServer : public xorg::testing::Process {
     XServer();
 
     /**
+     * Start a new server. If no binary is given, the server started is the
+     * default compiled-in server binary.
+     *
+     * @param [in] program Path to the XServer binary
+     */
+    void Start(std::string program = std::string());
+
+    /**
      * Waits until this server is ready to take connections.
      */
     void WaitForConnections(void);
diff --git a/src/environment.cpp b/src/environment.cpp
index 7573b62..1521564 100644
--- a/src/environment.cpp
+++ b/src/environment.cpp
@@ -144,12 +144,7 @@ void xorg::testing::Environment::SetUp() {
   d_->server.SetDisplayNumber(d_->display);
   d_->server.SetOption("-logfile", d_->path_to_log_file);
   d_->server.SetOption("-config", d_->path_to_conf);
-  d_->server.Start(d_->path_to_server, d_->path_to_server.c_str(),
-                    display_string,
-                    "-logverbose", "10",
-                    "-logfile", d_->path_to_log_file.c_str(),
-                    "-config", d_->path_to_conf.c_str(),
-                    NULL);
+  d_->server.Start(d_->path_to_server);
   d_->server.WaitForConnections();
 
   Process::SetEnv("DISPLAY", display_string, true);
diff --git a/src/xserver.cpp b/src/xserver.cpp
index 62bd48f..2f9c364 100644
--- a/src/xserver.cpp
+++ b/src/xserver.cpp
@@ -253,6 +253,25 @@ void xorg::testing::XServer::WaitForConnections(void) {
   throw std::runtime_error("Unable to open connection to dummy X server");
 }
 
+void xorg::testing::XServer::Start(std::string program) {
+  if (program.empty())
+    program = d_->path_to_server;
+
+  std::vector<std::string> args;
+  std::map<std::string, std::string>::iterator it;
+
+  args.push_back(program);
+  args.push_back(std::string(GetDisplayString()));
+
+  for (it = d_->options.begin(); it != d_->options.end(); it++) {
+    args.push_back(it->first);
+    if (!it->second.empty())
+      args.push_back(it->second);
+  }
+
+  Process::Start(program, args);
+}
+
 void xorg::testing::XServer::SetOption(std::string key, std::string value) {
   d_->options[key] = value;
 }
-- 
1.7.10.4



More information about the xorg-devel mailing list