From 21b5d83d492ac11f3d426f723fd66bfc7cd23a29 Mon Sep 17 00:00:00 2001 From: Sergey Khodych Date: Wed, 23 Apr 2008 00:45:41 +0300 Subject: Add test for IDirectInputDevice_GetProperty of keyboard device for unicode and ascii case. --- dlls/dinput/tests/keyboard.c | 105 ++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 105 insertions(+), 0 deletions(-) diff --git a/dlls/dinput/tests/keyboard.c b/dlls/dinput/tests/keyboard.c index f041119..15e3aeb 100644 --- a/dlls/dinput/tests/keyboard.c +++ b/dlls/dinput/tests/keyboard.c @@ -163,6 +163,110 @@ static void test_set_coop(LPDIRECTINPUT pDI, HWND hwnd) if (pKeyboard) IUnknown_Release(pKeyboard); } + +struct EnumContext +{ + LPDIRECTINPUTDEVICEW lpdiw; + LPDIRECTINPUTDEVICEA lpdia; +}; + +BOOL keyname_test( struct EnumContext *pec, DIPROPSTRING dipsw, DIPROPSTRING dipsa ) +{ + HRESULT hr; + BOOL result; + hr = IDirectInputDevice_GetProperty( pec->lpdiw, DIPROP_KEYNAME, (LPDIPROPHEADER)&dipsw ); + ok(SUCCEEDED(hr), "IDirectInputDevice_GetProperty( Unicode ) failed: %s\n", DXGetErrorString8(hr)); + if ( FAILED( hr) ) + return FALSE; + + hr = IDirectInputDevice_GetProperty( pec->lpdia, DIPROP_KEYNAME, (LPDIPROPHEADER)&dipsa ); + ok(SUCCEEDED(hr), "IDirectInputDevice_GetProperty( ASCII ) failed: %s\n", DXGetErrorString8(hr)); + if ( FAILED( hr) ) + return FALSE; + result = lstrcmpW( dipsw.wsz, dipsa.wsz ); + ok( result == 0 , "keyname_test failed: %d\n", result ); + return !result; +} + +BOOL WINAPI EnumObjectCallbackW( LPCDIDEVICEOBJECTINSTANCEW lpddoi, + LPVOID pvRef + ) +{ + DIPROPSTRING dipsw; + DIPROPSTRING dipsa; + struct EnumContext *pec = (struct EnumContext*)pvRef; + + dipsa.diph.dwSize = dipsw.diph.dwSize = sizeof( DIPROPSTRING ); + dipsa.diph.dwHeaderSize = dipsw.diph.dwHeaderSize = sizeof( DIPROPHEADER ); + dipsa.diph.dwHow = dipsw.diph.dwHow = DIPH_BYID; + dipsa.diph.dwObj = dipsw.diph.dwObj = lpddoi->dwType; + if ( !keyname_test( pec, dipsw, dipsa ) ) + return DIENUM_STOP; + + dipsa.diph.dwHow = dipsw.diph.dwHow = DIPH_BYOFFSET; + dipsa.diph.dwObj = dipsw.diph.dwObj = lpddoi->dwOfs; + if ( !keyname_test( pec, dipsw, dipsa ) ) + return DIENUM_STOP; + + return DIENUM_CONTINUE; +} + + +void test_IDirectInputDevice_GetProperty( HWND hWnd ) +{ + LPDIRECTINPUTW lpdiw = NULL; + LPDIRECTINPUTA lpdia = NULL; + LPDIRECTINPUTDEVICEW lpdidw = NULL; + LPDIRECTINPUTDEVICEA lpdida = NULL; + HRESULT hr; + struct EnumContext context; + + hr = DirectInput8Create( GetModuleHandle( NULL ), 0x0800, &IID_IDirectInput8W, (LPVOID)&lpdiw, NULL ); + ok(SUCCEEDED(hr), "DirectInput8Create( Unicode ) failed: %s\n", DXGetErrorString8(hr)); + if ( FAILED( hr ) ) + goto end; + + hr = DirectInput8Create( GetModuleHandle( NULL ), 0x0800, &IID_IDirectInput8A, (LPVOID)&lpdia, NULL ); + ok(SUCCEEDED(hr), "DirectInput8Create( ASCII ) failed: %s\n", DXGetErrorString8(hr)); + if ( FAILED( hr ) ) + goto end; + + hr = IDirectInput_CreateDevice( lpdiw, &GUID_SysKeyboard, &lpdidw, NULL ); + ok(SUCCEEDED(hr), "IDirectInput_CreateDevice( Unicode ) failed: %s\n", DXGetErrorString8(hr)); + if ( FAILED( hr ) ) + goto end; + + hr = IDirectInput_CreateDevice( lpdia, &GUID_SysKeyboard, &lpdida, NULL ); + ok(SUCCEEDED(hr), "IDirectInput_CreateDevice( ASCII ) failed: %s\n", DXGetErrorString8(hr)); + if ( FAILED( hr ) ) + goto end; + + hr = IDirectInputDevice_SetDataFormat( lpdidw, &c_dfDIKeyboard ); + ok(SUCCEEDED(hr), "IDirectInputDevice8_SetDataFormat( Unicode ) failed: %s\n", DXGetErrorString8(hr)); + if ( FAILED( hr ) ) + goto end; + + hr = IDirectInputDevice_SetDataFormat( lpdida, &c_dfDIKeyboard ); + ok(SUCCEEDED( hr ), "IDirectInputDevice8_SetDataFormat( ASCII ) failed: %s\n", DXGetErrorString8(hr)); + if ( FAILED( hr ) ) + goto end; + + context.lpdiw = lpdidw; + context.lpdia = lpdida; + + hr = IDirectInputDevice_EnumObjects( lpdidw, EnumObjectCallbackW, &context, DIDFT_BUTTON ); + ok(SUCCEEDED( hr ), "IDirectInputDevice8_EnumObjects( Unicode ) failed: %s\n", DXGetErrorString8(hr)); + end: + if ( lpdidw ) + IDirectInputDevice_Release( lpdidw ); + if ( lpdida ) + IDirectInputDevice_Release( lpdida ); + if ( lpdiw ) + IDirectInput_Release( lpdiw ); + if ( lpdia ) + IDirectInput_Release( lpdia ); +} + static void keyboard_tests(DWORD version) { HRESULT hr; @@ -188,6 +292,7 @@ static void keyboard_tests(DWORD version) { acquire_tests(pDI, hwnd); test_set_coop(pDI, hwnd); + test_IDirectInputDevice_GetProperty( hwnd ); } DestroyWindow(hwnd); -- 1.5.3.3