From 63e95070119c14b30d5d77ce636b5d7460309aa6 Mon Sep 17 00:00:00 2001
From: Andrew Fenn <andre...@gmail.com>
Date: Fri, 31 Oct 2008 17:50:54 +0000
Subject: xinput: Added the function XInputGetState with test case
---
dlls/xinput1_3/tests/Makefile.in | 13 ++++++
dlls/xinput1_3/tests/xinput.c | 81 ++++++++++++++++++++++++++++++++++++++
dlls/xinput1_3/xinput1_3.spec | 2 +-
dlls/xinput1_3/xinput1_3_main.c | 14 +++++++
4 files changed, 109 insertions(+), 1 deletions(-)
create mode 100644 dlls/xinput1_3/tests/Makefile.in
create mode 100644 dlls/xinput1_3/tests/xinput.c
diff --git a/dlls/xinput1_3/tests/Makefile.in b/dlls/xinput1_3/tests/Makefile.in
new file mode 100644
index 0000000..e855dc8
--- /dev/null
+++ b/dlls/xinput1_3/tests/Makefile.in
@@ -0,0 +1,13 @@
+TOPSRCDIR = @top_srcdir@
+TOPOBJDIR = ../../..
+SRCDIR = @srcdir@
+VPATH = @srcdir@
+TESTDLL = xinput1_3.dll
+IMPORTS = user32 kernel32
+
+CTESTS = \
+ xinput.c \
+
+@MAKE_TEST_RULES@
+
+@DEPENDENCIES@ # everything below this line is overwritten by make depend
diff --git a/dlls/xinput1_3/tests/xinput.c b/dlls/xinput1_3/tests/xinput.c
new file mode 100644
index 0000000..c969bc6
--- /dev/null
+++ b/dlls/xinput1_3/tests/xinput.c
@@ -0,0 +1,81 @@
+/*
+ * The Wine project - Xinput Joystick Library
+ * Copyright 2008 Andrew Fenn
+ *
+ * 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
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <windows.h>
+#include <stdio.h>
+
+#include "xinput.h"
+#include "wine/test.h"
+
+static DWORD (WINAPI *XInputGetState)(DWORD, XINPUT_STATE*)=NULL;
+
+static void test_get_state(void)
+{
+
+ XINPUT_STATE controllerState;
+ DWORD controllerNum;
+ DWORD result;
+
+ for(controllerNum=0; controllerNum < XUSER_MAX_COUNT; controllerNum++)
+ {
+ ZeroMemory(&controllerState, sizeof(XINPUT_STATE));
+
+ result = XInputGetState(controllerNum, &controllerState);
+ ok(result == ERROR_SUCCESS || result == ERROR_DEVICE_NOT_CONNECTED, "XInputGetState failed with (%d)\n", result);
+
+ if (ERROR_DEVICE_NOT_CONNECTED == result)
+ {
+ skip("Controller %d is not connected\n", controllerNum);
+ }
+ else
+ {
+ trace("-- Results for controller %d --\n", controllerNum);
+ trace("XInputGetState: %d\n", result);
+ trace("State->dwPacketNumber: %d\n", controllerState.dwPacketNumber);
+ trace("Gamepad Variables --\n");
+ trace("Gamepad.wButtons: %#x\n", controllerState.Gamepad.wButtons);
+ trace("Gamepad.bLeftTrigger: 0x%08x\n", controllerState.Gamepad.bLeftTrigger);
+ trace("Gamepad.bRightTrigger: 0x%08x\n", controllerState.Gamepad.bRightTrigger);
+ trace("Gamepad.sThumbLX: %d\n", controllerState.Gamepad.sThumbLX);
+ trace("Gamepad.sThumbLY: %d\n", controllerState.Gamepad.sThumbLY);
+ trace("Gamepad.sThumbRX: %d\n", controllerState.Gamepad.sThumbRX);
+ trace("Gamepad.sThumbRY: %d\n", controllerState.Gamepad.sThumbRY);
+ }
+ }
+
+ ZeroMemory(&controllerState, sizeof(XINPUT_STATE));
+ result = XInputGetState(XUSER_MAX_COUNT+1, &controllerState);
+ ok(result == ERROR_BAD_ARGUMENTS, "XInputGetState returned (%d)\n", result);
+}
+
+START_TEST(xinput)
+{
+ HMODULE hXinput;
+ hXinput = LoadLibraryA( "xinput1_3.dll" );
+
+ if (hXinput)
+ {
+ XInputGetState = (void*)GetProcAddress(hXinput, "XInputGetState");
+ test_get_state();
+ }
+ else
+ {
+ skip("Could not load xinput1_3.dll\n");
+ }
+}
diff --git a/dlls/xinput1_3/xinput1_3.spec b/dlls/xinput1_3/xinput1_3.spec
index 5caaa37..8fb6353 100644
--- a/dlls/xinput1_3/xinput1_3.spec
+++ b/dlls/xinput1_3/xinput1_3.spec
@@ -1,6 +1,6 @@
@ stub XInputEnable #(long)
@ stub XInputSetState #(long ptr)
-@ stub XInputGetState #(long ptr)
+@ stdcall XInputGetState(long ptr)
@ stub XInputGetKeystroke #(long long ptr)
@ stub XInputGetCapabilities #(long long ptr)
@ stub XInputGetDSoundAudioDeviceGuids #(long ptr ptr)
diff --git a/dlls/xinput1_3/xinput1_3_main.c b/dlls/xinput1_3/xinput1_3_main.c
index 6198b3b..b12b67f 100644
--- a/dlls/xinput1_3/xinput1_3_main.c
+++ b/dlls/xinput1_3/xinput1_3_main.c
@@ -27,6 +27,8 @@
#include "winbase.h"
#include "winerror.h"
+#include "xinput.h"
+
WINE_DEFAULT_DEBUG_CHANNEL(xinput);
BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, LPVOID reserved)
@@ -43,3 +45,15 @@ BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, LPVOID reserved)
}
return TRUE;
}
+
+DWORD WINAPI XInputGetState(DWORD dwUserIndex, XINPUT_STATE* pState)
+{
+ FIXME("(%d 0x%08x)\n", dwUserIndex, pState);
+
+ if (dwUserIndex < XUSER_MAX_COUNT)
+ {
+ return ERROR_DEVICE_NOT_CONNECTED;
+ /* If controller exists then return ERROR_SUCCESS */
+ }
+ return ERROR_BAD_ARGUMENTS;
+}
--
1.5.4.3