This is an example for using the fixture xorg::testing::Test for your own tests, using the xorg::testing::Environment to start up a server.
This is an example for using the fixture xorg::testing::Test for your own tests, using the xorg::testing::Environment to start up a server.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.
The xorg::testing::Environment starts up one server before the test execution, that server is alive during all tests until the end of the test suite. For options on controlling that server run this test with –help, the configuration path, display number can be controlled by the caller.
Note that the test environment (i.e. the X server instance) is shared between tests. If the tests are the only client connection, the server will trigger a regeneration when the test finishes with Test::TearDown(). If more than one client connection is active however, this regeneration will not happen and changes made by one test can affect outcomes on other tests.
This test is missing a main(), we pull that in from xorg-gtest-main.cpp
#include <xorg/gtest/xorg-gtest.h>
#include <X11/extensions/XInput2.h>
#include <X11/Xatom.h>
using namespace xorg::testing;
TEST_F(
Test, DummyXorgServerTest) {
EXPECT_NE((Window)None, DefaultRootWindow(Display()));
}
TEST_F(
Test, XIQueryVersion20) {
int major = 2, minor = 0;
ASSERT_EQ(Success, XIQueryVersion(Display(), &major, &minor));
ASSERT_GE(major * 100 + minor, 200);
}
TEST_F(
Test, XIQueryVersion22) {
int major = 2, minor = 2;
ASSERT_EQ(Success, XIQueryVersion(Display(), &major, &minor));
ASSERT_EQ(major * 100 + minor, 202);
}
TEST_F(
Test, CreateWindowProperty) {
Atom prop = XInternAtom(Display(), "xorg-gtest test atom", False);
ASSERT_NE((Atom)None, prop);
unsigned char data = 1;
XChangeProperty(Display(), DefaultRootWindow(Display()), prop,
XA_INTEGER, 8, PropModeReplace, &data, 1);
XFlush(Display());
}
TEST_F(
Test, CheckWindowProperty) {
Atom prop = XInternAtom(Display(), "xorg-gtest test atom", True);
ASSERT_EQ((Atom)None, prop) << "Property did not get removed, some client prevented regeneration";
}
public:
virtual void SetUp(
void) {
Test::SetUp();
}
protected:
};
ASSERT_NE((Atom)None, example_prop);
}
Example class for how to subclass tests.
Definition: xorg-gtest-environment-example.cpp:84
Atom example_prop
Example property that we'll use in the test.
Definition: xorg-gtest-environment-example.cpp:95
virtual void SetUp(void)
Tries to connect to an X server instance.
Definition: xorg-gtest-environment-example.cpp:86
Google Test fixture providing an Xlib connection to an X11 server.
Definition: xorg-gtest-test.h:52
::Display * Display() const
Accesses the display representing an Xlib connection.