[PATCH xorg-gtest 10/16] xserver: replace separate paths with an option/value map
Chase Douglas
chase.douglas at canonical.com
Tue Jul 3 11:03:28 PDT 2012
On 07/02/2012 11:44 PM, Peter Hutterer wrote:
> Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
> ---
> include/xorg/gtest/xorg-gtest-xserver.h | 18 ++++++++++++++++
> src/xserver.cpp | 35 ++++++++++++++++++++-----------
> 2 files changed, 41 insertions(+), 12 deletions(-)
>
> diff --git a/include/xorg/gtest/xorg-gtest-xserver.h b/include/xorg/gtest/xorg-gtest-xserver.h
> index 5cab01b..707888e 100644
> --- a/include/xorg/gtest/xorg-gtest-xserver.h
> +++ b/include/xorg/gtest/xorg-gtest-xserver.h
> @@ -82,10 +82,16 @@ class XServer : public xorg::testing::Process {
> */
> void SetDisplayNumber(unsigned int display_number);
> /**
> + * Set the logfile path for the server. This call is equivalent to
> + * XServer::SetOption("-logfile", path_to_logfile)
> + *
> * @param [in] path_to_logfile The path to the log file
> */
> void SetLogfilePath(std::string &path_to_logfile);
> /**
> + * Set the logfile path for the server. This call is equivalent to
> + * XServer::SetOption("-config", path_to_conf)
> + *
> * @param [in] path_to_conf The path to the xorg.conf file
> */
> void SetConfigPath(std::string &path_to_conf);
> @@ -103,6 +109,18 @@ class XServer : public xorg::testing::Process {
> const char* GetDisplayString(void);
>
> /**
> + * Set startup options for the server. This is a more generic call
> + * to XServer::SetLogfilePath and XServer::SetConfigPath.
> + *
> + * For arguments that do not take/need a value, use the empty string as
> + * value.
> + *
> + * @param [in] key Commandline option
> + * @param [in] value Option value (if any)
> + */
> + void SetOption(std::string key, std::string value);
> +
> + /**
> * Wait for a specific device to be added to the server.
> *
> * @param [in] display The X display connection
> diff --git a/src/xserver.cpp b/src/xserver.cpp
> index f5fd245..765feb1 100644
> --- a/src/xserver.cpp
> +++ b/src/xserver.cpp
> @@ -42,6 +42,7 @@
> #include <stdexcept>
> #include <vector>
> #include <fstream>
> +#include <map>
>
> #include <X11/Xlib.h>
> #include <X11/extensions/XInput2.h>
> @@ -50,16 +51,22 @@ struct xorg::testing::XServer::Private {
> Private()
> : display_number(DEFAULT_DISPLAY),
> display_string(),
> - path_to_logfile(DEFAULT_XORG_LOGFILE),
> - path_to_conf(DUMMY_CONF_PATH),
> path_to_server(DEFAULT_XORG_SERVER) {
> +
> + std::string key, value;
> + key = std::string("-config");
> + value = std::string(DUMMY_CONF_PATH);
> + options[key] = value;
> +
> + key = std::string("-logfile");
> + value = std::string(DEFAULT_XORG_LOGFILE);
> + options[key] = value;
> }
>
> unsigned int display_number;
> std::string display_string;
> - std::string path_to_logfile;
> - std::string path_to_conf;
> std::string path_to_server;
> + std::map<std::string, std::string> options;
> };
>
> xorg::testing::XServer::XServer() : d_(new Private) {
> @@ -79,11 +86,11 @@ const char* xorg::testing::XServer::GetDisplayString(void) {
> }
>
> void xorg::testing::XServer::SetLogfilePath(std::string &path_to_logfile) {
> - d_->path_to_logfile = path_to_logfile;
> + SetOption("-logfile", path_to_logfile);
> }
>
> void xorg::testing::XServer::SetConfigPath(std::string &path_to_conf) {
> - d_->path_to_conf = path_to_conf;
> + SetOption("-config", path_to_conf);
> }
>
> void xorg::testing::XServer::SetServerPath(std::string &path_to_server) {
> @@ -235,7 +242,7 @@ void xorg::testing::XServer::WaitForConnections(void) {
> message += ". Ensure that the \"dummy\" video driver is installed.\n"
> "If the X.org server is older than 1.12, "
> "tests will need to be run as root.\nCheck ";
> - message += d_->path_to_logfile;
> + message += d_->options["-logfile"];
> message += " for any errors";
> throw std::runtime_error(message);
> } else if (pid == 0) {
> @@ -265,17 +272,17 @@ void xorg::testing::XServer::TestStartup(void) {
> /* 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_logfile.c_str(), std::ofstream::out);
> + 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_->path_to_logfile;
> + message += d_->options["-logfile"];
> message += " is not writable.";
> throw std::runtime_error(message);
> }
>
> - std::string old_log_file = d_->path_to_logfile.c_str();
> + std::string old_log_file = d_->options["-logfile"].c_str();
> old_log_file += ".old";
> log_test.open(old_log_file.c_str(), std::ofstream::out);
> log_test.close();
> @@ -298,8 +305,8 @@ unsigned int xorg::testing::XServer::Start(std::string &program) {
> Process::Start(program, program.c_str(),
> GetDisplayString(),
> "-logverbose", "10",
> - "-logfile", d_->path_to_logfile.c_str(),
> - "-config", d_->path_to_conf.c_str(),
> + "-logfile", d_->options["-logfile"].c_str(),
> + "-config", d_->options["-config"].c_str(),
> NULL);
>
> /* FIXME: use -displayfd here once the released servers support it */
> @@ -339,3 +346,7 @@ bool xorg::testing::XServer::Kill(void) {
> std::cerr << "Warning: Dummy X server did not shut down\n";
> return false;
> }
> +
> +void xorg::testing::XServer::SetOption(std::string key, std::string value) {
> + d_->options[key] = value;
> +}
>
Works for me :)
Reviewed-by: Chase Douglas <chase.douglas at canonical.com>
More information about the xorg-devel
mailing list