2005-05-11 14:05:17 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2005 Robert Reif
|
2006-09-16 20:25:29 +02:00
|
|
|
* Copyright (c) 2006 Vitaliy Margolen
|
2005-05-11 14:05:17 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-05-11 14:05:17 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define DIRECTINPUT_VERSION 0x0700
|
|
|
|
|
2006-09-16 20:25:29 +02:00
|
|
|
#define COBJMACROS
|
2005-05-11 14:05:17 +02:00
|
|
|
#include <windows.h>
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "wine/test.h"
|
|
|
|
#include "windef.h"
|
|
|
|
#include "wingdi.h"
|
|
|
|
#include "dinput.h"
|
|
|
|
|
2006-09-16 20:25:29 +02:00
|
|
|
static const HRESULT SetCoop_null_window[16] = {
|
|
|
|
E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG,
|
|
|
|
E_INVALIDARG, E_HANDLE, E_HANDLE, E_INVALIDARG,
|
|
|
|
E_INVALIDARG, E_HANDLE, S_OK, E_INVALIDARG,
|
|
|
|
E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG};
|
|
|
|
|
|
|
|
static const HRESULT SetCoop_real_window[16] = {
|
|
|
|
E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG,
|
|
|
|
E_INVALIDARG, S_OK, S_OK, E_INVALIDARG,
|
|
|
|
E_INVALIDARG, E_NOTIMPL, S_OK, E_INVALIDARG,
|
|
|
|
E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG};
|
|
|
|
|
|
|
|
static void test_set_coop(LPDIRECTINPUT pDI, HWND hwnd)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
LPDIRECTINPUTDEVICE pMouse = NULL;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
hr = IDirectInput_CreateDevice(pDI, &GUID_SysMouse, &pMouse, NULL);
|
2008-07-08 17:49:03 +02:00
|
|
|
ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %08x\n", hr);
|
2006-09-16 20:25:29 +02:00
|
|
|
if (FAILED(hr)) return;
|
|
|
|
|
|
|
|
for (i=0; i<16; i++)
|
|
|
|
{
|
|
|
|
hr = IDirectInputDevice_SetCooperativeLevel(pMouse, NULL, i);
|
2008-07-08 17:49:03 +02:00
|
|
|
ok(hr == SetCoop_null_window[i], "SetCooperativeLevel(NULL, %d): %08x\n", i, hr);
|
2006-09-16 20:25:29 +02:00
|
|
|
}
|
|
|
|
for (i=0; i<16; i++)
|
|
|
|
{
|
|
|
|
hr = IDirectInputDevice_SetCooperativeLevel(pMouse, hwnd, i);
|
2008-07-08 17:49:03 +02:00
|
|
|
ok(hr == SetCoop_real_window[i], "SetCooperativeLevel(hwnd, %d): %08x\n", i, hr);
|
2006-09-16 20:25:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pMouse) IUnknown_Release(pMouse);
|
|
|
|
}
|
|
|
|
|
2006-12-01 18:54:42 +01:00
|
|
|
static void test_acquire(LPDIRECTINPUT pDI, HWND hwnd)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
LPDIRECTINPUTDEVICE pMouse = NULL;
|
2007-07-06 15:25:47 +02:00
|
|
|
DIMOUSESTATE m_state;
|
2009-10-15 09:20:00 +02:00
|
|
|
HWND hwnd2;
|
2006-12-01 18:54:42 +01:00
|
|
|
|
|
|
|
hr = IDirectInput_CreateDevice(pDI, &GUID_SysMouse, &pMouse, NULL);
|
2008-07-08 17:49:03 +02:00
|
|
|
ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %08x\n", hr);
|
2006-12-01 18:54:42 +01:00
|
|
|
if (FAILED(hr)) return;
|
|
|
|
|
2007-06-03 17:09:35 +02:00
|
|
|
hr = IDirectInputDevice_SetCooperativeLevel(pMouse, hwnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);
|
2008-07-08 17:49:03 +02:00
|
|
|
ok(hr == S_OK, "SetCooperativeLevel: %08x\n", hr);
|
2007-06-03 17:09:35 +02:00
|
|
|
|
2006-12-01 18:54:42 +01:00
|
|
|
hr = IDirectInputDevice_SetDataFormat(pMouse, &c_dfDIMouse);
|
2008-07-08 17:49:03 +02:00
|
|
|
ok(SUCCEEDED(hr), "IDirectInputDevice_SetDataFormat() failed: %08x\n", hr);
|
2006-12-01 18:54:42 +01:00
|
|
|
hr = IDirectInputDevice_Unacquire(pMouse);
|
2008-07-08 17:49:03 +02:00
|
|
|
ok(hr == S_FALSE, "IDirectInputDevice_Unacquire() should have failed: %08x\n", hr);
|
2006-12-01 18:54:42 +01:00
|
|
|
hr = IDirectInputDevice_Acquire(pMouse);
|
2008-07-08 17:49:03 +02:00
|
|
|
ok(SUCCEEDED(hr), "IDirectInputDevice_Acquire() failed: %08x\n", hr);
|
2006-12-01 18:54:42 +01:00
|
|
|
hr = IDirectInputDevice_Acquire(pMouse);
|
2008-07-08 17:49:03 +02:00
|
|
|
ok(hr == S_FALSE, "IDirectInputDevice_Acquire() should have failed: %08x\n", hr);
|
2007-06-03 17:09:35 +02:00
|
|
|
|
|
|
|
/* Foreground coop level requires window to have focus */
|
2009-10-15 09:20:00 +02:00
|
|
|
/* Create a temporary window, this should make dinput
|
|
|
|
* loose mouse input */
|
|
|
|
hwnd2 = CreateWindow("static", "Temporary", WS_VISIBLE,
|
|
|
|
10, 210, 200, 200, NULL, NULL, NULL, NULL);
|
2007-06-03 17:09:35 +02:00
|
|
|
|
|
|
|
hr = IDirectInputDevice_GetDeviceState(pMouse, sizeof(m_state), &m_state);
|
2008-07-08 17:49:03 +02:00
|
|
|
ok(hr == DIERR_NOTACQUIRED, "GetDeviceState() should have failed: %08x\n", hr);
|
2007-06-03 17:09:35 +02:00
|
|
|
/* Workaround so we can test other things. Remove when Wine is fixed */
|
|
|
|
IDirectInputDevice_Unacquire(pMouse);
|
|
|
|
|
|
|
|
hr = IDirectInputDevice_Acquire(pMouse);
|
2008-07-08 17:49:03 +02:00
|
|
|
ok(hr == DIERR_OTHERAPPHASPRIO, "Acquire() should have failed: %08x\n", hr);
|
2007-06-03 17:09:35 +02:00
|
|
|
|
|
|
|
SetActiveWindow( hwnd );
|
|
|
|
hr = IDirectInputDevice_Acquire(pMouse);
|
2008-07-08 17:49:03 +02:00
|
|
|
ok(hr == S_OK, "Acquire() failed: %08x\n", hr);
|
2006-12-01 18:54:42 +01:00
|
|
|
|
|
|
|
if (pMouse) IUnknown_Release(pMouse);
|
2009-10-15 09:20:00 +02:00
|
|
|
|
|
|
|
DestroyWindow( hwnd2 );
|
2006-12-01 18:54:42 +01:00
|
|
|
}
|
|
|
|
|
2005-06-21 22:53:13 +02:00
|
|
|
static void mouse_tests(void)
|
2005-05-11 14:05:17 +02:00
|
|
|
{
|
2006-09-16 20:25:29 +02:00
|
|
|
HRESULT hr;
|
|
|
|
LPDIRECTINPUT pDI = NULL;
|
|
|
|
HINSTANCE hInstance = GetModuleHandle(NULL);
|
|
|
|
HWND hwnd;
|
2006-12-22 18:54:29 +01:00
|
|
|
ULONG ref = 0;
|
2006-09-16 20:25:29 +02:00
|
|
|
|
|
|
|
hr = DirectInputCreate(hInstance, DIRECTINPUT_VERSION, &pDI, NULL);
|
2008-03-07 20:26:57 +01:00
|
|
|
if (hr == DIERR_OLDDIRECTINPUTVERSION)
|
|
|
|
{
|
|
|
|
skip("Tests require a newer dinput version\n");
|
|
|
|
return;
|
|
|
|
}
|
2008-07-08 17:49:03 +02:00
|
|
|
ok(SUCCEEDED(hr), "DirectInputCreate() failed: %08x\n", hr);
|
2006-09-16 20:25:29 +02:00
|
|
|
if (FAILED(hr)) return;
|
|
|
|
|
|
|
|
hwnd = CreateWindow("static", "Title", WS_OVERLAPPEDWINDOW,
|
|
|
|
10, 10, 200, 200, NULL, NULL, NULL, NULL);
|
2006-10-12 02:22:27 +02:00
|
|
|
ok(hwnd != NULL, "err: %d\n", GetLastError());
|
2006-12-01 18:54:42 +01:00
|
|
|
if (hwnd)
|
|
|
|
{
|
|
|
|
ShowWindow(hwnd, SW_SHOW);
|
2006-09-16 20:25:29 +02:00
|
|
|
|
2006-12-01 18:54:42 +01:00
|
|
|
test_set_coop(pDI, hwnd);
|
|
|
|
test_acquire(pDI, hwnd);
|
2006-09-16 20:25:29 +02:00
|
|
|
|
2006-12-01 18:54:42 +01:00
|
|
|
DestroyWindow(hwnd);
|
|
|
|
}
|
2006-12-22 18:54:29 +01:00
|
|
|
if (pDI) ref = IUnknown_Release(pDI);
|
|
|
|
ok(!ref, "IDirectInput_Release() reference count = %d\n", ref);
|
2005-05-11 14:05:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
START_TEST(mouse)
|
|
|
|
{
|
|
|
|
CoInitialize(NULL);
|
|
|
|
|
|
|
|
mouse_tests();
|
|
|
|
|
|
|
|
CoUninitialize();
|
|
|
|
}
|