[PATCH 2/2 xorg-gtest] Namespace xorg-gtest header filenames

Peter Hutterer peter.hutterer at who-t.net
Sun May 20 14:55:31 PDT 2012


On Fri, May 18, 2012 at 01:23:32PM -0700, Chase Douglas wrote:
> Due to the default automake compilation flags including -I. -I.., it is
> possible to pick up an xorg-gtest header like device.h instead of a
> project header. Namespacing the headers should resolve this issue. Users
> should be including xorg-gtest.h instead of individual headers, so this
> should not cause compilation failures.
> 
> Signed-off-by: Chase Douglas <chase.douglas at canonical.com>
> ---
>  include/Makefile.am                          |    8 +-
>  include/xorg/gtest/environment.h             |  184 --------------------------
>  include/xorg/gtest/evemu/device.h            |   91 -------------
>  include/xorg/gtest/evemu/xorg-gtest_device.h |   91 +++++++++++++
>  include/xorg/gtest/process.h                 |  166 -----------------------
>  include/xorg/gtest/test.h                    |  104 ---------------
>  include/xorg/gtest/xorg-gtest.h              |    8 +-
>  include/xorg/gtest/xorg-gtest_environment.h  |  184 ++++++++++++++++++++++++++
>  include/xorg/gtest/xorg-gtest_process.h      |  166 +++++++++++++++++++++++
>  include/xorg/gtest/xorg-gtest_test.h         |  104 +++++++++++++++
>  10 files changed, 553 insertions(+), 553 deletions(-)
>  delete mode 100644 include/xorg/gtest/environment.h
>  delete mode 100644 include/xorg/gtest/evemu/device.h
>  create mode 100644 include/xorg/gtest/evemu/xorg-gtest_device.h
>  delete mode 100644 include/xorg/gtest/process.h
>  delete mode 100644 include/xorg/gtest/test.h
>  create mode 100644 include/xorg/gtest/xorg-gtest_environment.h
>  create mode 100644 include/xorg/gtest/xorg-gtest_process.h
>  create mode 100644 include/xorg/gtest/xorg-gtest_test.h

tbh i'm not a big fan of a xorg-gtest_test naming. Can't we just use dashes?

Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net> otherwise


Cheers,
  Peter

