From b6931f2f5fab52dbb0c09e02ebb8315b3516e01b Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 4 Jan 2024 12:30:20 +1000 Subject: [PATCH] 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. --- test/xtest.c | 58 +++++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/test/xtest.c b/test/xtest.c index 12433afc4..171f285f6 100644 --- a/test/xtest.c +++ b/test/xtest.c @@ -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; }