These are examples for using xorg-gtest in tests and test fixtures.
These are examples for using xorg-gtest in tests and test fixtures.Please make sure that you have the X.org dummy display driver installed on your system and that you execute the test with root privileges.
Each of these tests starts a new server.
#include <xorg/gtest/xorg-gtest.h>
#include <sstream>
#include <X11/extensions/XInput2.h>
#include <X11/Xatom.h>
using namespace xorg::testing;
server.
SetOption(
"-logfile", LOGFILE_DIR
"/xserver-startserver.log");
server.
SetOption(
"-config", DUMMY_CONF_PATH);
ASSERT_EQ(server.
GetState(), Process::RUNNING);
ASSERT_EQ(server.
GetState(), Process::FINISHED_SUCCESS);
}
server.
SetOption(
"-logfile", LOGFILE_DIR
"/xserver-display-connection.log");
server.
SetOption(
"-config", DUMMY_CONF_PATH);
ASSERT_TRUE(dpy != NULL);
}
public:
virtual void SetUp(
void) {
const ::testing::TestInfo* const test_info =
::testing::UnitTest::GetInstance()->current_test_info();
std::stringstream log;
log << LOGFILE_DIR "/xserver-";
log << test_info->test_case_name() << "." << test_info->name();
log << ".log";
server.SetOption(
"-logfile", log.str());
server.SetOption(
"-config", DUMMY_CONF_PATH);
Test::SetDisplayString(
server.GetDisplayString());
ASSERT_NO_FATAL_FAILURE(Test::SetUp());
}
ASSERT_TRUE(
server.Terminate());
}
protected:
};
ASSERT_GT(DisplayWidth(Display(), 0), 0);
}
ASSERT_GT(DisplayHeight(Display(), 0), 0);
}
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
Example for a test fixture that starts a server per test.
Definition: xorg-gtest-example.cpp:60
virtual void TearDown(void)
Closes the display.
Definition: xorg-gtest-example.cpp:82
virtual void SetUp(void)
Tries to connect to an X server instance.
Definition: xorg-gtest-example.cpp:62
XServer server
The X server instance.
Definition: xorg-gtest-example.cpp:88
enum Process::State GetState()
Return the state of the process.
Google Test fixture providing an Xlib connection to an X11 server.
Definition: xorg-gtest-test.h:52
Class representing the X server process.
Definition: xorg-gtest-xserver.h:80
virtual bool Terminate(unsigned int timeout=2000)
Terminates this server process.
void RemoveLogFile(bool force=false)
Remove the log file used by this server.
const std::string & GetDisplayString(void)
Get the display string that may be used for XOpenDisplay to this server.
void SetOption(const std::string &key, const std::string &value="")
Set startup options for the server.
virtual void Start(const std::string &program="")
Start a new server.