d3dcompiler: Fix SystemValueType for pixelshader output signature.
[wine] / dlls / xinput1_3 / tests / xinput.c
1 /*
2  * The Wine project - Xinput Joystick Library
3  * Copyright 2008 Andrew Fenn
4  *
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.
9  *
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.
14  *
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
18  */
19
20 #include <windows.h>
21 #include <stdio.h>
22
23 #include "xinput.h"
24 #include "wine/test.h"
25
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*);
33
34 static void test_set_state(void)
35 {
36     XINPUT_VIBRATION vibrator;
37     DWORD controllerNum;
38     DWORD result;
39
40     for(controllerNum=0; controllerNum < XUSER_MAX_COUNT; controllerNum++)
41     {
42         ZeroMemory(&vibrator, sizeof(XINPUT_VIBRATION));
43
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);
48
49         pXInputEnable(0);
50
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);
55
56         pXInputEnable(1);
57     }
58
59     result = pXInputSetState(XUSER_MAX_COUNT+1, &vibrator);
60     ok(result == ERROR_BAD_ARGUMENTS, "XInputSetState returned (%d)\n", result);
61 }
62
63 static void test_get_state(void)
64 {
65
66     XINPUT_STATE controllerState;
67     DWORD controllerNum;
68     DWORD result;
69
70     for(controllerNum=0; controllerNum < XUSER_MAX_COUNT; controllerNum++)
71     {
72         ZeroMemory(&controllerState, sizeof(XINPUT_STATE));
73
74         result = pXInputGetState(controllerNum, &controllerState);
75         ok(result == ERROR_SUCCESS || result == ERROR_DEVICE_NOT_CONNECTED, "XInputGetState failed with (%d)\n", result);
76
77         if (ERROR_DEVICE_NOT_CONNECTED == result)
78         {
79             skip("Controller %d is not connected\n", controllerNum);
80         }
81         else
82         {
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);
94         }
95     }
96
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);
100 }
101
102 static void test_get_keystroke(void)
103 {
104     XINPUT_KEYSTROKE keystroke;
105     DWORD controllerNum;
106     DWORD result;
107
108     for(controllerNum=0; controllerNum < XUSER_MAX_COUNT; controllerNum++)
109     {
110         ZeroMemory(&keystroke, sizeof(XINPUT_KEYSTROKE));
111
112         result = pXInputGetKeystroke(controllerNum, XINPUT_FLAG_GAMEPAD, &keystroke);
113         ok(result == ERROR_SUCCESS || result == ERROR_DEVICE_NOT_CONNECTED, "XInputGetKeystroke failed with (%d)\n", result);
114
115         if (ERROR_DEVICE_NOT_CONNECTED == result)
116         {
117             skip("Controller %d is not connected\n", controllerNum);
118         }
119     }
120
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);
124 }
125
126 static void test_get_capabilities(void)
127 {
128     XINPUT_CAPABILITIES capabilities;
129     DWORD controllerNum;
130     DWORD result;
131
132     for(controllerNum=0; controllerNum < XUSER_MAX_COUNT; controllerNum++)
133     {
134         ZeroMemory(&capabilities, sizeof(XINPUT_CAPABILITIES));
135
136         result = pXInputGetCapabilities(controllerNum, XINPUT_FLAG_GAMEPAD, &capabilities);
137         ok(result == ERROR_SUCCESS || result == ERROR_DEVICE_NOT_CONNECTED, "XInputGetCapabilities failed with (%d)\n", result);
138
139         if (ERROR_DEVICE_NOT_CONNECTED == result)
140         {
141             skip("Controller %d is not connected\n", controllerNum);
142         }
143     }
144
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);
148 }
149
150 static void test_get_dsoundaudiodevice(void)
151 {
152     DWORD controllerNum;
153     DWORD result;
154     GUID soundRender;
155     GUID soundCapture;
156
157     for(controllerNum=0; controllerNum < XUSER_MAX_COUNT; controllerNum++)
158     {
159         result = pXInputGetDSoundAudioDeviceGuids(controllerNum, &soundRender, &soundCapture);
160         ok(result == ERROR_SUCCESS || result == ERROR_DEVICE_NOT_CONNECTED, "XInputGetDSoundAudioDeviceGuids failed with (%d)\n", result);
161
162         if (ERROR_DEVICE_NOT_CONNECTED == result)
163         {
164             skip("Controller %d is not connected\n", controllerNum);
165         }
166     }
167
168     result = pXInputGetDSoundAudioDeviceGuids(XUSER_MAX_COUNT+1, &soundRender, &soundCapture);
169     ok(result == ERROR_BAD_ARGUMENTS, "XInputGetDSoundAudioDeviceGuids returned (%d)\n", result);
170 }
171
172 static void test_get_batteryinformation(void)
173 {
174     DWORD controllerNum;
175     DWORD result;
176     XINPUT_BATTERY_INFORMATION batteryInfo;
177
178     for(controllerNum=0; controllerNum < XUSER_MAX_COUNT; controllerNum++)
179     {
180         ZeroMemory(&batteryInfo, sizeof(XINPUT_BATTERY_INFORMATION));
181
182         result = pXInputGetBatteryInformation(controllerNum, BATTERY_DEVTYPE_GAMEPAD, &batteryInfo);
183         ok(result == ERROR_SUCCESS || result == ERROR_DEVICE_NOT_CONNECTED, "XInputGetBatteryInformation failed with (%d)\n", result);
184
185         if (ERROR_DEVICE_NOT_CONNECTED == result)
186         {
187             ok(batteryInfo.BatteryLevel == BATTERY_TYPE_DISCONNECTED, "Failed to report device as being disconnected.\n");
188             skip("Controller %d is not connected\n", controllerNum);
189         }
190     }
191
192     result = pXInputGetBatteryInformation(XUSER_MAX_COUNT+1, BATTERY_DEVTYPE_GAMEPAD, &batteryInfo);
193     ok(result == ERROR_BAD_ARGUMENTS, "XInputGetBatteryInformation returned (%d)\n", result);
194 }
195
196 START_TEST(xinput)
197 {
198     HMODULE hXinput;
199     hXinput = LoadLibraryA( "xinput1_3.dll" );
200
201     if (!hXinput)
202     {
203         win_skip("Could not load xinput1_3.dll\n");
204         return;
205     }
206
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");
214
215     test_set_state();
216     test_get_state();
217     test_get_keystroke();
218     test_get_capabilities();
219     test_get_dsoundaudiodevice();
220     test_get_batteryinformation();
221
222     FreeLibrary(hXinput);
223 }