> 
> diff --git a/include/Makefile.am b/include/Makefile.am
> index 0256685..6b39d0b 100644
> --- a/include/Makefile.am
> +++ b/include/Makefile.am
> @@ -24,8 +24,8 @@
>  #
>  
>  nobase_include_HEADERS = \
> -	xorg/gtest/environment.h \
> -	xorg/gtest/process.h \
> -	xorg/gtest/test.h \
> -	xorg/gtest/evemu/device.h \
> +	xorg/gtest/xorg-gtest_environment.h \
> +	xorg/gtest/xorg-gtest_process.h \
> +	xorg/gtest/xorg-gtest_test.h \
> +	xorg/gtest/evemu/xorg-gtest_device.h \
>  	xorg/gtest/xorg-gtest.h
> diff --git a/include/xorg/gtest/environment.h b/include/xorg/gtest/environment.h
> deleted file mode 100644
> index e113cd7..0000000
> --- a/include/xorg/gtest/environment.h
> +++ /dev/null
> @@ -1,184 +0,0 @@
> -/*******************************************************************************
> - *
> - * X testing environment - Google Test environment feat. dummy x server
> - *
> - * Copyright (C) 2011, 2012 Canonical Ltd.
> - *
> - * Permission is hereby granted, free of charge, to any person obtaining a copy
> - * of this software and associated documentation files (the "Software"), to deal
> - * in the Software without restriction, including without limitation the rights
> - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> - * copies of the Software, and to permit persons to whom the Software is
> - * furnished to do so, subject to the following conditions:
> - *
> - * The above copyright notice and this permission notice (including the next
> - * paragraph) shall be included in all copies or substantial portions of the
> - * Software.
> - *
> - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
> - * SOFTWARE.
> - *
> - ******************************************************************************/
> -
> -#ifndef XORG_GTEST_ENVIRONMENT_H
> -#define XORG_GTEST_ENVIRONMENT_H
> -
> -#include <memory>
> -#include <string>
> -
> -#include <gtest/gtest.h>
> -
> -namespace xorg {
> -namespace testing {
> -
> -/**
> - * \mainpage X.org Google %Test Framework
> - *
> - * Xorg-gtest makes it easy to write test cases
> - * for a dummy headless X.org server. It can also run tests
> - * using a running X11 server.
> - *
> - */
> -
> -/**
> - * @class Environment environment.h xorg/gtest/environment.h
> - *
> - * Global Google %Test environment providing a dummy X server.
> - *
> - * Starts up a dummy X server for testing purposes.
> - * Either associate the environment manually
> - * with the overall testing framework like
> - * @code
> - * 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.
> - */
> -class Environment : public ::testing::Environment {
> - public:
> -  /**
> -   * Constructs an object to provide a global X server dummy environment.
> -   */
> -  Environment();
> -
> -  virtual ~Environment();
> -
> -  /**
> -   * 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 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;
> -
> -  /**
> -   * Kill the dummy Xorg server with SIGKILL.
> -   */
> -  void Kill();
> -
> - protected:
> -  /**
> -   * Starts the dummy X server.
> -   *
> -   * Reimplemented from ::testing::Environment. See Google %Test documentation
> -   * for details.
> -   *
> -   * @throws std::runtime_error if a dummy X server cannot be started.
> -   *
> -   * @post If successful: subsequent connections to the dummy X server succeed.
> -   * @post If successful: %Environment variable DISPLAY contains the
> -   * display port for connecting to the dummy X server.
> -   */
> -  virtual void SetUp();
> -
> -  /**
> -   * Stops the dummy X server.
> -   *
> -   * Reimplemented from ::testing::Environment. See Google %Test documentation
> -   * for details.
> -   *
> -   * @post Dummy X server stopped.
> -   */
> -  virtual void TearDown();
> -
> - private:
> -  struct Private;
> -  std::auto_ptr<Private> d_;
> -
> -  /* Disable copy constructor & assignment operator */
> -  Environment(const Environment&);
> -  Environment& operator=(const Environment&);
> -};
> -
> -} // namespace testing
> -} // namespace xorg
> -
> -#endif // XORG_GTEST_ENVIRONMENT_H
> diff --git a/include/xorg/gtest/evemu/device.h b/include/xorg/gtest/evemu/device.h
> deleted file mode 100644
> index 4e456ce..0000000
> --- a/include/xorg/gtest/evemu/device.h
> +++ /dev/null
> @@ -1,91 +0,0 @@
> -/*******************************************************************************
> - *
> - * X testing environment - Google Test environment feat. dummy x server
> - *
> - * Copyright (C) 2012 Canonical Ltd.
> - *
> - * Permission is hereby granted, free of charge, to any person obtaining a copy
> - * of this software and associated documentation files (the "Software"), to deal
> - * in the Software without restriction, including without limitation the rights
> - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> - * copies of the Software, and to permit persons to whom the Software is
> - * furnished to do so, subject to the following conditions:
> - *
> - * The above copyright notice and this permission notice (including the next
> - * paragraph) shall be included in all copies or substantial portions of the
> - * Software.
> - *
> - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
> - * SOFTWARE.
> - *
> - ******************************************************************************/
> -
> -#ifndef XORG_GTEST_EVEMU_DEVICE_H_
> -#define XORG_GTEST_EVEMU_DEVICE_H_
> -
> -#include <memory>
> -#include <string>
> -
> -extern "C" {
> -
> -#include <evemu.h>
> -
> -} // extern "C"
> -
> -namespace xorg {
> -namespace testing {
> -namespace evemu {
> -
> -/**
> - * @class Device device.h xorg/gtest/evemu/device.h
> - *
> - * uTouch-Evemu input device for replaying events through the Linux uinput
> - * evdev subsystem.
> - *
> - * Use the Recording class to play back a specific recording.
> - */
> -
> -class Device {
> - public:
> -  /**
> -   * Create a new device context.
> -   *
> -   * @param [in] path Path to uTouch-Evemu device property file.
> -   *
> -   * @throws std::runtime_error if the device property file could not be found
> -   *         or the device could not be created.
> -   */
> -  explicit Device(const std::string& path);
> -  ~Device();
> -
> -  /**
> -   * Play a uTouch-Evemu recording through the device.
> -   *
> -   * Plays the recording from the beginning through the end. This call will
> -   * block until the recording has finished.
> -   *
> -   * @param [in] path Path to uTouch-Evemu recording file.
> -   *
> -   * @throws std::runtime_error if playback failed for any reason.
> -   */
> -  void Play(const std::string& path) const;
> -
> - private:
> -  struct Private;
> -  std::auto_ptr<Private> d_;
> -
> -  /* Disable copy constructor & assignment operator */
> -  Device(const Device&);
> -  Device& operator=(const Device&);
> -};
> -
> -} // namespace evemu
> -} // namespace testing
> -} // namespace xorg
> -
> -#endif // XORG_GTEST_EVEMU_DEVICE_H_
> diff --git a/include/xorg/gtest/evemu/xorg-gtest_device.h b/include/xorg/gtest/evemu/xorg-gtest_device.h
> new file mode 100644
> index 0000000..4e456ce
> --- /dev/null
> +++ b/include/xorg/gtest/evemu/xorg-gtest_device.h
> @@ -0,0 +1,91 @@
> +/*******************************************************************************
> + *
> + * X testing environment - Google Test environment feat. dummy x server
> + *
> + * Copyright (C) 2012 Canonical Ltd.
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a copy
> + * of this software and associated documentation files (the "Software"), to deal
> + * in the Software without restriction, including without limitation the rights
> + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> + * copies of the Software, and to permit persons to whom the Software is
> + * furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice (including the next
> + * paragraph) shall be included in all copies or substantial portions of the
> + * Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
> + * SOFTWARE.
> + *
> + ******************************************************************************/
> +
> +#ifndef XORG_GTEST_EVEMU_DEVICE_H_
> +#define XORG_GTEST_EVEMU_DEVICE_H_
> +
> +#include <memory>
> +#include <string>
> +
> +extern "C" {
> +
> +#include <evemu.h>
> +
> +} // extern "C"
> +
> +namespace xorg {
> +namespace testing {
> +namespace evemu {
> +
> +/**
> + * @class Device device.h xorg/gtest/evemu/device.h
> + *
> + * uTouch-Evemu input device for replaying events through the Linux uinput
> + * evdev subsystem.
> + *
> + * Use the Recording class to play back a specific recording.
> + */
> +
> +class Device {
> + public:
> +  /**
> +   * Create a new device context.
> +   *
> +   * @param [in] path Path to uTouch-Evemu device property file.
> +   *
> +   * @throws std::runtime_error if the device property file could not be found
> +   *         or the device could not be created.
> +   */
> +  explicit Device(const std::string& path);
> +  ~Device();
> +
> +  /**
> +   * Play a uTouch-Evemu recording through the device.
> +   *
> +   * Plays the recording from the beginning through the end. This call will
> +   * block until the recording has finished.
> +   *
> +   * @param [in] path Path to uTouch-Evemu recording file.
> +   *
> +   * @throws std::runtime_error if playback failed for any reason.
> +   */
> +  void Play(const std::string& path) const;
> +
> + private:
> +  struct Private;
> +  std::auto_ptr<Private> d_;
> +
> +  /* Disable copy constructor & assignment operator */
> +  Device(const Device&);
> +  Device& operator=(const Device&);
> +};
> +
> +} // namespace evemu
> +} // namespace testing
> +} // namespace xorg
> +
> +#endif // XORG_GTEST_EVEMU_DEVICE_H_
> diff --git a/include/xorg/gtest/process.h b/include/xorg/gtest/process.h
> deleted file mode 100644
> index d7e1143..0000000
> --- a/include/xorg/gtest/process.h
> +++ /dev/null
> @@ -1,166 +0,0 @@
> -/*******************************************************************************
> - *
> - * X testing environment - Google Test environment feat. dummy x server
> - *
> - * Copyright (C) 2011, 2012 Canonical Ltd.
> - *
> - * Permission is hereby granted, free of charge, to any person obtaining a copy
> - * of this software and associated documentation files (the "Software"), to deal
> - * in the Software without restriction, including without limitation the rights
> - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> - * copies of the Software, and to permit persons to whom the Software is
> - * furnished to do so, subject to the following conditions:
> - *
> - * The above copyright notice and this permission notice (including the next
> - * paragraph) shall be included in all copies or substantial portions of the
> - * Software.
> - *
> - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
> - * SOFTWARE.
> - *
> - ******************************************************************************/
> -
> -#ifndef XORG_GTEST_PROCESS_H
> -#define XORG_GTEST_PROCESS_H
> -
> -#include <stdarg.h>
> -
> -#include <memory>
> -#include <string>
> -
> -namespace xorg {
> -namespace testing {
> -
> -/**
> - * @class Process test.h xorg/gtest/process.h
> - *
> - * Class that abstracts child process creation and termination.
> - *
> - * This class allows for forking, running and terminating child processes.
> - * In addition, manipulation of the child process' environment is supported.
> - * For example, starting an X server instance on display port 133 as a child
> - * process can be realized with the following code snippet:
> - * @code
> - * Process xorgServer;
> - * try {
> - *   xorgServer.Start("Xorg", "Xorg", ":133");
> - * } catch (const std::runtime_error&e) {
> - *   std::cerr << "Problem starting the X server: " << e.what() << std::endl;
> - * }
> - * ...
> - * if (!xorgServer.Terminate()) {
> - *   std::cerr << "Problem terminating server ... killing now ..." << std::endl;
> - *   if (!xorgServer.Kill())
> - *     std::cerr << "Problem killing server" << std::endl;
> - * }
> - * @endcode
> - */
> -class Process {
> - public:
> -  /**
> -   * Helper function to adjust the environment of the current process.
> -   *
> -   * @param [in] name Name of the environment variable.
> -   * @param [in] value Value of the environment variable.
> -   * @param [in] overwrite Whether to overwrite the value of existing env
> -   *             variables.
> -   *
> -   * @throws std::runtime_error if adjusting the environment does not succeed.
> -   */
> -  static void SetEnv(const std::string& name, const std::string& value,
> -                     bool overwrite);
> -
> -  /**
> -   * Helper function to query the environment of the current process.
> -   *
> -   * @param [in] name The name of the environment variable.
> -   * @param [out] exists If not NULL, the variable will be set to true if the
> -   *              environment variable exists and to false otherwise.
> -   * @returns The value of the environment variable, or an empty string.
> -   */
> -  static std::string GetEnv(const std::string& name, bool* exists = NULL);
> -
> -  /**
> -   * Creates a child-process that is in a terminated state.
> -   */
> -  Process();
> -
> -  /**
> -   * Starts a program as a child process.
> -   *
> -   * See 'man execvp' for further information on the variadic argument list.
> -   *
> -   * @param program The program to start.
> -   * @param args Variadic list of arguments passed to the program.
> -   *
> -   * @throws std::runtime_error on failure.
> -   *
> -   * @post If successful: Child process forked and program started.
> -   * @post If successful: Subsequent calls to Pid() return child process pid.
> -   */
> -  void Start(const std::string& program, va_list args);
> -
> -  /**
> -   * Starts a program as a child process.
> -   *
> -   * Takes a variadic list of arguments passed to the program.
> -   * See 'man execvp' for further information on the variadic argument list.
> -   *
> -   * @param program The program to start.
> -   *
> -   * @throws std::runtime_error on failure.
> -   *
> -   * @post If successful: Child process forked and program started.
> -   * @post If successful: Subsequent calls to Pid() return child process pid.
> -   */
> -  void Start(const std::string& program, ...);
> -
> -  /**
> -   * Terminates (SIGTERM) this child process.
> -   *
> -   * @throws std::runtime_error if child tries to terminate itself.
> -   *
> -   * @returns true if termination succeeded, false otherwise.
> -   *
> -   * @post If successful: Child process terminated.
> -   * @post If successful: Subsequent calls to Pid() return -1.
> -   */
> -  bool Terminate();
> -
> -  /**
> -   * Kills (SIGKILL) this child process.
> -   *
> -   * @throws std::runtime_error if child tries to kill itself.
> -   *
> -   * @returns true if kill succeeded, false otherwise.
> -   *
> -   * @post If successful: Child process killed.
> -   * @post If successful: Subsequent calls to Pid() return -1.
> -   */
> -  bool Kill();
> -
> -  /**
> -   * Accesses the pid of the child process.
> -   *
> -   * @returns The pid of the child process or -1.
> -   */
> -  pid_t Pid() const;
> -
> - private:
> -  struct Private;
> -  std::auto_ptr<Private> d_;
> -
> -  /* Disable copy constructor, assignment operator */
> -  Process(const Process&);
> -  Process& operator=(const Process&);
> -};
> -
> -} // testing
> -} // xorg
> -
> -#endif // XORG_GTEST_PROCESS_H
> diff --git a/include/xorg/gtest/test.h b/include/xorg/gtest/test.h
> deleted file mode 100644
> index 093890b..0000000
> --- a/include/xorg/gtest/test.h
> +++ /dev/null
> @@ -1,104 +0,0 @@
> -/*******************************************************************************
> - *
> - * X testing environment - Google Test environment feat. dummy x server
> - *
> - * Copyright (C) 2011, 2012 Canonical Ltd.
> - *
> - * Permission is hereby granted, free of charge, to any person obtaining a copy
> - * of this software and associated documentation files (the "Software"), to deal
> - * in the Software without restriction, including without limitation the rights
> - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> - * copies of the Software, and to permit persons to whom the Software is
> - * furnished to do so, subject to the following conditions:
> - *
> - * The above copyright notice and this permission notice (including the next
> - * paragraph) shall be included in all copies or substantial portions of the
> - * Software.
> - *
> - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
> - * SOFTWARE.
> - *
> - ******************************************************************************/
> -
> -#ifndef XORG_GTEST_TEST_H_
> -#define XORG_GTEST_TEST_H_
> -
> -#include <memory>
> -
> -#include <gtest/gtest.h>
> -#include <X11/Xlib.h>
> -
> -namespace xorg {
> -namespace testing {
> -
> -/**
> - * @class Test test.h xorg/gtest/test.h
> - *
> - * Google %Test fixture providing an Xlib connection to an X11 server.
> - *
> - * Sets up and tears down an XLib connection to an X11 server.
> - * Rely on Google %Test's TEST_F macro to use this fixture for your
> - * own tests or subclass it and override the SetUp and TearDown
> - * methods.
> - *
> - * @remark The display port is read from the environment variable DISPLAY.
> - */
> -class Test : public ::testing::Test {
> - public:
> -
> -  Test();
> -
> -  virtual ~Test();
> -
> - protected:
> -  /**
> -   * Tries to connect to an X server instance.
> -   *
> -   * Fails if no X server is running. Updates the display object.
> -   * Reimplemented from ::testing::Test. See Google %Test documentation for
> -   * details.
> -   *
> -   * @post Subsequent calls to Display() return a valid pointer or NULL if an error occured.
> -   *
> -   * @throws std::runtime_error if no X server is running.
> -   */
> -  virtual void SetUp();
> -
> -  /**
> -   * Closes the display.
> -   *
> -   * Reimplemented from ::testing::Test. See Google %Test documentation for
> -   * details.
> -   *
> -   * @post Subsequent calls to Display() return NULL.
> -   */
> -  virtual void TearDown();
> -
> -  /**
> -   * Accesses the display representing an Xlib connection.
> -   *
> -   * Accessible by subclasses and test cases relying on this fixture.
> -   *
> -   * @returns Pointer to a display or NULL.
> -   */
> -  ::Display* Display() const;
> -
> -  /** @cond Implementation */
> -  struct Private;
> -  std::auto_ptr<Private> d_;
> -  /** @endcond Implementation */
> - private:
> -  /* Disable copy c'tor, assignment operator */
> -  Test(const Test&);
> -  Test& operator=(const Test&);
> -};
> -
> -} // namespace testing
> -} // namespace xorg
> -
> -#endif // XORG_GTEST_TEST_H_
> diff --git a/include/xorg/gtest/xorg-gtest.h b/include/xorg/gtest/xorg-gtest.h
> index 5568185..deb2ad7 100644
> --- a/include/xorg/gtest/xorg-gtest.h
> +++ b/include/xorg/gtest/xorg-gtest.h
> @@ -25,10 +25,10 @@
>   *
>   ******************************************************************************/
>  
> -#include "environment.h"
> -#include "process.h"
> -#include "test.h"
> +#include "xorg-gtest_environment.h"
> +#include "xorg-gtest_process.h"
> +#include "xorg-gtest_test.h"
>  
>  #ifdef HAVE_EVEMU
> -#include "evemu/device.h"
> +#include "evemu/xorg-gtest_device.h"
>  #endif
> diff --git a/include/xorg/gtest/xorg-gtest_environment.h b/include/xorg/gtest/xorg-gtest_environment.h
> new file mode 100644
> index 0000000..e113cd7
> --- /dev/null
> +++ b/include/xorg/gtest/xorg-gtest_environment.h
> @@ -0,0 +1,184 @@
> +/*******************************************************************************
> + *
> + * X testing environment - Google Test environment feat. dummy x server
> + *
> + * Copyright (C) 2011, 2012 Canonical Ltd.
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a copy
> + * of this software and associated documentation files (the "Software"), to deal
> + * in the Software without restriction, including without limitation the rights
> + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> + * copies of the Software, and to permit persons to whom the Software is
> + * furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice (including the next
> + * paragraph) shall be included in all copies or substantial portions of the
> + * Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
> + * SOFTWARE.
> + *
> + ******************************************************************************/
> +
> +#ifndef XORG_GTEST_ENVIRONMENT_H
> +#define XORG_GTEST_ENVIRONMENT_H
> +
> +#include <memory>
> +#include <string>
> +
> +#include <gtest/gtest.h>
> +
> +namespace xorg {
> +namespace testing {
> +
> +/**
> + * \mainpage X.org Google %Test Framework
> + *
> + * Xorg-gtest makes it easy to write test cases
> + * for a dummy headless X.org server. It can also run tests
> + * using a running X11 server.
> + *
> + */
> +
> +/**
> + * @class Environment environment.h xorg/gtest/environment.h
> + *
> + * Global Google %Test environment providing a dummy X server.
> + *
> + * Starts up a dummy X server for testing purposes.
> + * Either associate the environment manually
> + * with the overall testing framework like
> + * @code
> + * 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.
> + */
> +class Environment : public ::testing::Environment {
> + public:
> +  /**
> +   * Constructs an object to provide a global X server dummy environment.
> +   */
> +  Environment();
> +
> +  virtual ~Environment();
> +
> +  /**
> +   * 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 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;
> +
> +  /**
> +   * Kill the dummy Xorg server with SIGKILL.
> +   */
> +  void Kill();
> +
> + protected:
> +  /**
> +   * Starts the dummy X server.
> +   *
> +   * Reimplemented from ::testing::Environment. See Google %Test documentation
> +   * for details.
> +   *
> +   * @throws std::runtime_error if a dummy X server cannot be started.
> +   *
> +   * @post If successful: subsequent connections to the dummy X server succeed.
> +   * @post If successful: %Environment variable DISPLAY contains the
> +   * display port for connecting to the dummy X server.
> +   */
> +  virtual void SetUp();
> +
> +  /**
> +   * Stops the dummy X server.
> +   *
> +   * Reimplemented from ::testing::Environment. See Google %Test documentation
> +   * for details.
> +   *
> +   * @post Dummy X server stopped.
> +   */
> +  virtual void TearDown();
> +
> + private:
> +  struct Private;
> +  std::auto_ptr<Private> d_;
> +
> +  /* Disable copy constructor & assignment operator */
> +  Environment(const Environment&);
> +  Environment& operator=(const Environment&);
> +};
> +
> +} // namespace testing
> +} // namespace xorg
> +
> +#endif // XORG_GTEST_ENVIRONMENT_H
> diff --git a/include/xorg/gtest/xorg-gtest_process.h b/include/xorg/gtest/xorg-gtest_process.h
> new file mode 100644
> index 0000000..d7e1143
> --- /dev/null
> +++ b/include/xorg/gtest/xorg-gtest_process.h
> @@ -0,0 +1,166 @@
> +/*******************************************************************************
> + *
> + * X testing environment - Google Test environment feat. dummy x server
> + *
> + * Copyright (C) 2011, 2012 Canonical Ltd.
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a copy
> + * of this software and associated documentation files (the "Software"), to deal
> + * in the Software without restriction, including without limitation the rights
> + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> + * copies of the Software, and to permit persons to whom the Software is
> + * furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice (including the next
> + * paragraph) shall be included in all copies or substantial portions of the
> + * Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
> + * SOFTWARE.
> + *
> + ******************************************************************************/
> +
> +#ifndef XORG_GTEST_PROCESS_H
> +#define XORG_GTEST_PROCESS_H
> +
> +#include <stdarg.h>
> +
> +#include <memory>
> +#include <string>
> +
> +namespace xorg {
> +namespace testing {
> +
> +/**
> + * @class Process test.h xorg/gtest/process.h
> + *
> + * Class that abstracts child process creation and termination.
> + *
> + * This class allows for forking, running and terminating child processes.
> + * In addition, manipulation of the child process' environment is supported.
> + * For example, starting an X server instance on display port 133 as a child
> + * process can be realized with the following code snippet:
> + * @code
> + * Process xorgServer;
> + * try {
> + *   xorgServer.Start("Xorg", "Xorg", ":133");
> + * } catch (const std::runtime_error&e) {
> + *   std::cerr << "Problem starting the X server: " << e.what() << std::endl;
> + * }
> + * ...
> + * if (!xorgServer.Terminate()) {
> + *   std::cerr << "Problem terminating server ... killing now ..." << std::endl;
> + *   if (!xorgServer.Kill())
> + *     std::cerr << "Problem killing server" << std::endl;
> + * }
> + * @endcode
> + */
> +class Process {
> + public:
> +  /**
> +   * Helper function to adjust the environment of the current process.
> +   *
> +   * @param [in] name Name of the environment variable.
> +   * @param [in] value Value of the environment variable.
> +   * @param [in] overwrite Whether to overwrite the value of existing env
> +   *             variables.
> +   *
> +   * @throws std::runtime_error if adjusting the environment does not succeed.
> +   */
> +  static void SetEnv(const std::string& name, const std::string& value,
> +                     bool overwrite);
> +
> +  /**
> +   * Helper function to query the environment of the current process.
> +   *
> +   * @param [in] name The name of the environment variable.
> +   * @param [out] exists If not NULL, the variable will be set to true if the
> +   *              environment variable exists and to false otherwise.
> +   * @returns The value of the environment variable, or an empty string.
> +   */
> +  static std::string GetEnv(const std::string& name, bool* exists = NULL);
> +
> +  /**
> +   * Creates a child-process that is in a terminated state.
> +   */
> +  Process();
> +
> +  /**
> +   * Starts a program as a child process.
> +   *
> +   * See 'man execvp' for further information on the variadic argument list.
> +   *
> +   * @param program The program to start.
> +   * @param args Variadic list of arguments passed to the program.
> +   *
> +   * @throws std::runtime_error on failure.
> +   *
> +   * @post If successful: Child process forked and program started.
> +   * @post If successful: Subsequent calls to Pid() return child process pid.
> +   */
> +  void Start(const std::string& program, va_list args);
> +
> +  /**
> +   * Starts a program as a child process.
> +   *
> +   * Takes a variadic list of arguments passed to the program.
> +   * See 'man execvp' for further information on the variadic argument list.
> +   *
> +   * @param program The program to start.
> +   *
> +   * @throws std::runtime_error on failure.
> +   *
> +   * @post If successful: Child process forked and program started.
> +   * @post If successful: Subsequent calls to Pid() return child process pid.
> +   */
> +  void Start(const std::string& program, ...);
> +
> +  /**
> +   * Terminates (SIGTERM) this child process.
> +   *
> +   * @throws std::runtime_error if child tries to terminate itself.
> +   *
> +   * @returns true if termination succeeded, false otherwise.
> +   *
> +   * @post If successful: Child process terminated.
> +   * @post If successful: Subsequent calls to Pid() return -1.
> +   */
> +  bool Terminate();
> +
> +  /**
> +   * Kills (SIGKILL) this child process.
> +   *
> +   * @throws std::runtime_error if child tries to kill itself.
> +   *
> +   * @returns true if kill succeeded, false otherwise.
> +   *
> +   * @post If successful: Child process killed.
> +   * @post If successful: Subsequent calls to Pid() return -1.
> +   */
> +  bool Kill();
> +
> +  /**
> +   * Accesses the pid of the child process.
> +   *
> +   * @returns The pid of the child process or -1.
> +   */
> +  pid_t Pid() const;
> +
> + private:
> +  struct Private;
> +  std::auto_ptr<Private> d_;
> +
> +  /* Disable copy constructor, assignment operator */
> +  Process(const Process&);
> +  Process& operator=(const Process&);
> +};
> +
> +} // testing
> +} // xorg
> +
> +#endif // XORG_GTEST_PROCESS_H
> diff --git a/include/xorg/gtest/xorg-gtest_test.h b/include/xorg/gtest/xorg-gtest_test.h
> new file mode 100644
> index 0000000..093890b
> --- /dev/null
> +++ b/include/xorg/gtest/xorg-gtest_test.h
> @@ -0,0 +1,104 @@
> +/*******************************************************************************
> + *
> + * X testing environment - Google Test environment feat. dummy x server
> + *
> + * Copyright (C) 2011, 2012 Canonical Ltd.
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a copy
> + * of this software and associated documentation files (the "Software"), to deal
> + * in the Software without restriction, including without limitation the rights
> + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> + * copies of the Software, and to permit persons to whom the Software is
> + * furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice (including the next
> + * paragraph) shall be included in all copies or substantial portions of the
> + * Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
> + * SOFTWARE.
> + *
> + ******************************************************************************/
> +
> +#ifndef XORG_GTEST_TEST_H_
> +#define XORG_GTEST_TEST_H_
> +
> +#include <memory>
> +
> +#include <gtest/gtest.h>
> +#include <X11/Xlib.h>
> +
> +namespace xorg {
> +namespace testing {
> +
> +/**
> + * @class Test test.h xorg/gtest/test.h
> + *
> + * Google %Test fixture providing an Xlib connection to an X11 server.
> + *
> + * Sets up and tears down an XLib connection to an X11 server.
> + * Rely on Google %Test's TEST_F macro to use this fixture for your
> + * own tests or subclass it and override the SetUp and TearDown
> + * methods.
> + *
> + * @remark The display port is read from the environment variable DISPLAY.
> + */
> +class Test : public ::testing::Test {
> + public:
> +
> +  Test();
> +
> +  virtual ~Test();
> +
> + protected:
> +  /**
> +   * Tries to connect to an X server instance.
> +   *
> +   * Fails if no X server is running. Updates the display object.
> +   * Reimplemented from ::testing::Test. See Google %Test documentation for
> +   * details.
> +   *
> +   * @post Subsequent calls to Display() return a valid pointer or NULL if an error occured.
> +   *
> +   * @throws std::runtime_error if no X server is running.
> +   */
> +  virtual void SetUp();
> +
> +  /**
> +   * Closes the display.
> +   *
> +   * Reimplemented from ::testing::Test. See Google %Test documentation for
> +   * details.
> +   *
> +   * @post Subsequent calls to Display() return NULL.
> +   */
> +  virtual void TearDown();
> +
> +  /**
> +   * Accesses the display representing an Xlib connection.
> +   *
> +   * Accessible by subclasses and test cases relying on this fixture.
> +   *
> +   * @returns Pointer to a display or NULL.
> +   */
> +  ::Display* Display() const;
> +
> +  /** @cond Implementation */
> +  struct Private;
> +  std::auto_ptr<Private> d_;
> +  /** @endcond Implementation */
> + private:
> +  /* Disable copy c'tor, assignment operator */
> +  Test(const Test&);
> +  Test& operator=(const Test&);
> +};
> +
> +} // namespace testing
> +} // namespace xorg
> +
> +#endif // XORG_GTEST_TEST_H_
> -- 
> 1.7.9.5
> 


More information about the xorg-devel mailing list