xorg-gtest  0.1
Xorg testing extension to Google Test
xorg::testing::XServer Class Reference

Class representing the X server process. More...

#include <xorg/gtest/xorg-gtest-xserver.h>

Inheritance diagram for xorg::testing::XServer:
xorg::testing::Process

Public Member Functions

virtual void Start (const std::string &program="")
 Start a new server. More...
 
virtual bool Terminate (unsigned int timeout=2000)
 Terminates this server process. More...
 
virtual bool Kill (unsigned int timeout=2000)
 Kills the server. More...
 
void RemoveLogFile (bool force=false)
 Remove the log file used by this server. More...
 
_X_DEPRECATED void WaitForConnections (void)
 Waits until this server is ready to take connections. More...
 
void SetDisplayNumber (unsigned int display_number)
 Set the display number for this server. More...
 
void SetServerPath (const std::string &path_to_server)
 Set the path to the server binary to be started. More...
 
unsigned int GetDisplayNumber (void)
 Get the display number from this server. More...
 
const std::string & GetDisplayString (void)
 Get the display string that may be used for XOpenDisplay to this server. More...
 
const std::string & GetVersion ()
 Get the X server version as printed into the log file, usually in the form a.b.c[.d], with d being the optional part for release candidates. More...
 
const std::string & GetLogFilePath ()
 Get the server's log file path. More...
 
const std::string & GetConfigPath ()
 Get the server's config file path. More...
 
void SetOption (const std::string &key, const std::string &value="")
 Set startup options for the server. More...
 
void RemoveOption (const std::string &option)
 Remove a previously set option. More...
 
- Public Member Functions inherited from xorg::testing::Process
 Process ()
 Creates a child-process that is in a terminated state. More...
 
pid_t Fork ()
 Fork manually. More...
 
void Start (const std::string &program, const std::vector< std::string > &args)
 Starts a program as a child process. More...
 
void Start (const std::string &program, va_list *args)
 Starts a program as a child process. More...
 
void Start (const std::string &program,...) _X_SENTINEL(0)
 Starts a program as a child process. More...
 
pid_t Pid () const
 Accesses the pid of the child process. More...
 
enum Process::State GetState ()
 Return the state of the process. More...
 

Static Public Member Functions

static bool WaitForDevice (::Display *display, const std::string &name, time_t timeout=1000)
 Wait for a specific device to be added to the server. More...
 
static bool WaitForEvent (::Display *display, time_t timeout=1000)
 Wait for an event on the X connection. More...
 
static bool WaitForEventOfType (::Display *display, int type, int extension=-1, int evtype=-1, time_t timeout=1000)
 Wait for an event of a specific type on the X connection. More...
 
static void RegisterXIOErrorHandler ()
 Install a default XIOErrorHandler. More...
 
static void RegisterXErrorHandler ()
 Install a default XErrorHandler. More...
 
- Static Public Member Functions inherited from xorg::testing::Process
static void SetEnv (const std::string &name, const std::string &value, bool overwrite)
 Helper function to adjust the environment of the current process. More...
 
static std::string GetEnv (const std::string &name, bool *exists=NULL)
 Helper function to query the environment of the current process. More...
 

Additional Inherited Members

- Public Types inherited from xorg::testing::Process
enum  State {
  ERROR, NONE, RUNNING, FINISHED_SUCCESS,
  FINISHED_FAILURE, TERMINATED
}
 Describes the state of a process as seen by this library. More...
 

Detailed Description

Class representing the X server process.

XServer server;
server.SetOption("-logfile", "/tmp/Xserver.log");
server.Start();
...
if (!server.Terminate()) {
std::cerr << "Problem terminating server ... killing now ..." << std::endl;
if (!server.Kill())
std::cerr << "Problem killing server" << std::endl;
}

Once a XServer is started, a default XIOErrorHandler is installed and subsequent IO errors on the display connection will throw an XIOError.

Examples:
xorg-gtest-example.cpp.

Member Function Documentation

◆ GetConfigPath()

const std::string& xorg::testing::XServer::GetConfigPath ( )

Get the server's config file path.

If this path is empty, the server will use it's built-in config file path.

Returns
The config file path this server will use, is using or has used.

◆ GetDisplayNumber()

unsigned int xorg::testing::XServer::GetDisplayNumber ( void  )

Get the display number from this server.

If the server was not started yet, this function returns the display number the server will be started on.

Returns
The numeric display number this server runs on

◆ GetDisplayString()

const std::string& xorg::testing::XServer::GetDisplayString ( void  )

Get the display string that may be used for XOpenDisplay to this server.

This string is effectively :display_number.

Returns
The display string used for XOpenDisplay() to this server.
Examples:
xorg-gtest-example.cpp.

◆ GetLogFilePath()

const std::string& xorg::testing::XServer::GetLogFilePath ( )

Get the server's log file path.

If this path is empty, the server will use it's built-in log file path.

Returns
The log file path this server will use, is using or has used.

◆ GetVersion()

const std::string& xorg::testing::XServer::GetVersion ( )

Get the X server version as printed into the log file, usually in the form a.b.c[.d], with d being the optional part for release candidates.

Returns
A string representing this server's version. If the server hasn't been started yet, GetVersion() returns an empty string.

◆ Kill()

virtual bool xorg::testing::XServer::Kill ( unsigned int  timeout = 2000)
virtual

Kills the server.

With a vengeance.

Parameters
[in]timeoutThe timeout in millis to wait for the process to terminate. A timeout of 0 implies not to wait but return immediately.
Returns
true if kill succeeded and, if a timout is given, the process shut down within that timeout. false otherwise.

Reimplemented from xorg::testing::Process.

◆ RegisterXErrorHandler()

static void xorg::testing::XServer::RegisterXErrorHandler ( )
static

Install a default XErrorHandler.

That error handler will cause a test failure if called.

This function is called automatically by XServer::Start(). Usually, you will not need to call this function unless your test does not instantiate and Start() an XServer object.

This function will only install a new error handler if the currently installed XErrorHandler is not the default handler used by Xlib.

◆ RegisterXIOErrorHandler()

static void xorg::testing::XServer::RegisterXIOErrorHandler ( )
static

Install a default XIOErrorHandler.

That error handler will throw an xorg::testing::XIOError when encountered.

This function is called automatically by XServer::Start(). Usually, you will not need to call this function unless your test does not instantiate and Start() an XServer object.

This function will only install a new error handler if the currently installed XIOErrorHandler is not the default handler used by Xlib.

◆ RemoveLogFile()

void xorg::testing::XServer::RemoveLogFile ( bool  force = false)

Remove the log file used by this server.

By default, this function only removes the log file if the server was terminated or finished with an exit code of 0.

If force is true, the log file is removed regardless of the state of the server.

Parameters
forceForce removal of the log file
Examples:
xorg-gtest-example.cpp.

◆ RemoveOption()

void xorg::testing::XServer::RemoveOption ( const std::string &  option)

Remove a previously set option.

If an option was set through SetOption(), remove the option again. If the specified option has never been set, do nothing.

Parameters
[in]optionCommandline option to remove

◆ SetDisplayNumber()

void xorg::testing::XServer::SetDisplayNumber ( unsigned int  display_number)

Set the display number for this server.

This number must be set before the server is started to have any effect. If unset, the default display number is used.

Parameters
[in]display_numberThe display number the server runs on

◆ SetOption()

void xorg::testing::XServer::SetOption ( const std::string &  key,
const std::string &  value = "" 
)

Set startup options for the server.

For arguments that do not take/need a value, use the empty string as value.

Parameters
[in]keyCommandline option
[in]valueOption value (if any)
Examples:
xorg-gtest-example.cpp.

◆ SetServerPath()

void xorg::testing::XServer::SetServerPath ( const std::string &  path_to_server)

Set the path to the server binary to be started.

Optional call, if not invoked the built-in default path is chosen.

Parameters
[in]path_to_serverThe path to the binary

◆ Start()

virtual void xorg::testing::XServer::Start ( const std::string &  program = "")
virtual

Start a new server.

If no binary is given, the server started is the default compiled-in server binary.

Parameters
[in]programPath to the XServer binary
Examples:
xorg-gtest-example.cpp.

◆ Terminate()

virtual bool xorg::testing::XServer::Terminate ( unsigned int  timeout = 2000)
virtual

Terminates this server process.

Will signal the server to terminate multiple times before giving up.

Parameters
[in]timeoutThe timeout in millis to wait for the process to terminate. A timeout of 0 implies not to wait but return immediately.
Returns
true if termination succeeded and, if a timout is given, the process shut down within that timeout. false otherwise.

Reimplemented from xorg::testing::Process.

Examples:
xorg-gtest-example.cpp.

◆ WaitForConnections()

_X_DEPRECATED void xorg::testing::XServer::WaitForConnections ( void  )

Waits until this server is ready to take connections.

◆ WaitForDevice()

static bool xorg::testing::XServer::WaitForDevice ( ::Display *  display,
const std::string &  name,
time_t  timeout = 1000 
)
static

Wait for a specific device to be added to the server.

Parameters
[in]displayThe X display connection
[in]nameThe name of the device to wait for
[in]timeoutThe timeout in milliseconds
Returns
Whether the device was added

◆ WaitForEvent()

static bool xorg::testing::XServer::WaitForEvent ( ::Display *  display,
time_t  timeout = 1000 
)
static

Wait for an event on the X connection.

Parameters
[in]displayThe X display connection
[in]timeoutThe timeout in milliseconds
Returns
Whether an event is available

◆ WaitForEventOfType()

static bool xorg::testing::XServer::WaitForEventOfType ( ::Display *  display,
int  type,
int  extension = -1,
int  evtype = -1,
time_t  timeout = 1000 
)
static

Wait for an event of a specific type on the X connection.

All events preceding the matching event are discarded. If no event was found before the timeout expires, all events in the queue will have been discarded.

Parameters
[in]displayThe X display connection
[in]typeThe X core protocol event type
[in]extensionThe X extension opcode of a generic event, or -1 for any generic event
[in]evtypeThe X extension event type of a generic event, or -1 for any event of the given extension
[in]timeoutThe timeout in milliseconds
Returns
Whether an event is available

The documentation for this class was generated from the following file: