xinput: Added XInputGetCapabilities function with test case.
[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
29 static void test_get_state(void)
30 {
31
32     XINPUT_STATE controllerState;
33     DWORD controllerNum;
34     DWORD result;
35
36     for(controllerNum=0; controllerNum < XUSER_MAX_COUNT; controllerNum++)
37     {
38         ZeroMemory(&controllerState, sizeof(XINPUT_STATE));
39
40         result = pXInputGetState(controllerNum, &controllerState);
41         ok(result == ERROR_SUCCESS || result == ERROR_DEVICE_NOT_CONNECTED, "XInputGetState failed with (%d)\n", result);
42
43         if (ERROR_DEVICE_NOT_CONNECTED == result)
44         {
45             skip("Controller %d is not connected\n", controllerNum);
46         }
47         else
48         {
49             trace("-- Results for controller %d --\n", controllerNum);
50             trace("XInputGetState: %d\n", result);
51             trace("State->dwPacketNumber: %d\n", controllerState.dwPacketNumber);
52             trace("Gamepad Variables --\n");
53             trace("Gamepad.wButtons: %#x\n", controllerState.Gamepad.wButtons);
54             trace("Gamepad.bLeftTrigger: 0x%08x\n", controllerState.Gamepad.bLeftTrigger);
55             trace("Gamepad.bRightTrigger: 0x%08x\n", controllerState.Gamepad.bRightTrigger);
56             trace("Gamepad.sThumbLX: %d\n", controllerState.Gamepad.sThumbLX);
57             trace("Gamepad.sThumbLY: %d\n", controllerState.Gamepad.sThumbLY);
58             trace("Gamepad.sThumbRX: %d\n", controllerState.Gamepad.sThumbRX);
59             trace("Gamepad.sThumbRY: %d\n", controllerState.Gamepad.sThumbRY);
60         }
61     }
62
63     ZeroMemory(&controllerState, sizeof(XINPUT_STATE));
64     result = pXInputGetState(XUSER_MAX_COUNT+1, &controllerState);
65     ok(result == ERROR_BAD_ARGUMENTS, "XInputGetState returned (%d)\n", result);
66 }
67
68 static void test_get_capabilities(void)
69 {
70     XINPUT_CAPABILITIES capabilities;
71     DWORD controllerNum;
72     DWORD result;
73
74     for(controllerNum=0; controllerNum < XUSER_MAX_COUNT; controllerNum++)
75     {
76         ZeroMemory(&capabilities, sizeof(XINPUT_CAPABILITIES));
77
78         result = pXInputGetCapabilities(controllerNum, XINPUT_FLAG_GAMEPAD, &capabilities);
79         ok(result == ERROR_SUCCESS || result == ERROR_DEVICE_NOT_CONNECTED, "XInputGetCapabilities failed with (%d)\n", result);
80
81         if (ERROR_DEVICE_NOT_CONNECTED == result)
82         {
83             skip("Controller %d is not connected\n", controllerNum);
84         }
85     }
86
87     ZeroMemory(&capabilities, sizeof(XINPUT_CAPABILITIES));
88     result = pXInputGetCapabilities(XUSER_MAX_COUNT+1, XINPUT_FLAG_GAMEPAD, &capabilities);
89     ok(result == ERROR_BAD_ARGUMENTS, "XInputGetCapabilities returned (%d)\n", result);
90 }
91
92 START_TEST(xinput)
93 {
94     HMODULE hXinput;
95     hXinput = LoadLibraryA( "xinput1_3.dll" );
96
97     if (hXinput)
98     {
99         pXInputGetState = (void*)GetProcAddress(hXinput, "XInputGetState");
100         pXInputGetCapabilities = (void*)GetProcAddress(hXinput, "XInputGetCapabilities");
101         test_get_state();
102         test_get_capabilities();
103     }
104     else
105     {
106         skip("Could not load xinput1_3.dll\n");
107     }
108 }