ddraw: Use a less offensive handle table implementation for surfaces.
[wine/hramrach.git] / dlls / xinput1_3 / tests / xinput.c
blob2a07f2d76b9fb76c0fe7e8e1bb088a65f7c9d777
1 /*
2 * The Wine project - Xinput Joystick Library
3 * Copyright 2008 Andrew Fenn
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include <windows.h>
21 #include <stdio.h>
23 #include "xinput.h"
24 #include "wine/test.h"
26 static DWORD (WINAPI *pXInputGetState)(DWORD, XINPUT_STATE*);
27 static DWORD (WINAPI *pXInputGetCapabilities)(DWORD,DWORD,XINPUT_CAPABILITIES*);
28 static DWORD (WINAPI *pXInputSetState)(DWORD, XINPUT_VIBRATION*);
29 static void (WINAPI *pXInputEnable)(BOOL);
30 static DWORD (WINAPI *pXInputGetKeystroke)(DWORD, DWORD, PXINPUT_KEYSTROKE);
31 static DWORD (WINAPI *pXInputGetDSoundAudioDeviceGuids)(DWORD, GUID*, GUID*);
32 static DWORD (WINAPI *pXInputGetBatteryInformation)(DWORD, BYTE, XINPUT_BATTERY_INFORMATION*);
34 static void test_set_state(void)
36 XINPUT_VIBRATION vibrator;
37 DWORD controllerNum;
38 DWORD result;
40 for(controllerNum=0; controllerNum < XUSER_MAX_COUNT; controllerNum++)
42 ZeroMemory(&vibrator, sizeof(XINPUT_VIBRATION));
44 vibrator.wLeftMotorSpeed = 0;
45 vibrator.wRightMotorSpeed = 0;
46 result = pXInputSetState(controllerNum, &vibrator);
47 ok(result == ERROR_SUCCESS || result == ERROR_DEVICE_NOT_CONNECTED, "XInputSetState failed with (%d)\n", result);
49 pXInputEnable(0);
51 vibrator.wLeftMotorSpeed = 65535;
52 vibrator.wRightMotorSpeed = 65535;
53 result = pXInputSetState(controllerNum, &vibrator);
54 ok(result == ERROR_SUCCESS || result == ERROR_DEVICE_NOT_CONNECTED, "XInputSetState failed with (%d)\n", result);
56 pXInputEnable(1);
59 result = pXInputSetState(XUSER_MAX_COUNT+1, &vibrator);
60 ok(result == ERROR_BAD_ARGUMENTS, "XInputSetState returned (%d)\n", result);
63 static void test_get_state(void)
66 XINPUT_STATE controllerState;
67 DWORD controllerNum;
68 DWORD result;
70 for(controllerNum=0; controllerNum < XUSER_MAX_COUNT; controllerNum++)
72 ZeroMemory(&controllerState, sizeof(XINPUT_STATE));
74 result = pXInputGetState(controllerNum, &controllerState);
75 ok(result == ERROR_SUCCESS || result == ERROR_DEVICE_NOT_CONNECTED, "XInputGetState failed with (%d)\n", result);
77 if (ERROR_DEVICE_NOT_CONNECTED == result)
79 skip("Controller %d is not connected\n", controllerNum);
81 else
83 trace("-- Results for controller %d --\n", controllerNum);
84 trace("XInputGetState: %d\n", result);
85 trace("State->dwPacketNumber: %d\n", controllerState.dwPacketNumber);
86 trace("Gamepad Variables --\n");
87 trace("Gamepad.wButtons: %#x\n", controllerState.Gamepad.wButtons);
88 trace("Gamepad.bLeftTrigger: 0x%08x\n", controllerState.Gamepad.bLeftTrigger);
89 trace("Gamepad.bRightTrigger: 0x%08x\n", controllerState.Gamepad.bRightTrigger);
90 trace("Gamepad.sThumbLX: %d\n", controllerState.Gamepad.sThumbLX);
91 trace("Gamepad.sThumbLY: %d\n", controllerState.Gamepad.sThumbLY);
92 trace("Gamepad.sThumbRX: %d\n", controllerState.Gamepad.sThumbRX);
93 trace("Gamepad.sThumbRY: %d\n", controllerState.Gamepad.sThumbRY);
97 ZeroMemory(&controllerState, sizeof(XINPUT_STATE));
98 result = pXInputGetState(XUSER_MAX_COUNT+1, &controllerState);
99 ok(result == ERROR_BAD_ARGUMENTS, "XInputGetState returned (%d)\n", result);
102 static void test_get_keystroke(void)
104 XINPUT_KEYSTROKE keystroke;
105 DWORD controllerNum;
106 DWORD result;
108 for(controllerNum=0; controllerNum < XUSER_MAX_COUNT; controllerNum++)
110 ZeroMemory(&keystroke, sizeof(XINPUT_KEYSTROKE));
112 result = pXInputGetKeystroke(controllerNum, XINPUT_FLAG_GAMEPAD, &keystroke);
113 ok(result == ERROR_SUCCESS || result == ERROR_DEVICE_NOT_CONNECTED, "XInputGetKeystroke failed with (%d)\n", result);
115 if (ERROR_DEVICE_NOT_CONNECTED == result)
117 skip("Controller %d is not connected\n", controllerNum);
121 ZeroMemory(&keystroke, sizeof(XINPUT_KEYSTROKE));
122 result = pXInputGetKeystroke(XUSER_MAX_COUNT+1, XINPUT_FLAG_GAMEPAD, &keystroke);
123 ok(result == ERROR_BAD_ARGUMENTS, "XInputGetKeystroke returned (%d)\n", result);
126 static void test_get_capabilities(void)
128 XINPUT_CAPABILITIES capabilities;
129 DWORD controllerNum;
130 DWORD result;
132 for(controllerNum=0; controllerNum < XUSER_MAX_COUNT; controllerNum++)
134 ZeroMemory(&capabilities, sizeof(XINPUT_CAPABILITIES));
136 result = pXInputGetCapabilities(controllerNum, XINPUT_FLAG_GAMEPAD, &capabilities);
137 ok(result == ERROR_SUCCESS || result == ERROR_DEVICE_NOT_CONNECTED, "XInputGetCapabilities failed with (%d)\n", result);
139 if (ERROR_DEVICE_NOT_CONNECTED == result)
141 skip("Controller %d is not connected\n", controllerNum);
145 ZeroMemory(&capabilities, sizeof(XINPUT_CAPABILITIES));
146 result = pXInputGetCapabilities(XUSER_MAX_COUNT+1, XINPUT_FLAG_GAMEPAD, &capabilities);
147 ok(result == ERROR_BAD_ARGUMENTS, "XInputGetCapabilities returned (%d)\n", result);
150 static void test_get_dsoundaudiodevice(void)
152 DWORD controllerNum;
153 DWORD result;
154 GUID soundRender;
155 GUID soundCapture;
157 for(controllerNum=0; controllerNum < XUSER_MAX_COUNT; controllerNum++)
159 result = pXInputGetDSoundAudioDeviceGuids(controllerNum, &soundRender, &soundCapture);
160 ok(result == ERROR_SUCCESS || result == ERROR_DEVICE_NOT_CONNECTED, "XInputGetDSoundAudioDeviceGuids failed with (%d)\n", result);
162 if (ERROR_DEVICE_NOT_CONNECTED == result)
164 skip("Controller %d is not connected\n", controllerNum);
168 result = pXInputGetDSoundAudioDeviceGuids(XUSER_MAX_COUNT+1, &soundRender, &soundCapture);
169 ok(result == ERROR_BAD_ARGUMENTS, "XInputGetDSoundAudioDeviceGuids returned (%d)\n", result);
172 static void test_get_batteryinformation(void)
174 DWORD controllerNum;
175 DWORD result;
176 XINPUT_BATTERY_INFORMATION batteryInfo;
178 for(controllerNum=0; controllerNum < XUSER_MAX_COUNT; controllerNum++)
180 ZeroMemory(&batteryInfo, sizeof(XINPUT_BATTERY_INFORMATION));
182 result = pXInputGetBatteryInformation(controllerNum, BATTERY_DEVTYPE_GAMEPAD, &batteryInfo);
183 ok(result == ERROR_SUCCESS || result == ERROR_DEVICE_NOT_CONNECTED, "XInputGetBatteryInformation failed with (%d)\n", result);
185 if (ERROR_DEVICE_NOT_CONNECTED == result)
187 ok(batteryInfo.BatteryLevel == BATTERY_TYPE_DISCONNECTED, "Failed to report device as being disconnected.\n");
188 skip("Controller %d is not connected\n", controllerNum);
192 result = pXInputGetBatteryInformation(XUSER_MAX_COUNT+1, BATTERY_DEVTYPE_GAMEPAD, &batteryInfo);
193 ok(result == ERROR_BAD_ARGUMENTS, "XInputGetBatteryInformation returned (%d)\n", result);
196 START_TEST(xinput)
198 HMODULE hXinput;
199 hXinput = LoadLibraryA( "xinput1_3.dll" );
201 if (!hXinput)
203 win_skip("Could not load xinput1_3.dll\n");
204 return;
207 pXInputEnable = (void*)GetProcAddress(hXinput, "XInputEnable");
208 pXInputSetState = (void*)GetProcAddress(hXinput, "XInputSetState");
209 pXInputGetState = (void*)GetProcAddress(hXinput, "XInputGetState");
210 pXInputGetKeystroke = (void*)GetProcAddress(hXinput, "XInputGetKeystroke");
211 pXInputGetCapabilities = (void*)GetProcAddress(hXinput, "XInputGetCapabilities");
212 pXInputGetDSoundAudioDeviceGuids = (void*)GetProcAddress(hXinput, "XInputGetDSoundAudioDeviceGuids");
213 pXInputGetBatteryInformation = (void*)GetProcAddress(hXinput, "XInputGetBatteryInformation");
215 test_set_state();
216 test_get_state();
217 test_get_keystroke();
218 test_get_capabilities();
219 test_get_dsoundaudiodevice();
220 test_get_batteryinformation();
222 FreeLibrary(hXinput);