Fix SetProperty error returned.

Add EnumDevice joystick version check.
Test multiple versions.
This commit is contained in:
Robert Reif 2005-05-13 13:57:17 +00:00 committed by Alexandre Julliard
parent 5037202554
commit 0f60464b95
4 changed files with 57 additions and 22 deletions

View File

@ -95,6 +95,7 @@ HRESULT WINAPI DirectInputCreateEx(
This->lpVtbl = &ddi7avt;
This->ref = 1;
This->version = 1;
This->dwVersion = dwVersion;
*ppDI = This;
return DI_OK;
@ -107,6 +108,7 @@ HRESULT WINAPI DirectInputCreateEx(
This->lpVtbl = &ddi7wvt;
This->ref = 1;
This->version = 1;
This->dwVersion = dwVersion;
*ppDI = This;
return DI_OK;
@ -117,6 +119,7 @@ HRESULT WINAPI DirectInputCreateEx(
This->lpVtbl = &ddi8avt;
This->ref = 1;
This->version = 8;
This->dwVersion = dwVersion;
*ppDI = This;
return DI_OK;
@ -127,6 +130,7 @@ HRESULT WINAPI DirectInputCreateEx(
This->lpVtbl = &ddi8wvt;
This->ref = 1;
This->version = 8;
This->dwVersion = dwVersion;
*ppDI = This;
return DI_OK;
@ -145,6 +149,7 @@ HRESULT WINAPI DirectInputCreateA(HINSTANCE hinst, DWORD dwVersion, LPDIRECTINPU
This = HeapAlloc(GetProcessHeap(),0,sizeof(IDirectInputImpl));
This->lpVtbl = &ddi7avt;
This->ref = 1;
This->dwVersion = dwVersion;
if (dwVersion >= 0x0800) {
This->version = 8;
} else {
@ -166,6 +171,7 @@ HRESULT WINAPI DirectInputCreateW(HINSTANCE hinst, DWORD dwVersion, LPDIRECTINPU
This = HeapAlloc(GetProcessHeap(),0,sizeof(IDirectInputImpl));
This->lpVtbl = &ddi7wvt;
This->ref = 1;
This->dwVersion = dwVersion;
if (dwVersion >= 0x0800) {
This->version = 8;
} else {
@ -228,6 +234,10 @@ static HRESULT WINAPI IDirectInputAImpl_EnumDevices(
lpCallback, pvRef, dwFlags);
TRACE(" flags: "); _dump_EnumDevices_dwFlags(dwFlags); TRACE("\n");
/* joysticks are not supported in version 0x0300 */
if ((dwDevType == DIDEVTYPE_JOYSTICK) && (This->dwVersion <= 0x0300))
return E_INVALIDARG;
for (i = 0; i < NB_DINPUT_DEVICES; i++) {
if (!dinput_devices[i]->enum_deviceA) continue;
for (j = 0, r = -1; r != 0; j++) {
@ -258,6 +268,10 @@ static HRESULT WINAPI IDirectInputWImpl_EnumDevices(
lpCallback, pvRef, dwFlags);
TRACE(" flags: "); _dump_EnumDevices_dwFlags(dwFlags); TRACE("\n");
/* joysticks are not supported in version 0x0300 */
if ((dwDevType == DIDEVTYPE_JOYSTICK) && (This->dwVersion <= 0x0300))
return E_INVALIDARG;
for (i = 0; i < NB_DINPUT_DEVICES; i++) {
if (!dinput_devices[i]->enum_deviceW) continue;
for (j = 0, r = -1; r != 0; j++) {

View File

@ -36,6 +36,7 @@ struct IDirectInputImpl
DWORD evsequence;
int version;
DWORD dwVersion;
};
/* Function called by all devices that Wine supports */

View File

@ -1125,7 +1125,7 @@ static HRESULT WINAPI JoystickAImpl_SetProperty(
if (ph == NULL) {
WARN("invalid pointer\n");
return E_POINTER;
return E_INVALIDARG;
}
if (TRACE_ON(dinput))

View File

@ -35,6 +35,11 @@
#define numObjects(x) (sizeof(x) / sizeof(x[0]))
typedef struct tagUserData {
LPDIRECTINPUT pDI;
DWORD version;
} UserData;
static const DIOBJECTDATAFORMAT dfDIJoystickTest[] = {
{ &GUID_XAxis,DIJOFS_X,DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0},
{ &GUID_YAxis,DIJOFS_Y,DIDFT_OPTIONAL|DIDFT_AXIS|DIDFT_ANYINSTANCE,0},
@ -103,8 +108,8 @@ static BOOL CALLBACK EnumAxes(
diprg.lMax = +1000;
hr = IDirectInputDevice_SetProperty(info->pJoystick, DIPROP_RANGE, NULL);
ok(hr==E_POINTER,"IDirectInputDevice_SetProperty() should have returned "
"E_POINTER, returned: %s\n", DXGetErrorString8(hr));
ok(hr==E_INVALIDARG,"IDirectInputDevice_SetProperty() should have returned "
"E_INVALIDARG, returned: %s\n", DXGetErrorString8(hr));
hr = IDirectInputDevice_SetProperty(info->pJoystick, DIPROP_RANGE, &diprg.diph);
ok(hr==DI_OK,"IDirectInputDevice_SetProperty() failed: %s\n", DXGetErrorString8(hr));
@ -123,7 +128,7 @@ static BOOL CALLBACK EnumJoysticks(
LPVOID pvRef)
{
HRESULT hr;
LPDIRECTINPUT pDI = (LPDIRECTINPUT)pvRef;
UserData * data = (UserData *)pvRef;
LPDIRECTINPUTDEVICE pJoystick;
DIDATAFORMAT format;
DIDEVCAPS caps;
@ -132,19 +137,20 @@ static BOOL CALLBACK EnumJoysticks(
int i, count;
ULONG ref;
hr = IDirectInput_CreateDevice(pDI, &lpddi->guidInstance, NULL, NULL);
hr = IDirectInput_CreateDevice(data->pDI, &lpddi->guidInstance, NULL, NULL);
ok(hr==E_POINTER,"IDirectInput_CreateDevice() should have returned "
"E_POINTER, returned: %s\n", DXGetErrorString8(hr));
hr = IDirectInput_CreateDevice(pDI, NULL, &pJoystick, NULL);
hr = IDirectInput_CreateDevice(data->pDI, NULL, &pJoystick, NULL);
ok(hr==E_POINTER,"IDirectInput_CreateDevice() should have returned "
"E_POINTER, returned: %s\n", DXGetErrorString8(hr));
hr = IDirectInput_CreateDevice(pDI, NULL, NULL, NULL);
hr = IDirectInput_CreateDevice(data->pDI, NULL, NULL, NULL);
ok(hr==E_POINTER,"IDirectInput_CreateDevice() should have returned "
"E_POINTER, returned: %s\n", DXGetErrorString8(hr));
hr = IDirectInput_CreateDevice(pDI, &lpddi->guidInstance, &pJoystick, NULL);
hr = IDirectInput_CreateDevice(data->pDI, &lpddi->guidInstance,
&pJoystick, NULL);
ok(hr==DI_OK,"IDirectInput_CreateDevice() failed: %s\n",
DXGetErrorString8(hr));
if (hr!=DI_OK)
@ -260,22 +266,34 @@ DONE:
return DIENUM_CONTINUE;
}
static void joystick_tests()
static void joystick_tests(DWORD version)
{
HRESULT hr;
LPDIRECTINPUT pDI;
ULONG ref;
hr = DirectInputCreate(GetModuleHandle(NULL), DIRECTINPUT_VERSION, &pDI, NULL);
ok(hr==DI_OK, "DirectInputCreate() failed: %s\n", DXGetErrorString8(hr));
if (hr!=DI_OK)
return;
hr = IDirectInput_EnumDevices(pDI, DIDEVTYPE_JOYSTICK, EnumJoysticks, pDI, DIEDFL_ALLDEVICES);
ok(hr==DI_OK,"IDirectInput_EnumDevices() failed: %s\n", DXGetErrorString8(hr));
trace("-- Testing Direct Input Version 0x%04lx --\n", version);
hr = DirectInputCreate(GetModuleHandle(NULL), version, &pDI, NULL);
ok(hr==DI_OK||hr==DIERR_OLDDIRECTINPUTVERSION,
"DirectInputCreate() failed: %s\n", DXGetErrorString8(hr));
if (hr==DI_OK && pDI!=0) {
UserData data;
data.pDI = pDI;
data.version = version;
hr = IDirectInput_EnumDevices(pDI, DIDEVTYPE_JOYSTICK, EnumJoysticks,
&data, DIEDFL_ALLDEVICES);
if (version == 0x0300) {
trace(" Joysticks Not Supported\n");
ok(hr==E_INVALIDARG,"IDirectInput_EnumDevices() should have "
"returned E_INVALIDARG, returned: %s\n", DXGetErrorString8(hr));
} else {
ok(hr==DI_OK,"IDirectInput_EnumDevices() failed: %s\n",
DXGetErrorString8(hr));
}
ref = IDirectInput_Release(pDI);
ok(ref==0,"IDirectInput_Release() reference count = %ld\n", ref);
} else if (hr==DIERR_OLDDIRECTINPUTVERSION)
trace(" Version Not Supported\n");
}
START_TEST(joystick)
@ -284,7 +302,9 @@ START_TEST(joystick)
trace("DLL Version: %s\n", get_file_version("dinput.dll"));
joystick_tests();
joystick_tests(0x0700);
joystick_tests(0x0500);
joystick_tests(0x0300);
CoUninitialize();
}