[PATCH] dinput/tests: Add Reference counting test
Alistair Leslie-Hughes
leslie_alistair at hotmail.com
Wed Oct 23 21:27:53 CDT 2019
This test is to show the issue in
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=34635
Signed-off-by: Alistair Leslie-Hughes <leslie_alistair at hotmail.com>
---
dlls/dinput/tests/dinput.c | 60 ++++++++++++++++++++++++++++++++++++++
1 file changed, 60 insertions(+)
diff --git a/dlls/dinput/tests/dinput.c b/dlls/dinput/tests/dinput.c
index 5947b17468..79cd3abe40 100644
--- a/dlls/dinput/tests/dinput.c
+++ b/dlls/dinput/tests/dinput.c
@@ -500,6 +500,65 @@ static void test_GetDeviceStatus(void)
IDirectInput_Release(pDI);
}
+static inline LONG refcount(IUnknown *unk)
+{
+ LONG ref;
+ IUnknown_AddRef(unk);
+ ref = IUnknown_Release(unk);
+ return ref;
+}
+
+static void test_reference_count(void)
+{
+ IDirectInputA *pDI;
+ LONG ref;
+ HRESULT hr;
+ IDirectInputDeviceA *mouse = NULL;
+ IDirectInputDeviceA *keyboard = NULL;
+
+ hr = CoCreateInstance(&CLSID_DirectInput, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectInputA, (void **)&pDI);
+ if (FAILED(hr))
+ {
+ win_skip("Failed to instantiate a IDirectInputA instance: 0x%08x\n", hr);
+ return;
+ }
+
+ hr = IDirectInput_Initialize(pDI, hInstance, DIRECTINPUT_VERSION_700);
+ ok(SUCCEEDED(hr), "Failed: %08x\n", hr);
+
+ ref = refcount( (IUnknown*)pDI);
+ ok(ref == 1, "got: %d\n", ref);
+
+ hr = IDirectInput_CreateDevice(pDI, &GUID_SysMouse, &mouse, NULL);
+ ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %08x\n", hr);
+ if (FAILED(hr)) return;
+
+ ref = refcount( (IUnknown*)pDI);
+ todo_wine ok(ref == 1, "got: %d\n", ref);
+
+ ref = refcount( (IUnknown*)mouse);
+ ok(ref == 1, "got: %d\n", ref);
+
+ hr = IDirectInput_CreateDevice(pDI, &GUID_SysKeyboard, &keyboard, NULL);
+ ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %08x\n", hr);
+ if (FAILED(hr)) return;
+
+ ref = refcount( (IUnknown*)pDI);
+ todo_wine ok(ref == 1, "got: %d\n", ref);
+
+ ref = refcount( (IUnknown*)keyboard);
+ ok(ref == 1, "got: %d\n", ref);
+
+ ref = IUnknown_Release(keyboard);
+ ok(ref == 0, "got: %d\n", ref);
+
+ ref = IDirectInput_Release(pDI);
+ todo_wine ok(ref == 0, "got: %d\n", ref);
+
+ ref = IUnknown_Release(mouse);
+ ok(ref == 0, "got: %d\n", ref);
+}
+
static void test_Initialize(void)
{
IDirectInputA *pDI;
@@ -639,6 +698,7 @@ START_TEST(dinput)
test_EnumDevices();
test_GetDeviceStatus();
test_Initialize();
+ test_reference_count();
test_RunControlPanel();
test_DirectInputJoyConfig8();
CoUninitialize();
--
2.17.1
More information about the wine-devel
mailing list