~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/dlls/dinput/tests/joystick.c

Version: ~ [ wine-1.1.3 ] ~ [ wine-1.1.2 ] ~ [ wine-1.1.1 ] ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~ [ wine-1.0-rc5 ] ~ [ wine-1.0-rc4 ] ~ [ wine-1.0-rc3 ] ~ [ wine-1.0-rc2 ] ~ [ wine-1.0-rc1 ] ~ [ wine-0.9.61 ] ~ [ wine-0.9.60 ] ~ [ wine-0.9.59 ] ~ [ wine-0.9.58 ] ~ [ wine-0.9.57 ] ~ [ wine-0.9.56 ] ~ [ wine-0.9.55 ] ~ [ wine-0.9.54 ] ~ [ wine-0.9.53 ] ~ [ wine-0.9.52 ] ~ [ wine-0.9.51 ] ~ [ wine-0.9.50 ] ~ [ wine-0.9.49 ] ~ [ wine-0.9.48 ] ~ [ wine-0.9.47 ] ~ [ wine-0.9.46 ] ~ [ wine-0.9.45 ] ~ [ wine-0.9.44 ] ~ [ wine-0.9.43 ] ~ [ wine-0.9.42 ] ~ [ wine-0.9.41 ] ~ [ wine-0.9.40 ] ~ [ wine-0.9.39 ] ~ [ wine-0.9.38 ] ~ [ wine-0.9.37 ] ~ [ wine-0.9.36 ] ~ [ wine-0.9.35 ] ~ [ wine-0.9.34 ] ~ [ wine-0.9.33 ] ~ [ wine-0.9.32 ] ~ [ wine-0.9.31 ] ~ [ wine-0.9.30 ] ~ [ wine-0.9.29 ] ~ [ wine-0.9.28 ] ~ [ wine-0.9.27 ] ~ [ wine-0.9.26 ] ~ [ wine-0.9.25 ] ~ [ wine-0.9.24 ] ~ [ wine-0.9.23 ] ~ [ wine-0.9.22 ] ~ [ wine-0.9.21 ] ~ [ wine-0.9.20 ] ~ [ wine-0.9.19 ] ~ [ wine-0.9.18 ] ~ [ wine-0.9.17 ] ~ [ wine-0.9.16 ] ~ [ wine-0.9.15 ] ~ [ wine-0.9.14 ] ~ [ wine-0.9.13 ] ~ [ wine-0.9.12 ] ~ [ wine-0.9.11 ] ~ [ wine-0.9.10 ] ~ [ wine-0.9.9 ] ~ [ wine-0.9.8 ] ~ [ wine-0.9.7 ] ~ [ wine-0.9.6 ] ~ [ wine-0.9.5 ] ~ [ wine-0.9.4 ] ~ [ wine-0.9.3 ] ~ [ wine-0.9.2 ] ~ [ wine-0.9.1 ] ~ [ wine-0.9 ] ~ [ wine20050930 ] ~ [ wine20050830 ] ~ [ wine20050725 ] ~ [ wine20050628 ] ~ [ wine20050524 ] ~ [ wine20050419 ] ~ [ wine20050310 ] ~ [ wine20050211 ] ~ [ wine20050111 ] ~ [ wine20041201 ] ~ [ wine20041019 ] ~ [ wine20040914 ] ~ [ wine20040813 ] ~ [ wine20040716 ] ~ [ wine20040615 ] ~ [ wine20040505 ] ~ [ wine20040408 ] ~ [ wine20040309 ] ~ [ wine20040213 ] ~ [ wine20040121 ] ~ [ wine20031212 ] ~ [ wine20031118 ] ~ [ wine20031016 ] ~ [ wine20030911 ] ~ [ wine20030813 ] ~ [ wine20030709 ] ~ [ wine20030618 ] ~ [ wine20030508 ] ~ [ wine20030408 ] ~ [ wine20030318 ] ~ [ wine20030219 ] ~ [ wine20030115 ] ~ [ wine20021219 ] ~ [ wine20021125 ] ~ [ wine20021031 ] ~ [ wine20021007 ] ~ [ wine20020904 ] ~ [ wine20020804 ] ~ [ wine20020710 ] ~ [ wine20020605 ] ~ [ wine20020509 ] ~ [ wine20020411 ] ~ [ wine20020310 ] ~ [ wine20020228 ] ~ [ wine20011226 ] ~ [ wine20011108 ] ~ [ wine20011004 ] ~ [ wine20010824 ] ~ [ wine20010731 ] ~ [ wine20010629 ] ~ [ wine20010510 ] ~ [ wine20010418 ] ~ [ wine20010326 ] ~ [ wine20010305 ] ~ [ wine20010216 ] ~ [ wine20010112 ] ~ [ wine20001222 ] ~ [ wine20001202 ] ~ [ wine20001026 ] ~ [ wine20001002 ] ~ [ wine20000909 ] ~ [ wine20000821 ] ~ [ wine20000801 ] ~ [ wine20000716 ] ~ [ wine20000326 ] ~ [ wine20000227 ] ~ [ wine20000130 ] ~ [ wine20000109 ] ~

  1 /*
  2  * Copyright (c) 2004-2005 Robert Reif
  3  *
  4  * This library is free software; you can redistribute it and/or
  5  * modify it under the terms of the GNU Lesser General Public
  6  * License as published by the Free Software Foundation; either
  7  * version 2.1 of the License, or (at your option) any later version.
  8  *
  9  * This library is distributed in the hope that it will be useful,
 10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 12  * Lesser General Public License for more details.
 13  *
 14  * You should have received a copy of the GNU Lesser General Public
 15  * License along with this library; if not, write to the Free Software
 16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 17  */
 18 
 19 #define DIRECTINPUT_VERSION 0x0700
 20 
 21 #define COBJMACROS
 22 #include <windows.h>
 23 
 24 #include <math.h>
 25 #include <stdio.h>
 26 #include <stdlib.h>
 27 
 28 #include "wine/test.h"
 29 #include "windef.h"
 30 #include "wingdi.h"
 31 #include "dinput.h"
 32 #include "dinput_test.h"
 33 
 34 #define numObjects(x) (sizeof(x) / sizeof(x[0]))
 35 
 36 typedef struct tagUserData {
 37     LPDIRECTINPUT pDI;
 38     DWORD version;
 39 } UserData;
 40 
 41 static const DIOBJECTDATAFORMAT dfDIJoystickTest[] = {
 42   { &GUID_XAxis,DIJOFS_X,DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0},
 43   { &GUID_YAxis,DIJOFS_Y,DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0},
 44   { &GUID_ZAxis,DIJOFS_Z,DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0},
 45   { &GUID_RxAxis,DIJOFS_RX,DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0},
 46   { &GUID_RyAxis,DIJOFS_RY,DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0},
 47   { &GUID_RzAxis,DIJOFS_RZ,DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0},
 48   { &GUID_Button,DIJOFS_BUTTON(0),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
 49   { &GUID_Button,DIJOFS_BUTTON(1),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
 50   { &GUID_Button,DIJOFS_BUTTON(2),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
 51   { &GUID_Button,DIJOFS_BUTTON(3),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
 52   { &GUID_Button,DIJOFS_BUTTON(4),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
 53   { &GUID_Button,DIJOFS_BUTTON(5),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
 54   { &GUID_Button,DIJOFS_BUTTON(6),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
 55   { &GUID_Button,DIJOFS_BUTTON(7),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
 56   { &GUID_Button,DIJOFS_BUTTON(8),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
 57   { &GUID_Button,DIJOFS_BUTTON(9),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
 58   { &GUID_Button,DIJOFS_BUTTON(10),DIDFT_OPTIONAL|DIDFT_BUTTON|DIDFT_ANYINSTANCE,0},
 59 };
 60 
 61 static const DIDATAFORMAT c_dfDIJoystickTest = {
 62     sizeof(DIDATAFORMAT),
 63     sizeof(DIOBJECTDATAFORMAT),
 64     DIDF_ABSAXIS,
 65     sizeof(DIJOYSTATE2),
 66     numObjects(dfDIJoystickTest),
 67     (LPDIOBJECTDATAFORMAT)dfDIJoystickTest
 68 };
 69 
 70 static HWND get_hwnd(void)
 71 {
 72     HWND hwnd=GetForegroundWindow();
 73     if (!hwnd)
 74         hwnd=GetDesktopWindow();
 75     return hwnd;
 76 }
 77 
 78 typedef struct tagJoystickInfo
 79 {
 80     LPDIRECTINPUTDEVICE pJoystick;
 81     DWORD axis;
 82     DWORD pov;
 83     DWORD button;
 84     LONG  lMin, lMax;
 85     DWORD dZone;
 86 } JoystickInfo;
 87 
 88 static int get_refcount(IUnknown *object)
 89 {
 90     IUnknown_AddRef( object );
 91     return IUnknown_Release( object );
 92 }
 93 
 94 static BOOL CALLBACK EnumAxes(
 95     const DIDEVICEOBJECTINSTANCE* pdidoi,
 96     VOID* pContext)
 97 {
 98     HRESULT hr;
 99     JoystickInfo * info = (JoystickInfo *)pContext;
100 
101     if (IsEqualIID(&pdidoi->guidType, &GUID_XAxis) ||
102         IsEqualIID(&pdidoi->guidType, &GUID_YAxis) ||
103         IsEqualIID(&pdidoi->guidType, &GUID_ZAxis) ||
104         IsEqualIID(&pdidoi->guidType, &GUID_RxAxis) ||
105         IsEqualIID(&pdidoi->guidType, &GUID_RyAxis) ||
106         IsEqualIID(&pdidoi->guidType, &GUID_RzAxis) ||
107         IsEqualIID(&pdidoi->guidType, &GUID_Slider))
108     {
109         DIPROPRANGE diprg;
110         DIPROPDWORD dipdw;
111 
112         diprg.diph.dwSize       = sizeof(DIPROPRANGE);
113         diprg.diph.dwHeaderSize = sizeof(DIPROPHEADER);
114         diprg.diph.dwHow        = DIPH_BYID;
115         diprg.diph.dwObj        = pdidoi->dwType;
116 
117         dipdw.diph.dwSize       = sizeof(dipdw);
118         dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
119         dipdw.diph.dwHow        = DIPH_BYID;
120         dipdw.diph.dwObj        = pdidoi->dwType;
121 
122         hr = IDirectInputDevice_GetProperty(info->pJoystick, DIPROP_RANGE, &diprg.diph);
123         ok(SUCCEEDED(hr), "IDirectInputDevice_GetProperty() failed: %08x\n", hr);
124         ok(info->lMin == diprg.lMin && info->lMax == diprg.lMax, "Min/Max range invalid: "
125            "expected %d..%d got %d..%d\n", info->lMin, info->lMax, diprg.lMin, diprg.lMax);
126 
127         diprg.lMin = -2000;
128         diprg.lMax = +2000;
129 
130         hr = IDirectInputDevice_SetProperty(info->pJoystick, DIPROP_RANGE, NULL);
131         ok(hr==E_INVALIDARG,"IDirectInputDevice_SetProperty() should have returned "
132            "E_INVALIDARG, returned: %08x\n", hr);
133 
134         hr = IDirectInputDevice_SetProperty(info->pJoystick, DIPROP_RANGE, &diprg.diph);
135         ok(hr==DI_OK,"IDirectInputDevice_SetProperty() failed: %08x\n", hr);
136 
137         /* dead zone */
138         hr = IDirectInputDevice_GetProperty(info->pJoystick, DIPROP_DEADZONE, &dipdw.diph);
139         ok(SUCCEEDED(hr), "IDirectInputDevice_GetProperty() failed: %08x\n", hr);
140         ok(info->dZone == dipdw.dwData, "deadzone invalid: expected %d got %d\n",
141            info->dZone, dipdw.dwData);
142 
143         dipdw.dwData = 123;
144 
145         hr = IDirectInputDevice_SetProperty(info->pJoystick, DIPROP_DEADZONE, &dipdw.diph);
146         ok(hr==DI_OK,"IDirectInputDevice_SetProperty() failed: %08x\n", hr);
147 
148         info->axis++;
149     } else if (IsEqualIID(&pdidoi->guidType, &GUID_POV))
150         info->pov++;
151     else if (IsEqualIID(&pdidoi->guidType, &GUID_Button))
152         info->button++;
153 
154     return DIENUM_CONTINUE;
155 }
156 
157 static const HRESULT SetCoop_null_window[16] =  {
158     E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG,
159     E_INVALIDARG, E_HANDLE,     E_HANDLE,     E_INVALIDARG,
160     E_INVALIDARG, E_HANDLE,     S_OK,         E_INVALIDARG,
161     E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG};
162 
163 static const HRESULT SetCoop_real_window[16] =  {
164     E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG,
165     E_INVALIDARG, S_OK,         S_OK,         E_INVALIDARG,
166     E_INVALIDARG, S_OK,         S_OK,         E_INVALIDARG,
167     E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG};
168 
169 static BOOL CALLBACK EnumJoysticks(
170     LPCDIDEVICEINSTANCE lpddi,
171     LPVOID pvRef)
172 {
173     HRESULT hr;
174     UserData * data = (UserData *)pvRef;
175     LPDIRECTINPUTDEVICE pJoystick;
176     DIDATAFORMAT format;
177     DIDEVCAPS caps;
178     DIJOYSTATE2 js;
179     JoystickInfo info;
180     int i, count;
181     ULONG ref;
182     DIDEVICEINSTANCE inst;
183     DIDEVICEINSTANCE_DX3 inst3;
184     HWND hWnd = get_hwnd();
185     char oldstate[248], curstate[248];
186 
187     ok(data->version > 0x0300, "Joysticks not supported in version 0x%04x\n", data->version);
188  
189     hr = IDirectInput_CreateDevice(data->pDI, &lpddi->guidInstance, NULL, NULL);
190     ok(hr==E_POINTER,"IDirectInput_CreateDevice() should have returned "
191        "E_POINTER, returned: %08x\n", hr);
192 
193     hr = IDirectInput_CreateDevice(data->pDI, NULL, &pJoystick, NULL);
194     ok(hr==E_POINTER,"IDirectInput_CreateDevice() should have returned "
195        "E_POINTER, returned: %08x\n", hr);
196 
197     hr = IDirectInput_CreateDevice(data->pDI, NULL, NULL, NULL);
198     ok(hr==E_POINTER,"IDirectInput_CreateDevice() should have returned "
199        "E_POINTER, returned: %08x\n", hr);
200 
201     hr = IDirectInput_CreateDevice(data->pDI, &lpddi->guidInstance,
202                                    &pJoystick, NULL);
203     ok(hr==DI_OK,"IDirectInput_CreateDevice() failed: %08x\n", hr);
204     if (hr!=DI_OK)
205         goto DONE;
206 
207     trace("---- %s ----\n", lpddi->tszProductName);
208 
209     hr = IDirectInputDevice_SetDataFormat(pJoystick, NULL);
210     ok(hr==E_POINTER,"IDirectInputDevice_SetDataFormat() should have returned "
211        "E_POINTER, returned: %08x\n", hr);
212 
213     ZeroMemory(&format, sizeof(format));
214     hr = IDirectInputDevice_SetDataFormat(pJoystick, &format);
215     ok(hr==DIERR_INVALIDPARAM,"IDirectInputDevice_SetDataFormat() should have "
216        "returned DIERR_INVALIDPARAM, returned: %08x\n", hr);
217 
218     /* try the default formats */
219     hr = IDirectInputDevice_SetDataFormat(pJoystick, &c_dfDIJoystick);
220     ok(hr==DI_OK,"IDirectInputDevice_SetDataFormat() failed: %08x\n", hr);
221 
222     hr = IDirectInputDevice_SetDataFormat(pJoystick, &c_dfDIJoystick2);
223     ok(hr==DI_OK,"IDirectInputDevice_SetDataFormat() failed: %08x\n", hr);
224 
225     /* try an alternate format */
226     hr = IDirectInputDevice_SetDataFormat(pJoystick, &c_dfDIJoystickTest);
227     ok(hr==DI_OK,"IDirectInputDevice_SetDataFormat() failed: %08x\n", hr);
228 
229     hr = IDirectInputDevice_SetDataFormat(pJoystick, &c_dfDIJoystick2);
230     ok(hr==DI_OK,"IDirectInputDevice_SetDataFormat() failed: %08x\n", hr);
231     if (hr != DI_OK)
232         goto RELEASE;
233 
234     for (i=0; i<16; i++)
235     {
236         hr = IDirectInputDevice_SetCooperativeLevel(pJoystick, NULL, i);
237         ok(hr == SetCoop_null_window[i], "SetCooperativeLevel(NULL, %d): %08x\n", i, hr);
238     }
239     for (i=0; i<16; i++)
240     {
241         hr = IDirectInputDevice_SetCooperativeLevel(pJoystick, hWnd, i);
242         ok(hr == SetCoop_real_window[i], "SetCooperativeLevel(hwnd, %d): %08x\n", i, hr);
243     }
244 
245     hr = IDirectInputDevice_SetCooperativeLevel(pJoystick, hWnd,
246                                                 DISCL_NONEXCLUSIVE | DISCL_BACKGROUND);
247     ok(hr==DI_OK,"IDirectInputDevice_SetCooperativeLevel() failed: %08x\n", hr);
248 
249     /* get capabilities */
250     hr = IDirectInputDevice_GetCapabilities(pJoystick, NULL);
251     ok(hr==E_POINTER,"IDirectInputDevice_GetCapabilities() "
252        "should have returned E_POINTER, returned: %08x\n", hr);
253 
254     ZeroMemory(&caps, sizeof(caps));
255     hr = IDirectInputDevice_GetCapabilities(pJoystick, &caps);
256     ok(hr==DIERR_INVALIDPARAM,"IDirectInputDevice_GetCapabilities() "
257        "should have returned DIERR_INVALIDPARAM, returned: %08x\n", hr);
258 
259     caps.dwSize = sizeof(caps);
260     hr = IDirectInputDevice_GetCapabilities(pJoystick, &caps);
261     ok(hr==DI_OK,"IDirectInputDevice_GetCapabilities() failed: %08x\n", hr);
262 
263     ZeroMemory(&info, sizeof(info));
264     info.pJoystick = pJoystick;
265 
266     /* default min/max limits */
267     info.lMin = 0;
268     info.lMax = 0xffff;
269     /* enumerate objects */
270     hr = IDirectInputDevice_EnumObjects(pJoystick, EnumAxes, (VOID*)&info, DIDFT_ALL);
271     ok(hr==DI_OK,"IDirectInputDevice_EnumObjects() failed: %08x\n", hr);
272 
273     ok(caps.dwAxes == info.axis, "Number of enumerated axes (%d) doesn't match capabilities (%d)\n", info.axis, caps.dwAxes);
274     ok(caps.dwButtons == info.button, "Number of enumerated buttons (%d) doesn't match capabilities (%d)\n", info.button, caps.dwButtons);
275     ok(caps.dwPOVs == info.pov, "Number of enumerated POVs (%d) doesn't match capabilities (%d)\n", info.pov, caps.dwPOVs);
276 
277     /* Set format and check limits again */
278     hr = IDirectInputDevice_SetDataFormat(pJoystick, &c_dfDIJoystick2);
279     ok(hr==DI_OK,"IDirectInputDevice_SetDataFormat() failed: %08x\n", hr);
280     info.lMin = -2000;
281     info.lMax = +2000;
282     info.dZone= 123;
283     hr = IDirectInputDevice_EnumObjects(pJoystick, EnumAxes, (VOID*)&info, DIDFT_ALL);
284     ok(hr==DI_OK,"IDirectInputDevice_EnumObjects() failed: %08x\n", hr);
285 
286     hr = IDirectInputDevice_GetDeviceInfo(pJoystick, 0);
287     ok(hr==E_POINTER, "IDirectInputDevice_GetDeviceInfo() "
288        "should have returned E_POINTER, returned: %08x\n", hr);
289 
290     ZeroMemory(&inst, sizeof(inst));
291     ZeroMemory(&inst3, sizeof(inst3));
292 
293     hr = IDirectInputDevice_GetDeviceInfo(pJoystick, &inst);
294     ok(hr==DIERR_INVALIDPARAM, "IDirectInputDevice_GetDeviceInfo() "
295        "should have returned DIERR_INVALIDPARAM, returned: %08x\n", hr);
296 
297     inst.dwSize = sizeof(inst);
298     hr = IDirectInputDevice_GetDeviceInfo(pJoystick, &inst);
299     ok(hr==DI_OK,"IDirectInputDevice_GetDeviceInfo() failed: %08x\n", hr);
300 
301     inst3.dwSize = sizeof(inst3);
302     hr = IDirectInputDevice_GetDeviceInfo(pJoystick, (LPDIDEVICEINSTANCE)&inst3);
303     ok(hr==DI_OK,"IDirectInputDevice_GetDeviceInfo() failed: %08x\n", hr);
304 
305     hr = IDirectInputDevice_Unacquire(pJoystick);
306     ok(hr == S_FALSE, "IDirectInputDevice_Unacquire() should have returned S_FALSE, got: %08x\n", hr);
307 
308     hr = IDirectInputDevice_Acquire(pJoystick);
309     ok(hr==DI_OK,"IDirectInputDevice_Acquire() failed: %08x\n", hr);
310     if (hr != DI_OK)
311         goto RELEASE;
312 
313     hr = IDirectInputDevice_Acquire(pJoystick);
314     ok(hr == S_FALSE, "IDirectInputDevice_Acquire() should have returned S_FALSE, got: %08x\n", hr);
315 
316     if (info.pov < 4)
317     {
318         hr = IDirectInputDevice_GetDeviceState(pJoystick, sizeof(DIJOYSTATE2), &js);
319         ok(hr == DI_OK, "IDirectInputDevice_GetDeviceState() failed: %08x\n", hr);
320         ok(js.rgdwPOV[3] == -1, "Default for unassigned POV should be -1 not: %d\n", js.rgdwPOV[3]);
321     }
322 
323     if (caps.dwFlags & DIDC_FORCEFEEDBACK)
324     {
325         DWORD axes[2] = {DIJOFS_X, DIJOFS_Y};
326         LONG  direction[2] = {0, 0};
327         DICONSTANTFORCE force = {0};
328         DIEFFECT eff;
329         LPDIRECTINPUTEFFECT effect = NULL;
330         LONG cnt1, cnt2;
331 
332         trace("Testing force-feedback\n");
333         memset(&eff, 0, sizeof(eff));
334         eff.dwSize                = sizeof(eff);
335         eff.dwFlags               = DIEFF_CARTESIAN | DIEFF_OBJECTOFFSETS;
336         eff.dwDuration            = INFINITE;
337         eff.dwGain                = DI_FFNOMINALMAX;
338         eff.dwTriggerButton       = DIEB_NOTRIGGER;
339         eff.cAxes                 = sizeof(axes) / sizeof(axes[0]);
340         eff.rgdwAxes              = axes;
341         eff.rglDirection          = direction;
342         eff.cbTypeSpecificParams  = sizeof(force);
343         eff.lpvTypeSpecificParams = &force;
344 
345         cnt1 = get_refcount((IUnknown*)pJoystick);
346 
347         hr = IDirectInputDevice2_CreateEffect((LPDIRECTINPUTDEVICE2)pJoystick, &GUID_ConstantForce,
348                                               &eff, &effect, NULL);
349         ok(hr == DI_OK, "IDirectInputDevice_CreateEffect() failed: %08x\n", hr);
350         cnt2 = get_refcount((IUnknown*)pJoystick);
351         ok(cnt1 == cnt2, "Ref count is wrong %d != %d\n", cnt1, cnt2);
352 
353         if (effect)
354         {
355             ref = IUnknown_Release(effect);
356             ok(ref == 0, "IDirectInputDevice_Release() reference count = %d\n", ref);
357         }
358         cnt1 = get_refcount((IUnknown*)pJoystick);
359         ok(cnt1 == cnt2, "Ref count is wrong %d != %d\n", cnt1, cnt2);
360     }
361 
362     if (winetest_interactive) {
363         trace("You have 30 seconds to test all axes, sliders, POVs and buttons\n");
364         count = 300;
365     } else
366         count = 1;
367 
368     trace("\n");
369     oldstate[0]='\0';
370     for (i = 0; i < count; i++) {
371         hr = IDirectInputDevice_GetDeviceState(pJoystick, sizeof(DIJOYSTATE2), &js);
372         ok(hr==DI_OK,"IDirectInputDevice_GetDeviceState() failed: %08x\n", hr);
373         if (hr != DI_OK)
374             break;
375         sprintf(curstate, "X%5d Y%5d Z%5d Rx%5d Ry%5d Rz%5d "
376               "S0%5d S1%5d POV0%5d POV1%5d POV2%5d POV3%5d "
377               "B %d %d %d %d %d %d %d %d %d %d %d %d\n",
378               js.lX, js.lY, js.lZ, js.lRx, js.lRy, js.lRz,
379               js.rglSlider[0], js.rglSlider[1],
380               js.rgdwPOV[0], js.rgdwPOV[1], js.rgdwPOV[2], js.rgdwPOV[3],
381               js.rgbButtons[0]>>7, js.rgbButtons[1]>>7, js.rgbButtons[2]>>7,
382               js.rgbButtons[3]>>7, js.rgbButtons[4]>>7, js.rgbButtons[5]>>7,
383               js.rgbButtons[6]>>7, js.rgbButtons[7]>>7, js.rgbButtons[8]>>7,
384               js.rgbButtons[9]>>7, js.rgbButtons[10]>>7, js.rgbButtons[11]>>7);
385         if (strcmp(oldstate, curstate) != 0)
386         {
387             trace(curstate);
388             strcpy(oldstate, curstate);
389         }
390         Sleep(100);
391     }
392     trace("\n");
393 
394     hr = IDirectInputDevice_Unacquire(pJoystick);
395     ok(hr==DI_OK,"IDirectInputDevice_Unacquire() failed: %08x\n", hr);
396 
397 RELEASE:
398     ref = IDirectInputDevice_Release(pJoystick);
399     ok(ref==0,"IDirectInputDevice_Release() reference count = %d\n", ref);
400 
401 DONE:
402     return DIENUM_CONTINUE;
403 }
404 
405 static void joystick_tests(DWORD version)
406 {
407     HRESULT hr;
408     LPDIRECTINPUT pDI;
409     ULONG ref;
410     HINSTANCE hInstance = GetModuleHandle(NULL);
411 
412     trace("-- Testing Direct Input Version 0x%04x --\n", version);
413     hr = DirectInputCreate(hInstance, version, &pDI, NULL);
414     ok(hr==DI_OK||hr==DIERR_OLDDIRECTINPUTVERSION,
415        "DirectInputCreate() failed: %08x\n", hr);
416     if (hr==DI_OK && pDI!=0) {
417         UserData data;
418         data.pDI = pDI;
419         data.version = version;
420         hr = IDirectInput_EnumDevices(pDI, DIDEVTYPE_JOYSTICK, EnumJoysticks,
421                                       &data, DIEDFL_ALLDEVICES);
422         ok(hr==DI_OK,"IDirectInput_EnumDevices() failed: %08x\n", hr);
423         ref = IDirectInput_Release(pDI);
424         ok(ref==0,"IDirectInput_Release() reference count = %d\n", ref);
425     } else if (hr==DIERR_OLDDIRECTINPUTVERSION)
426         trace("  Version Not Supported\n");
427 }
428 
429 START_TEST(joystick)
430 {
431     CoInitialize(NULL);
432 
433     trace("DLL Version: %s\n", get_file_version("dinput.dll"));
434 
435     joystick_tests(0x0700);
436     joystick_tests(0x0500);
437     joystick_tests(0x0300);
438 
439     CoUninitialize();
440 }
441 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.