diff options
author | Daniel d'Andrada <daniel.dandrada@canonical.com> | 2012-02-06 09:29:46 -0200 |
---|---|---|
committer | Chase Douglas <chase.douglas@canonical.com> | 2012-02-06 10:05:53 -0800 |
commit | 4216fddec31fed8b141f6d6f233c31e73e651fde (patch) | |
tree | ca7b9e9e74f454b01bcd216c9d82cbb114116662 | |
parent | d568a6c0626eeef038753f207f234037bbbb26e4 (diff) |
Make Environment API property-based.
Instead of shoving all parameters in the constructor.
Signed-off-by: Daniel d'Andrada <daniel.dandrada@canonical.com>
Reviewed-by: Chase Douglas <chase.douglas@canonical.com>
Signed-off-by: Chase Douglas <chase.douglas@canonical.com>
-rw-r--r-- | include/xorg/gtest/environment.h | 85 | ||||
-rw-r--r-- | src/Makefile.am | 6 | ||||
-rw-r--r-- | src/defines.h | 2 | ||||
-rw-r--r-- | src/environment.cpp | 48 | ||||
-rw-r--r-- | src/main.cpp | 37 |
5 files changed, 127 insertions, 51 deletions
diff --git a/include/xorg/gtest/environment.h b/include/xorg/gtest/environment.h index 3996507..843c451 100644 --- a/include/xorg/gtest/environment.h +++ b/include/xorg/gtest/environment.h @@ -47,16 +47,11 @@ namespace testing { * Either associate the environment manually * 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"); - * - * xorg::testing::Environment* environment = new xorg::testing::Environment( - * xorg_conf_path, - * server, - * xorg_display); - * environment->set_log_file(xorg_log_file_path); + * xorg::testing::Environment* environment = new xorg::testing::Environment; + * environment->set_server("Xorg"); + * environment->set_display(133); + * environment->set_conf_file("conf/dummy.conf"); + * environment->set_log_file("/tmp/MyDummyXorg.log"); * testing::AddGlobalTestEnvironment(environment); * @endcode * or link to libxorg-gtest_main. @@ -65,28 +60,78 @@ class Environment : public ::testing::Environment { public: /** * Constructs an object to provide a global X server dummy environment. - * @param path_to_conf Path to xserver configuration. - * @param path_to_server Path to xserver executable. - * @param display Display port of dummy xserver instance. */ - Environment(const std::string& path_to_conf, - const std::string& path_to_server = "Xorg", int display = 133); + Environment(); virtual ~Environment(); /** - * Sets the path where the xserver log file will be created. - * @param path_to_log_file Path to xserver logfile. + * Sets the path where the server log file will be created. + * + * The path will be passed on to the server via the command line argument + * "-logfile". The default value is "/tmp/Xorg.GTest.log". + * + * @param path_to_log_file Path to server 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. + * Returns the path where the server log file will be created. + * + * @return Path to server logfile. */ const std::string& log_file() const; + /** + * Sets the path to the desired server configuration file. + * + * The path will be passed on to the server via the command line argument + * "-config". The default value is "[datadir]/xorg/gtest/dummy.conf". + * + * @param path_conf_file Path to a Xorg X server .conf file. + */ + void set_conf_file(const std::string& path_conf_file); + + /** + * Returns the path of the server configuration file to be used. + * + * @return File path of the server configuration currently set + */ + const std::string& conf_file() const; + + /** + * Sets the path to the server executable + * + * The default value is "Xorg". + * + * @param path_to_server Path to an X.org server executable + */ + void set_server(const std::string& path_to_server); + + /** + * Returns the path of the server executable to be used. + * + * @return Path to server executable. + */ + const std::string& server() const; + + /** + * Sets the display number that the server will use. + * + * The display number will be passed on to the server via the command line. + * The default value is 133. + * + * @param diplay_num A display number. + */ + void set_display(int display_num); + + /** + * Returns the display number of the server instance. + * + * @return Display number of the server. + */ + int display() const; + protected: /** * Starts the dummy X server. diff --git a/src/Makefile.am b/src/Makefile.am index d1b5995..1daeeb8 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -7,7 +7,8 @@ libxorg_gtest_la_SOURCES = \ libxorg_gtest_la_CPPFLAGS = \ $(AM_CPPFLAGS) \ - $(GTEST_CPPFLAGS) + $(GTEST_CPPFLAGS) \ + -DDUMMY_CONF_PATH="\"$(library_datadir)/dummy.conf\"" libxorg_gtest_main_la_SOURCES = \ defines.h \ @@ -23,8 +24,7 @@ library_data_DATA = $(top_srcdir)/conf/dummy.conf libxorg_gtest_main_la_CPPFLAGS = \ $(AM_CPPFLAGS) \ - $(GTEST_CPPFLAGS) \ - -DDUMMY_CONF_PATH="\"$(library_datadir)/dummy.conf\"" + $(GTEST_CPPFLAGS) libxorg_gtest_la_LDFLAGS = $(X11_LIBS) libxorg_gtest_main_la_LDFLAGS = $(X11_LIBS) diff --git a/src/defines.h b/src/defines.h index 6b5bcac..3bfc1da 100644 --- a/src/defines.h +++ b/src/defines.h @@ -2,5 +2,7 @@ #define XORGGTEST_DEFINES #define DEFAULT_XORG_LOGFILE "/tmp/Xorg.GTest.log" +#define DEFAULT_XORG_SERVER "Xorg" +#define DEFAULT_DISPLAY 133 #endif diff --git a/src/environment.cpp b/src/environment.cpp index a888454..10db3c7 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -36,22 +36,20 @@ #include <X11/Xlib.h> struct xorg::testing::Environment::Private { - Private(const std::string& conf, const std::string& server, int display_num) - : path_to_conf(conf), path_to_log_file(DEFAULT_XORG_LOGFILE), - path_to_server(server), display(display_num) { + Private() + : path_to_conf(DUMMY_CONF_PATH), path_to_log_file(DEFAULT_XORG_LOGFILE), + path_to_server(DEFAULT_XORG_SERVER), display(DEFAULT_DISPLAY) { } - const std::string path_to_conf; + std::string path_to_conf; std::string path_to_log_file; - const std::string path_to_server; - const int display; + std::string path_to_server; + int display; Process process; }; -xorg::testing::Environment::Environment(const std::string& path_to_conf, - const std::string& path_to_server, - int display) - : d_(new Private(path_to_conf, path_to_server, display)) { +xorg::testing::Environment::Environment() + : d_(new Private) { } xorg::testing::Environment::~Environment() {} @@ -66,6 +64,36 @@ const std::string& xorg::testing::Environment::log_file() const return d_->path_to_log_file; } +void xorg::testing::Environment::set_conf_file(const std::string& path_conf_file) +{ + d_->path_to_conf = path_conf_file; +} + +const std::string& xorg::testing::Environment::conf_file() const +{ + return d_->path_to_conf; +} + +void xorg::testing::Environment::set_server(const std::string& path_to_server) +{ + d_->path_to_server = path_to_server; +} + +const std::string& xorg::testing::Environment::server() const +{ + return d_->path_to_server; +} + +void xorg::testing::Environment::set_display(int display_num) +{ + d_->display = display_num; +} + +int xorg::testing::Environment::display() const +{ + return d_->display; +} + void xorg::testing::Environment::SetUp() { static char display_string[6]; snprintf(display_string, 6, ":%d", d_->display); diff --git a/src/main.cpp b/src/main.cpp index 10a94bd..7b482e7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -30,33 +30,28 @@ namespace { int help = false; int no_dummy_server = false; -int xorg_conf = false; -int xorg_display_opt = false; +int xorg_conf_specified = false; +int xorg_display_specified = false; int xorg_logfile_specified = false; -int server = false; +int server_specified = false; const struct option longopts[] = { { "help", no_argument, &help, true, }, { "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-conf", required_argument, &xorg_conf_specified, true, }, + { "xorg-display", required_argument, &xorg_display_specified, true, }, { "xorg-logfile", required_argument, &xorg_logfile_specified, true, }, - { "server", required_argument, &server, true, }, + { "server", required_argument, &server_specified, true, }, { NULL, 0, NULL, 0 } }; } // namespace int main(int argc, char *argv[]) { - /* Default Xorg dummy conf path. */ - std::string xorg_conf_path(DUMMY_CONF_PATH); + std::string xorg_conf_path; std::string xorg_log_file_path; - - /* Default X display */ - int xorg_display = 133; - - /* Default Xorg executable */ - std::string server("Xorg"); + int xorg_display = -1; + std::string server; testing::InitGoogleTest(&argc, argv); @@ -109,10 +104,16 @@ int main(int argc, char *argv[]) { } if (!no_dummy_server) { - xorg::testing::Environment* environment = new xorg::testing::Environment( - xorg_conf_path, - server, - xorg_display); + xorg::testing::Environment* environment = new xorg::testing::Environment; + + if (xorg_conf_specified) + environment->set_conf_file(xorg_conf_path); + + if (server_specified) + environment->set_server(server); + + if (xorg_display_specified) + environment->set_display(xorg_display); if (xorg_logfile_specified) environment->set_log_file(xorg_log_file_path); |