diff options
author | Chase Douglas <chase.douglas@canonical.com> | 2012-02-01 11:12:29 -0800 |
---|---|---|
committer | Chase Douglas <chase.douglas@canonical.com> | 2012-02-01 11:22:57 -0800 |
commit | 79b2d4e7f976621705bd32a9fd16e56c989a5a45 (patch) | |
tree | c2b2cfd8cbf00d5299ea20ea355ef1640799d188 | |
parent | 656d8b22be42b23d5336a85173d7381bf115a327 (diff) |
And by default point to a location that doesn't require root privileges to be used.
This will make it possible to run Xorg without being root.
Signed-off-by: Daniel d'Andrada <daniel.dandrada@canonical.com>
-rw-r--r-- | include/xorg/gtest/environment.h | 15 | ||||
-rw-r--r-- | src/defines.h | 6 | ||||
-rw-r--r-- | src/environment.cpp | 20 | ||||
-rw-r--r-- | src/main.cpp | 14 |
4 files changed, 53 insertions, 2 deletions
diff --git a/include/xorg/gtest/environment.h b/include/xorg/gtest/environment.h index fd550e7..3996507 100644 --- a/include/xorg/gtest/environment.h +++ b/include/xorg/gtest/environment.h @@ -48,6 +48,7 @@ namespace testing { * with the overall testing framework like * @code * std::string xorg_conf_path("conf/dummy.conf"); + * std::string xorg_log_file_path("/tmp/MyDummyXorg.log"); * int xorg_display = 133; * std::string server("Xorg"); * @@ -55,6 +56,7 @@ namespace testing { * xorg_conf_path, * server, * xorg_display); + * environment->set_log_file(xorg_log_file_path); * testing::AddGlobalTestEnvironment(environment); * @endcode * or link to libxorg-gtest_main. @@ -72,6 +74,19 @@ class Environment : public ::testing::Environment { virtual ~Environment(); + /** + * Sets the path where the xserver log file will be created. + * @param path_to_log_file Path to xserver logfile. + */ + void set_log_file(const std::string& path_to_log_file); + + /** + * Returns the path where the xserver log file will be created. + * Its default value is "/tmp/Xorg.GTest.log" + * @return Path to xserver logfile. + */ + const std::string& log_file() const; + protected: /** * Starts the dummy X server. diff --git a/src/defines.h b/src/defines.h new file mode 100644 index 0000000..6b5bcac --- /dev/null +++ b/src/defines.h @@ -0,0 +1,6 @@ +#ifndef XORGGTEST_DEFINES +#define XORGGTEST_DEFINES + +#define DEFAULT_XORG_LOGFILE "/tmp/Xorg.GTest.log" + +#endif diff --git a/src/environment.cpp b/src/environment.cpp index b00eaf9..a888454 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -21,6 +21,7 @@ #include "xorg/gtest/environment.h" #include "xorg/gtest/process.h" +#include "defines.h" #include <sys/types.h> #include <unistd.h> @@ -36,10 +37,12 @@ struct xorg::testing::Environment::Private { Private(const std::string& conf, const std::string& server, int display_num) - : path_to_conf(conf), path_to_server(server), display(display_num) { + : path_to_conf(conf), path_to_log_file(DEFAULT_XORG_LOGFILE), + path_to_server(server), display(display_num) { } const std::string path_to_conf; + std::string path_to_log_file; const std::string path_to_server; const int display; Process process; @@ -53,12 +56,25 @@ xorg::testing::Environment::Environment(const std::string& path_to_conf, xorg::testing::Environment::~Environment() {} +void xorg::testing::Environment::set_log_file(const std::string& path_to_log_file) +{ + d_->path_to_log_file = path_to_log_file; +} + +const std::string& xorg::testing::Environment::log_file() const +{ + return d_->path_to_log_file; +} + void xorg::testing::Environment::SetUp() { static char display_string[6]; snprintf(display_string, 6, ":%d", d_->display); d_->process.Start(d_->path_to_server, d_->path_to_server.c_str(), - display_string, "-config", d_->path_to_conf.c_str(), NULL); + display_string, + "-logfile", d_->path_to_log_file.c_str(), + "-config", d_->path_to_conf.c_str(), + NULL); Process::SetEnv("DISPLAY", display_string, true); diff --git a/src/main.cpp b/src/main.cpp index 331aa28..10a94bd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -24,6 +24,7 @@ #include <gtest/gtest.h> #include "xorg/gtest/environment.h" +#include "defines.h" namespace { @@ -31,6 +32,7 @@ int help = false; int no_dummy_server = false; int xorg_conf = false; int xorg_display_opt = false; +int xorg_logfile_specified = false; int server = false; const struct option longopts[] = { @@ -38,6 +40,7 @@ const struct option longopts[] = { { "no-dummy-server", no_argument, &no_dummy_server, true, }, { "xorg-conf", required_argument, &xorg_conf, true, }, { "xorg-display", required_argument, &xorg_display_opt, true, }, + { "xorg-logfile", required_argument, &xorg_logfile_specified, true, }, { "server", required_argument, &server, true, }, { NULL, 0, NULL, 0 } }; @@ -47,6 +50,7 @@ const struct option longopts[] = { int main(int argc, char *argv[]) { /* Default Xorg dummy conf path. */ std::string xorg_conf_path(DUMMY_CONF_PATH); + std::string xorg_log_file_path; /* Default X display */ int xorg_display = 133; @@ -80,6 +84,10 @@ int main(int argc, char *argv[]) { break; case 4: + xorg_log_file_path = optarg; + break; + + case 5: server = optarg; break; @@ -95,6 +103,8 @@ int main(int argc, char *argv[]) { std::cout << " --xorg-conf: Path to xorg dummy configuration file\n"; std::cout << " --server: Path to X server executable\n"; std::cout << " --xorg-display: xorg dummy display port\n"; + std::cout << " --xorg-logfile: xorg logfile filename. See -logfile in \"man Xorg\".\n" + " Its default value is "DEFAULT_XORG_LOGFILE".\n"; exit(-1); } @@ -103,6 +113,10 @@ int main(int argc, char *argv[]) { xorg_conf_path, server, xorg_display); + + if (xorg_logfile_specified) + environment->set_log_file(xorg_log_file_path); + testing::AddGlobalTestEnvironment(environment); } |