Commit f5e9079e authored by Rémi Bernon's avatar Rémi Bernon Committed by Alexandre Julliard

dinput/tests: Use dinput_test_(init|exit) for all tests.

parent 4e04c710
......@@ -18,14 +18,19 @@
#define DIRECTINPUT_VERSION 0x0700
#define COBJMACROS
#include <windows.h>
#include <stdarg.h>
#include <stddef.h>
#include <limits.h>
#include "wine/test.h"
#include "ntstatus.h"
#define WIN32_NO_STATUS
#include "windef.h"
#include "winbase.h"
#define COBJMACROS
#include "dinput.h"
#include <limits.h>
#include "dinput_test.h"
static const DIOBJECTDATAFORMAT obj_data_format[] = {
{ &GUID_YAxis, 16, DIDFT_OPTIONAL|DIDFT_AXIS |DIDFT_MAKEINSTANCE(1), 0},
......@@ -465,7 +470,6 @@ static void device_tests(void)
{
HRESULT hr;
IDirectInputA *pDI = NULL, *obj = NULL;
HINSTANCE hInstance = GetModuleHandleW(NULL);
HWND hwnd;
struct enum_data data;
......@@ -478,7 +482,7 @@ static void device_tests(void)
ok(SUCCEEDED(hr), "DirectInputCreateA() failed: %#lx\n", hr);
if (FAILED(hr)) return;
hr = IDirectInput_Initialize(pDI, hInstance, DIRECTINPUT_VERSION);
hr = IDirectInput_Initialize(pDI, instance, DIRECTINPUT_VERSION);
ok(SUCCEEDED(hr), "Initialize() failed: %#lx\n", hr);
if (FAILED(hr)) return;
......@@ -521,9 +525,9 @@ static void device_tests(void)
START_TEST(device)
{
CoInitialize(NULL);
dinput_test_init();
device_tests();
CoUninitialize();
dinput_test_exit();
}
......@@ -31,10 +31,7 @@
#include "dinput.h"
#include "hidusage.h"
#include "wine/test.h"
static HINSTANCE instance;
static BOOL localized; /* object names get translated */
#include "dinput_test.h"
struct enum_data {
IDirectInput8A *pDI;
......@@ -382,7 +379,6 @@ static void test_appdata_property_vs_map(struct enum_data *data)
static void test_action_mapping(void)
{
HRESULT hr;
HINSTANCE hinst = GetModuleHandleA(NULL);
IDirectInput8A *pDI = NULL;
DIACTIONFORMATA af;
DIPROPSTRING dps;
......@@ -400,7 +396,7 @@ static void test_action_mapping(void)
ok(SUCCEEDED(hr), "DirectInput8 Create failed: hr=%#lx\n", hr);
if (FAILED(hr)) return;
hr = IDirectInput8_Initialize(pDI,hinst, DIRECTINPUT_VERSION);
hr = IDirectInput8_Initialize(pDI, instance, DIRECTINPUT_VERSION);
if (hr == DIERR_OLDDIRECTINPUTVERSION || hr == DIERR_BETADIRECTINPUTVERSION)
{
win_skip("ActionMapping requires dinput8\n");
......@@ -520,7 +516,6 @@ static void test_action_mapping(void)
static void test_save_settings(void)
{
HRESULT hr;
HINSTANCE hinst = GetModuleHandleA(NULL);
IDirectInput8A *pDI = NULL;
DIACTIONFORMATA af;
IDirectInputDevice8A *pKey;
......@@ -552,7 +547,7 @@ static void test_save_settings(void)
ok (SUCCEEDED(hr), "DirectInput8 Create failed: hr=%#lx\n", hr);
if (FAILED(hr)) return;
hr = IDirectInput8_Initialize(pDI,hinst, DIRECTINPUT_VERSION);
hr = IDirectInput8_Initialize(pDI, instance, DIRECTINPUT_VERSION);
if (hr == DIERR_OLDDIRECTINPUTVERSION || hr == DIERR_BETADIRECTINPUTVERSION)
{
win_skip("ActionMapping requires dinput8\n");
......@@ -955,7 +950,6 @@ static void test_keyboard_events(void)
static void test_appdata_property(void)
{
HRESULT hr;
HINSTANCE hinst = GetModuleHandleA(NULL);
IDirectInputDevice8A *di_keyboard;
IDirectInput8A *pDI = NULL;
HWND hwnd;
......@@ -973,7 +967,7 @@ static void test_appdata_property(void)
ok(SUCCEEDED(hr), "DirectInput8 Create failed: hr=%#lx\n", hr);
if (FAILED(hr)) return;
hr = IDirectInput8_Initialize(pDI,hinst, DIRECTINPUT_VERSION);
hr = IDirectInput8_Initialize(pDI, instance, DIRECTINPUT_VERSION);
if (hr == DIERR_OLDDIRECTINPUTVERSION || hr == DIERR_BETADIRECTINPUTVERSION)
{
win_skip("DIPROP_APPDATA requires dinput8\n");
......@@ -1054,24 +1048,6 @@ static void test_appdata_property(void)
IDirectInput_Release(pDI);
}
#define check_member_( file, line, val, exp, fmt, member ) \
ok_( file, line )((val).member == (exp).member, "got " #member " " fmt ", expected " fmt "\n", \
(val).member, (exp).member)
#define check_member( val, exp, fmt, member ) \
check_member_( __FILE__, __LINE__, val, exp, fmt, member )
#define check_member_guid_( file, line, val, exp, member ) \
ok_( file, line )(IsEqualGUID( &(val).member, &(exp).member ), "got " #member " %s, expected %s\n", \
debugstr_guid( &(val).member ), debugstr_guid( &(exp).member ))
#define check_member_guid( val, exp, member ) \
check_member_guid_( __FILE__, __LINE__, val, exp, member )
#define check_member_wstr_( file, line, val, exp, member ) \
ok_( file, line )(!wcscmp( (val).member, (exp).member ), "got " #member " %s, expected %s\n", \
debugstr_w((val).member), debugstr_w((exp).member))
#define check_member_wstr( val, exp, member ) \
check_member_wstr_( __FILE__, __LINE__, val, exp, member )
struct check_objects_todos
{
BOOL offset;
......@@ -1838,9 +1814,7 @@ static void test_keyboard_info(void)
START_TEST(device8)
{
instance = GetModuleHandleW( NULL );
CoInitialize(NULL);
dinput_test_init();
test_mouse_info();
test_keyboard_info();
......@@ -1850,5 +1824,5 @@ START_TEST(device8)
test_keyboard_events();
test_appdata_property();
CoUninitialize();
dinput_test_exit();
}
......@@ -50,6 +50,7 @@ extern const GUID expect_guid_product;
extern const WCHAR expect_path[];
extern const WCHAR expect_path_end[];
extern typeof(DirectInputCreateEx) *pDirectInputCreateEx;
extern HANDLE device_added, device_removed;
extern HINSTANCE instance;
extern BOOL localized; /* object names get translated */
......@@ -62,7 +63,7 @@ void bus_device_stop(void);
void cleanup_registry_keys(void);
#define dinput_test_init() dinput_test_init_( __FILE__, __LINE__ )
BOOL dinput_test_init_( const char *file, int line );
void dinput_test_init_( const char *file, int line );
void dinput_test_exit(void);
HRESULT dinput_test_create_device( DWORD version, DIDEVICEINSTANCEW *devinst, IDirectInputDevice8W **device );
......
......@@ -6405,10 +6405,9 @@ done:
START_TEST( force_feedback )
{
if (!dinput_test_init()) return;
dinput_test_init();
if (!bus_device_start()) goto done;
CoInitialize( NULL );
if (test_force_feedback_joystick( 0x800 ))
{
test_force_feedback_joystick( 0x500 );
......@@ -6416,7 +6415,6 @@ START_TEST( force_feedback )
test_device_managed_effect();
test_windows_gaming_input();
}
CoUninitialize();
done:
bus_device_stop();
......
......@@ -44,7 +44,6 @@
#include "objbase.h"
#define COBJMACROS
#include "dinput.h"
#include "initguid.h"
#include "ddk/wdm.h"
......@@ -52,13 +51,16 @@
#include "ddk/hidsdi.h"
#include "ddk/hidpi.h"
#include "ddk/hidport.h"
#include "hidusage.h"
#include "devguid.h"
#include "dinput.h"
#include "dinputd.h"
#include "hidusage.h"
#include "wine/mssign.h"
#include "dinput_test.h"
typeof(DirectInputCreateEx) *pDirectInputCreateEx;
HINSTANCE instance;
BOOL localized; /* object names get translated */
......@@ -475,6 +477,8 @@ void bus_device_stop(void)
DWORD size;
BOOL ret;
if (!test_data) return;
set = SetupDiCreateDeviceInfoList( NULL, NULL );
ok( set != INVALID_HANDLE_VALUE, "failed to create device list, error %lu\n", GetLastError() );
......@@ -600,6 +604,8 @@ BOOL bus_device_start(void)
HDEVINFO set;
FILE *f;
if (!test_data) return FALSE;
old_mute_threshold = winetest_mute_threshold;
winetest_mute_threshold = 1;
......@@ -3459,52 +3465,56 @@ DWORD WINAPI monitor_thread_proc( void *stop_event )
return 0;
}
BOOL dinput_test_init_( const char *file, int line )
void dinput_test_init_( const char *file, int line )
{
BOOL is_wow64;
monitor_stop = CreateEventW( NULL, FALSE, FALSE, NULL );
ok( !!monitor_stop, "CreateEventW failed, error %lu\n", GetLastError() );
ok_(file, line)( !!monitor_stop, "CreateEventW failed, error %lu\n", GetLastError() );
device_added = CreateEventW( NULL, FALSE, FALSE, NULL );
ok( !!device_added, "CreateEventW failed, error %lu\n", GetLastError() );
ok_(file, line)( !!device_added, "CreateEventW failed, error %lu\n", GetLastError() );
device_removed = CreateEventW( NULL, FALSE, FALSE, NULL );
ok( !!device_removed, "CreateEventW failed, error %lu\n", GetLastError() );
ok_(file, line)( !!device_removed, "CreateEventW failed, error %lu\n", GetLastError() );
monitor_thread = CreateThread( NULL, 0, monitor_thread_proc, monitor_stop, 0, NULL );
ok( !!monitor_thread, "CreateThread failed, error %lu\n", GetLastError() );
ok_(file, line)( !!monitor_thread, "CreateThread failed, error %lu\n", GetLastError() );
CoInitialize( NULL );
subtest_(file, line)( "hid" );
instance = GetModuleHandleW( NULL );
localized = GetUserDefaultLCID() != MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT);
pSignerSign = (void *)GetProcAddress( LoadLibraryW( L"mssign32" ), "SignerSign" );
pDirectInputCreateEx = (void *)GetProcAddress( LoadLibraryW(L"dinput.dll"), "DirectInputCreateEx" );
if (IsWow64Process( GetCurrentProcess(), &is_wow64 ) && is_wow64)
{
skip( "Running in WoW64.\n" );
return FALSE;
skip_(file, line)( "Skipping driver tests: running in wow64.\n" );
return;
}
test_data_mapping = CreateFileMappingW( INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0,
sizeof(*test_data), L"Global\\winetest_dinput_section" );
if (!test_data_mapping && GetLastError() == ERROR_ACCESS_DENIED)
{
win_skip( "Failed to create test data mapping.\n" );
return FALSE;
win_skip_(file, line)( "Skipping driver tests: failed to create mapping.\n" );
return;
}
ok( !!test_data_mapping, "got error %lu\n", GetLastError() );
ok_(file, line)( !!test_data_mapping, "got error %lu\n", GetLastError() );
test_data = MapViewOfFile( test_data_mapping, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 1024 );
ok_(file, line)( !!test_data, "MapViewOfFile failed, error %lu\n", GetLastError() );
test_data->running_under_wine = !strcmp( winetest_platform, "wine" );
test_data->winetest_report_success = winetest_report_success;
test_data->winetest_debug = winetest_debug;
okfile = CreateFileW( L"C:\\windows\\winetest_dinput_okfile", GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, 0, NULL );
ok( okfile != INVALID_HANDLE_VALUE, "failed to create file, error %lu\n", GetLastError() );
ok_(file, line)( okfile != INVALID_HANDLE_VALUE, "failed to create file, error %lu\n", GetLastError() );
subtest( "driver" );
subtest( "driver_bus" );
subtest( "driver_hid" );
subtest( "driver_hid_poll" );
return TRUE;
subtest_(file, line)( "hid" );
subtest_(file, line)( "driver" );
subtest_(file, line)( "driver_bus" );
subtest_(file, line)( "driver_hid" );
subtest_(file, line)( "driver_hid_poll" );
}
void dinput_test_exit(void)
......@@ -3520,6 +3530,8 @@ void dinput_test_exit(void)
CloseHandle( monitor_stop );
CloseHandle( device_removed );
CloseHandle( device_added );
CoUninitialize();
}
BOOL CALLBACK find_test_device( const DIDEVICEINSTANCEW *devinst, void *context )
......@@ -3931,7 +3943,7 @@ done:
START_TEST( hid )
{
if (!dinput_test_init()) return;
dinput_test_init();
test_bus_driver();
......
......@@ -1218,10 +1218,9 @@ next:
START_TEST( hotplug )
{
if (!dinput_test_init()) return;
dinput_test_init();
if (!bus_device_start()) goto done;
CoInitialize( NULL );
if (test_input_lost( 0x500 ))
{
test_input_lost( 0x700 );
......@@ -1230,7 +1229,6 @@ START_TEST( hotplug )
test_RegisterDeviceNotification();
test_windows_gaming_input();
}
CoUninitialize();
done:
bus_device_stop();
......
......@@ -18,18 +18,19 @@
#define DIRECTINPUT_VERSION 0x0700
#define COBJMACROS
#include <windows.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stddef.h>
#include "wine/test.h"
#include "ntstatus.h"
#define WIN32_NO_STATUS
#include "windef.h"
#include "wingdi.h"
#include "winbase.h"
#define COBJMACROS
#include "dinput.h"
#include "dinput_test.h"
typedef struct tagUserData {
IDirectInputA *pDI;
DWORD version;
......@@ -317,7 +318,6 @@ static BOOL CALLBACK EnumJoysticks(const DIDEVICEINSTANCEA *lpddi, void *pvRef)
LPDIRECTINPUTEFFECT effect = NULL;
LONG cnt1, cnt2;
HWND real_hWnd;
HINSTANCE hInstance = GetModuleHandleW(NULL);
DIPROPDWORD dip_gain_set, dip_gain_get;
struct effect_enum effect_data;
......@@ -549,7 +549,7 @@ static BOOL CALLBACK EnumJoysticks(const DIDEVICEINSTANCEA *lpddi, void *pvRef)
* - a visible window
*/
real_hWnd = CreateWindowExA(0, "EDIT", "Test text", 0, 10, 10, 300, 300, NULL, NULL,
hInstance, NULL);
instance, NULL);
ok(real_hWnd!=0,"CreateWindowExA failed: %p\n", real_hWnd);
ShowWindow(real_hWnd, SW_SHOW);
hr = IDirectInputDevice_Unacquire(pJoystick);
......@@ -598,7 +598,7 @@ static BOOL CALLBACK EnumJoysticks(const DIDEVICEINSTANCEA *lpddi, void *pvRef)
GUID guid = {0};
DIEFFECT effect_empty;
hr = IDirectInputEffect_Initialize(effect, hInstance, data->version,
hr = IDirectInputEffect_Initialize(effect, instance, data->version,
&effect_data.guid);
ok(hr==DI_OK,"IDirectInputEffect_Initialize failed: %#lx\n", hr);
......@@ -915,10 +915,9 @@ static void joystick_tests(DWORD version)
HRESULT hr;
IDirectInputA *pDI;
ULONG ref;
HINSTANCE hInstance = GetModuleHandleW(NULL);
trace("-- Testing Direct Input Version %#lx --\n", version);
hr = DirectInputCreateA(hInstance, version, &pDI, NULL);
hr = DirectInputCreateA(instance, version, &pDI, NULL);
ok(hr==DI_OK||hr==DIERR_OLDDIRECTINPUTVERSION, "DirectInputCreateA() failed: %#lx\n", hr);
if (hr==DI_OK && pDI!=0) {
UserData data;
......@@ -938,9 +937,8 @@ static void test_enum_feedback(void)
HRESULT hr;
IDirectInputA *pDI;
ULONG ref;
HINSTANCE hInstance = GetModuleHandleW(NULL);
hr = DirectInputCreateA(hInstance, 0x0700, &pDI, NULL);
hr = DirectInputCreateA(instance, 0x0700, &pDI, NULL);
ok(hr==DI_OK||hr==DIERR_OLDDIRECTINPUTVERSION, "DirectInputCreateA() failed: %#lx\n", hr);
if (hr==DI_OK && pDI!=0) {
hr = IDirectInput_EnumDevices(pDI, 0, EnumAllFeedback, NULL, DIEDFL_ATTACHEDONLY | DIEDFL_FORCEFEEDBACK);
......@@ -953,7 +951,7 @@ static void test_enum_feedback(void)
START_TEST(joystick)
{
CoInitialize(NULL);
dinput_test_init();
joystick_tests(0x0700);
joystick_tests(0x0500);
......@@ -961,5 +959,5 @@ START_TEST(joystick)
test_enum_feedback();
CoUninitialize();
dinput_test_exit();
}
......@@ -4163,10 +4163,9 @@ done:
START_TEST( joystick8 )
{
if (!dinput_test_init()) return;
dinput_test_init();
if (!bus_device_start()) goto done;
CoInitialize( NULL );
if (test_device_types( 0x800 ))
{
/* This needs to be done before doing anything involving dinput.dll
......@@ -4184,7 +4183,6 @@ START_TEST( joystick8 )
test_driving_wheel_axes();
test_windows_gaming_input();
}
CoUninitialize();
done:
bus_device_stop();
......
......@@ -18,20 +18,18 @@
#define DIRECTINPUT_VERSION 0x0700
#define COBJMACROS
#include <windows.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stddef.h>
#include "wine/test.h"
#include "ntstatus.h"
#define WIN32_NO_STATUS
#include "windef.h"
#include "wingdi.h"
#include "winbase.h"
#define COBJMACROS
#include "dinput.h"
/* to make things easier with PSDK without a dinput.lib */
static HRESULT (WINAPI *pDirectInputCreateA)(HINSTANCE,DWORD,IDirectInputA **,IUnknown *);
#include "dinput_test.h"
static void pump_messages(void)
{
......@@ -513,11 +511,10 @@ static void keyboard_tests(DWORD version)
{
HRESULT hr;
IDirectInputA *pDI = NULL;
HINSTANCE hInstance = GetModuleHandleW(NULL);
HWND hwnd;
ULONG ref = 0;
hr = pDirectInputCreateA(hInstance, version, &pDI, NULL);
hr = DirectInputCreateA(instance, version, &pDI, NULL);
if (hr == DIERR_OLDDIRECTINPUTVERSION)
{
skip("Tests require a newer dinput version\n");
......@@ -554,11 +551,9 @@ static void keyboard_tests(DWORD version)
START_TEST(keyboard)
{
pDirectInputCreateA = (void *)GetProcAddress(GetModuleHandleA("dinput.dll"), "DirectInputCreateA");
CoInitialize(NULL);
dinput_test_init();
keyboard_tests(0x0700);
CoUninitialize();
dinput_test_exit();
}
......@@ -19,17 +19,19 @@
#define DIRECTINPUT_VERSION 0x0700
#define COBJMACROS
#include <windows.h>
#include <math.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stddef.h>
#include "wine/test.h"
#include "ntstatus.h"
#define WIN32_NO_STATUS
#include "windef.h"
#include "wingdi.h"
#include "winbase.h"
#define COBJMACROS
#include "dinput.h"
#include "dinput_test.h"
static const HRESULT SetCoop_null_window[16] = {
E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG,
E_INVALIDARG, E_HANDLE, E_HANDLE, E_INVALIDARG,
......@@ -290,11 +292,10 @@ static void mouse_tests(void)
{
HRESULT hr;
IDirectInputA *pDI = NULL;
HINSTANCE hInstance = GetModuleHandleW(NULL);
HWND hwnd;
ULONG ref = 0;
hr = DirectInputCreateA(hInstance, DIRECTINPUT_VERSION, &pDI, NULL);
hr = DirectInputCreateA(instance, DIRECTINPUT_VERSION, &pDI, NULL);
if (hr == DIERR_OLDDIRECTINPUTVERSION)
{
skip("Tests require a newer dinput version\n");
......@@ -323,9 +324,9 @@ static void mouse_tests(void)
START_TEST(mouse)
{
CoInitialize(NULL);
dinput_test_init();
mouse_tests();
CoUninitialize();
dinput_test_exit();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment