dinput: Test that upload, unacquire, acquire still permits updating uploaded effect.
Vincent Pelletier
plr.vincent at gmail.com
Tue Jan 20 17:15:18 CST 2009
Kudos to Daniel Remenak for his help.
--
Vincent Pelletier
-------------- next part --------------
From 7ae6931431ea32e6fd47d243fdf6542b6c604e32 Mon Sep 17 00:00:00 2001
From: Vincent Pelletier <plr.vincent at gmail.com>
Date: Tue, 20 Jan 2009 23:57:20 +0100
Subject: Test that upload, unacquire, acquire still permits updating uploaded effect.
---
dlls/dinput/tests/joystick.c | 48 ++++++++++++++++++++++++++++++++++++++++++
1 files changed, 48 insertions(+), 0 deletions(-)
diff --git a/dlls/dinput/tests/joystick.c b/dlls/dinput/tests/joystick.c
index b318323..77cfa4c 100644
--- a/dlls/dinput/tests/joystick.c
+++ b/dlls/dinput/tests/joystick.c
@@ -328,6 +328,8 @@ static BOOL CALLBACK EnumJoysticks(
DIEFFECT eff;
LPDIRECTINPUTEFFECT effect = NULL;
LONG cnt1, cnt2;
+ HWND real_hWnd;
+ HINSTANCE hInstance = GetModuleHandle(NULL);
trace("Testing force-feedback\n");
memset(&eff, 0, sizeof(eff));
@@ -342,6 +344,25 @@ static BOOL CALLBACK EnumJoysticks(
eff.cbTypeSpecificParams = sizeof(force);
eff.lpvTypeSpecificParams = &force;
+ /* Sending effects to joystick requires
+ * calling IDirectInputEffect_Initialize, which requires
+ * having exclusive access to the device, which requires
+ * - not having acquired the joystick when calling
+ * IDirectInputDevice_SetCooperativeLevel
+ * - a visible window
+ */
+ real_hWnd = CreateWindowEx(0, "EDIT", "Test text", 0, 10, 10, 300,
+ 300, NULL, NULL, hInstance, NULL);
+ ok(real_hWnd!=0,"CreateWindowEx failed: %p\n", real_hWnd);
+ ShowWindow(real_hWnd, SW_SHOW);
+ hr = IDirectInputDevice_Unacquire(pJoystick);
+ ok(hr==DI_OK,"IDirectInputDevice_Unacquire() failed: %08x\n", hr);
+ hr = IDirectInputDevice_SetCooperativeLevel(pJoystick, real_hWnd,
+ DISCL_EXCLUSIVE | DISCL_FOREGROUND);
+ ok(hr==DI_OK,"IDirectInputDevice_SetCooperativeLevel() failed: %08x\n", hr);
+ hr = IDirectInputDevice_Acquire(pJoystick);
+ ok(hr==DI_OK,"IDirectInputDevice_Acquire() failed: %08x\n", hr);
+
cnt1 = get_refcount((IUnknown*)pJoystick);
hr = IDirectInputDevice2_CreateEffect((LPDIRECTINPUTDEVICE2)pJoystick, &GUID_ConstantForce,
@@ -352,11 +373,38 @@ static BOOL CALLBACK EnumJoysticks(
if (effect)
{
+ hr = IDirectInputEffect_Initialize(effect, hInstance, DIRECTINPUT_VERSION,
+ &GUID_ConstantForce);
+ ok(hr==DI_OK,"IDirectInputEffect_Initialize failed: %08x\n", hr);
+ hr = IDirectInputEffect_SetParameters(effect, &eff, DIEP_AXES | DIEP_DIRECTION |
+ DIEP_TYPESPECIFICPARAMS);
+ ok(hr==DI_OK,"IDirectInputEffect_SetParameters failed: %08x\n", hr);
+ if (hr==DI_OK) {
+ /* Test that upload, unacquire, acquire still permits updating
+ * uploaded effect. */
+ hr = IDirectInputDevice_Unacquire(pJoystick);
+ ok(hr==DI_OK,"IDirectInputDevice_Unacquire() failed: %08x\n", hr);
+ hr = IDirectInputDevice_Acquire(pJoystick);
+ ok(hr==DI_OK,"IDirectInputDevice_Acquire() failed: %08x\n", hr);
+ hr = IDirectInputEffect_SetParameters(effect, &eff, DIEP_GAIN);
+ todo_wine ok(hr==DI_OK,"IDirectInputEffect_SetParameters failed: %08x\n", hr);
+ }
ref = IUnknown_Release(effect);
ok(ref == 0, "IDirectInputDevice_Release() reference count = %d\n", ref);
}
cnt1 = get_refcount((IUnknown*)pJoystick);
ok(cnt1 == cnt2, "Ref count is wrong %d != %d\n", cnt1, cnt2);
+
+ /* Before destroying the window, release joystick to revert to
+ * non-exclusive, background cooperative level. */
+ hr = IDirectInputDevice_Unacquire(pJoystick);
+ ok(hr==DI_OK,"IDirectInputDevice_Unacquire() failed: %08x\n", hr);
+ hr = IDirectInputDevice_SetCooperativeLevel(pJoystick, hWnd,
+ DISCL_NONEXCLUSIVE | DISCL_BACKGROUND);
+ ok(hr==DI_OK,"IDirectInputDevice_SetCooperativeLevel() failed: %08x\n", hr);
+ DestroyWindow (real_hWnd);
+ hr = IDirectInputDevice_Acquire(pJoystick);
+ ok(hr==DI_OK,"IDirectInputDevice_Acquire() failed: %08x\n", hr);
}
if (winetest_interactive) {
--
1.5.6.5
More information about the wine-patches
mailing list