test: fix the xtest device test to show the dependency

These two tests were dependent on each other, the second test relied on
the xtest devices created in the first test. Let's move the bits that
are shared out into the main function instead to illustrate this better.

This lets us add a call to CloseDownDevices() that will remove the leaks
in this set of tests.

(cherry picked from commit b6931f2f5f)
This commit is contained in:
Peter Hutterer 2024-01-04 12:30:20 +10:00
parent 67ef0f0834
commit ed4a6bdff6

View file

@ -62,34 +62,6 @@ device_cursor_cleanup(DeviceIntPtr dev, ScreenPtr screen)
static void
xtest_init_devices(void)
{
ScreenRec screen = {0};
ClientRec server_client = {0};
WindowRec root = {{0}};
WindowOptRec optional = {0};
/* random stuff that needs initialization */
root.drawable.id = 0xab;
root.optional = &optional;
screen.root = &root;
screenInfo.numScreens = 1;
screenInfo.screens[0] = &screen;
screen.myNum = 0;
screen.id = 100;
screen.width = 640;
screen.height = 480;
screen.DeviceCursorInitialize = device_cursor_init;
screen.DeviceCursorCleanup = device_cursor_cleanup;
dixResetPrivates();
serverClient = &server_client;
InitClient(serverClient, 0, (void *) NULL);
if (!InitClientResources(serverClient)) /* for root resources */
FatalError("couldn't init server resources");
InitAtoms();
SyncExtensionInit();
/* this also inits the xtest devices */
InitCoreDevices();
assert(xtestpointer);
assert(xtestkeyboard);
assert(IsXTestDevice(xtestpointer, NULL));
@ -135,8 +107,38 @@ xtest_properties(void)
int
xtest_test(void)
{
ScreenRec screen = {0};
ClientRec server_client = {0};
WindowRec root = {{0}};
WindowOptRec optional = {0};
/* random stuff that needs initialization */
root.drawable.id = 0xab;
root.optional = &optional;
screen.root = &root;
screenInfo.numScreens = 1;
screenInfo.screens[0] = &screen;
screen.myNum = 0;
screen.id = 100;
screen.width = 640;
screen.height = 480;
screen.DeviceCursorInitialize = device_cursor_init;
screen.DeviceCursorCleanup = device_cursor_cleanup;
dixResetPrivates();
serverClient = &server_client;
InitClient(serverClient, 0, (void *) NULL);
if (!InitClientResources(serverClient)) /* for root resources */
FatalError("couldn't init server resources");
InitAtoms();
SyncExtensionInit();
/* this also inits the xtest devices */
InitCoreDevices();
xtest_init_devices();
xtest_properties();
CloseDownDevices();
return 0;
}