dinput8/tests: Tests for creation and initialization of DInput8 interface and simple...
[wine/multimedia.git] / dlls / dinput8 / tests / device.c
blobc18a83a5c500c3a6eddc07f254ad8bfd8cbe9032
1 /*
2 * Copyright (c) 2011 Lucas Fialho Zawacki
3 * Copyright (c) 2006 Vitaliy Margolen
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 #define DIRECTINPUT_VERSION 0x0800
22 #define COBJMACROS
23 #include <windows.h>
25 #include "wine/test.h"
26 #include "windef.h"
27 #include "initguid.h"
28 #include "dinput.h"
30 static BOOL CALLBACK enum_by_semantics(
31 LPCDIDEVICEINSTANCE lpddi,
32 LPDIRECTINPUTDEVICE8 lpdid,
33 DWORD dwFlags,
34 DWORD dwRemaining,
35 LPVOID pvRef)
37 return DIENUM_CONTINUE;
41 static void test_action_mapping(void)
43 HRESULT hr;
44 HINSTANCE hinst = GetModuleHandle(NULL);
45 LPDIRECTINPUT8 pDI = NULL;
46 DIACTIONFORMAT af;
47 /* Dummy GUID */
48 const GUID ACTION_MAPPING_GUID = { 0x1, 0x2, 0x3, { 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb } };
50 DIACTION actionMapping[]=
52 /* axis */
53 { 0, 0x01008A01 /* DIAXIS_DRIVINGR_STEER */ , 0, { "Steer" } },
55 /* button */
56 { 1, 0x01000C01 /* DIBUTTON_DRIVINGR_SHIFTUP */ , 0, { "Upshift" } }
59 hr = CoCreateInstance(&CLSID_DirectInput8, 0, 1, &IID_IDirectInput8A, (LPVOID*)&pDI);
60 if (hr == DIERR_OLDDIRECTINPUTVERSION ||
61 hr == DIERR_BETADIRECTINPUTVERSION ||
62 hr == REGDB_E_CLASSNOTREG)
64 win_skip("ActionMapping requires dinput8\n");
65 return;
67 ok(SUCCEEDED(hr), "DirectInput8 Create failed: hr=%08x\n", hr);
68 if (FAILED(hr)) return;
70 hr = IDirectInput8_Initialize(pDI,hinst, DIRECTINPUT_VERSION);
71 if (hr == DIERR_OLDDIRECTINPUTVERSION || hr == DIERR_BETADIRECTINPUTVERSION)
73 win_skip("ActionMapping requires dinput8\n");
74 return;
76 ok(SUCCEEDED(hr), "DirectInput8 Initialize failed: hr=%08x\n", hr);
77 if (FAILED(hr)) return;
79 memset (&af, 0, sizeof(af));
80 af.dwSize = sizeof(af);
81 af.dwActionSize = sizeof(DIACTION);
82 af.dwDataSize = 4 * sizeof(actionMapping) / sizeof(actionMapping[0]);
83 af.dwNumActions = sizeof(actionMapping) / sizeof(actionMapping[0]);
84 af.rgoAction = actionMapping;
85 af.guidActionMap = ACTION_MAPPING_GUID;
86 af.dwGenre = 0x01000000; /* DIVIRTUAL_DRIVING_RACE */
88 hr = IDirectInput8_EnumDevicesBySemantics(pDI,0, &af,
89 enum_by_semantics, 0, 0);
91 ok(SUCCEEDED(hr), "EnumDevicesBySemantics failed: hr=%08x\n",hr);
93 /* The call fails with a zeroed GUID */
94 memset(&af.guidActionMap, 0, sizeof(GUID));
95 hr = IDirectInput8_EnumDevicesBySemantics(pDI,0, &af,
96 enum_by_semantics, 0, 0);
98 todo_wine ok(FAILED(hr), "EnumDevicesBySemantics succeeded with invalid GUID hr=%08x\n", hr);
102 START_TEST(device)
104 CoInitialize(NULL);
106 test_action_mapping();
108 CoUninitialize();