xinput: Added the function XInputGetState 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
28 static void test_get_state(void)
29 {
30
31     XINPUT_STATE controllerState;
32     DWORD controllerNum;
33     DWORD result;
34
35     for(controllerNum=0; controllerNum < XUSER_MAX_COUNT; controllerNum++)
36     {
37         ZeroMemory(&controllerState, sizeof(XINPUT_STATE));
38
39         result = pXInputGetState(controllerNum, &controllerState);
40         ok(result == ERROR_SUCCESS || result == ERROR_DEVICE_NOT_CONNECTED, "XInputGetState failed with (%d)\n", result);
41
42         if (ERROR_DEVICE_NOT_CONNECTED == result)
43         {
44             skip("Controller %d is not connected\n", controllerNum);
45         }
46         else
47         {
48             trace("-- Results for controller %d --\n", controllerNum);
49             trace("XInputGetState: %d\n", result);
50             trace("State->dwPacketNumber: %d\n", controllerState.dwPacketNumber);
51             trace("Gamepad Variables --\n");
52             trace("Gamepad.wButtons: %#x\n", controllerState.Gamepad.wButtons);
53             trace("Gamepad.bLeftTrigger: 0x%08x\n", controllerState.Gamepad.bLeftTrigger);
54             trace("Gamepad.bRightTrigger: 0x%08x\n", controllerState.Gamepad.bRightTrigger);
55             trace("Gamepad.sThumbLX: %d\n", controllerState.Gamepad.sThumbLX);
56             trace("Gamepad.sThumbLY: %d\n", controllerState.Gamepad.sThumbLY);
57             trace("Gamepad.sThumbRX: %d\n", controllerState.Gamepad.sThumbRX);
58             trace("Gamepad.sThumbRY: %d\n", controllerState.Gamepad.sThumbRY);
59         }
60     }
61
62     ZeroMemory(&controllerState, sizeof(XINPUT_STATE));
63     result = pXInputGetState(XUSER_MAX_COUNT+1, &controllerState);
64     ok(result == ERROR_BAD_ARGUMENTS, "XInputGetState returned (%d)\n", result);
65 }
66
67 START_TEST(xinput)
68 {
69     HMODULE hXinput;
70     hXinput = LoadLibraryA( "xinput1_3.dll" );
71
72     if (hXinput)
73     {
74         pXInputGetState = (void*)GetProcAddress(hXinput, "XInputGetState");
75         test_get_state();
76     }
77     else
78     {
79         skip("Could not load xinput1_3.dll\n");
80     }
81 }