Squashed 'external/gainput/' content from commit 2be0a50
git-subtree-dir: external/gainput git-subtree-split: 2be0a50089eafcc6fccb66142180082e48f27f4c
This commit is contained in:
37
test/CMakeLists.txt
Normal file
37
test/CMakeLists.txt
Normal file
@@ -0,0 +1,37 @@
|
||||
|
||||
project(gainputtest)
|
||||
|
||||
include_directories(../lib/include/)
|
||||
include_directories(../extern/catch/)
|
||||
|
||||
file(GLOB_RECURSE sources *.cpp)
|
||||
|
||||
if(CMAKE_COMPILER_IS_GNUCXX)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
|
||||
endif()
|
||||
|
||||
if(ANDROID)
|
||||
add_library(gainputtest SHARED ${sources})
|
||||
else()
|
||||
add_executable(gainputtest WIN32 ${sources})
|
||||
endif()
|
||||
|
||||
if(APPLE AND NOT IOS)
|
||||
find_library(APPKIT AppKit)
|
||||
else()
|
||||
set(APPKIT "")
|
||||
endif()
|
||||
|
||||
target_link_libraries(gainputtest gainputstatic)
|
||||
|
||||
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
||||
target_link_libraries(gainputtest X11 GL rt)
|
||||
elseif(WIN32)
|
||||
target_link_libraries(gainputtest ${XINPUT} ws2_32)
|
||||
elseif(APPLE)
|
||||
target_link_libraries(gainputtest ${FOUNDATION} ${IOKIT} ${APPKIT})
|
||||
endif()
|
||||
|
||||
if(MSVC)
|
||||
set_target_properties(gainputtest PROPERTIES LINK_FLAGS "/SUBSYSTEM:CONSOLE")
|
||||
endif(MSVC)
|
||||
17
test/test.cpp
Normal file
17
test/test.cpp
Normal file
@@ -0,0 +1,17 @@
|
||||
|
||||
#if defined(__ANDROID__) || defined(ANDROID)
|
||||
#include <android_native_app_glue.h>
|
||||
#define CATCH_CONFIG_RUNNER
|
||||
#include "catch.hpp"
|
||||
void android_main(struct android_app* stateMain)
|
||||
{
|
||||
app_dummy();
|
||||
char* cmd[] = {"gainputtest"};
|
||||
Catch::Session().run( 1, cmd );
|
||||
}
|
||||
#else
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include "catch.hpp"
|
||||
#endif
|
||||
|
||||
|
||||
184
test/test_inputdevice.cpp
Normal file
184
test/test_inputdevice.cpp
Normal file
@@ -0,0 +1,184 @@
|
||||
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <gainput/gainput.h>
|
||||
|
||||
using namespace gainput;
|
||||
|
||||
TEST_CASE("InputDevice/keyboard", "")
|
||||
{
|
||||
InputManager manager;
|
||||
|
||||
InputDeviceKeyboard* device = manager.CreateAndGetDevice<InputDeviceKeyboard>();
|
||||
|
||||
REQUIRE(device);
|
||||
REQUIRE(device->GetIndex() == 0);
|
||||
REQUIRE(device->GetDeviceId() != InvalidDeviceId);
|
||||
REQUIRE(device->GetType() == InputDevice::DT_KEYBOARD);
|
||||
REQUIRE(device->GetTypeName());
|
||||
|
||||
REQUIRE(device->IsValidButtonId(KeyEscape));
|
||||
REQUIRE(device->IsValidButtonId(KeyReturn));
|
||||
REQUIRE(device->IsValidButtonId(Key1));
|
||||
REQUIRE(device->IsValidButtonId(KeyA));
|
||||
REQUIRE(device->IsValidButtonId(KeyZ));
|
||||
REQUIRE(device->IsValidButtonId(KeySpace));
|
||||
|
||||
char buf[32];
|
||||
REQUIRE(device->GetButtonName(KeyF10, buf, 32) > 0);
|
||||
REQUIRE(device->GetButtonName(KeyRightParenthesis, buf, 32) > 0);
|
||||
REQUIRE(device->GetButtonName(KeyPeriod, buf, 32) > 0);
|
||||
REQUIRE(device->GetButtonName(KeyV, buf, 32) > 0);
|
||||
REQUIRE(device->GetButtonName(KeySpace, buf, 32) > 0);
|
||||
|
||||
REQUIRE(device->GetButtonType(KeyEscape) == BT_BOOL);
|
||||
REQUIRE(device->GetButtonType(Key2) == BT_BOOL);
|
||||
REQUIRE(device->GetButtonType(KeyD) == BT_BOOL);
|
||||
REQUIRE(device->GetButtonType(KeyBackSpace) == BT_BOOL);
|
||||
|
||||
REQUIRE(device->GetButtonByName("space") == KeySpace);
|
||||
REQUIRE(device->GetButtonByName("5") == Key5);
|
||||
|
||||
REQUIRE(device->GetInputState());
|
||||
REQUIRE(device->GetPreviousInputState());
|
||||
|
||||
REQUIRE(device->IsTextInputEnabled());
|
||||
device->SetTextInputEnabled(false);
|
||||
REQUIRE(!device->IsTextInputEnabled());
|
||||
}
|
||||
|
||||
TEST_CASE("InputDevice/mouse", "")
|
||||
{
|
||||
InputManager manager;
|
||||
|
||||
InputDeviceMouse* device = manager.CreateAndGetDevice<InputDeviceMouse>();
|
||||
|
||||
REQUIRE(device);
|
||||
REQUIRE(device->GetIndex() == 0);
|
||||
REQUIRE(device->GetDeviceId() != InvalidDeviceId);
|
||||
REQUIRE(device->GetType() == InputDevice::DT_MOUSE);
|
||||
REQUIRE(device->GetTypeName());
|
||||
|
||||
REQUIRE(device->IsValidButtonId(MouseButtonLeft));
|
||||
REQUIRE(device->IsValidButtonId(MouseButtonMiddle));
|
||||
REQUIRE(device->IsValidButtonId(MouseButtonRight));
|
||||
REQUIRE(device->IsValidButtonId(MouseAxisX));
|
||||
REQUIRE(device->IsValidButtonId(MouseAxisY));
|
||||
|
||||
char buf[32];
|
||||
REQUIRE(device->GetButtonName(MouseButtonLeft, buf, 32) > 0);
|
||||
REQUIRE(device->GetButtonName(MouseButtonRight, buf, 32) > 0);
|
||||
REQUIRE(device->GetButtonName(MouseButton14, buf, 32) > 0);
|
||||
REQUIRE(device->GetButtonName(MouseAxisX, buf, 32) > 0);
|
||||
REQUIRE(device->GetButtonName(MouseAxisY, buf, 32) > 0);
|
||||
|
||||
REQUIRE(device->GetButtonType(MouseButtonLeft) == BT_BOOL);
|
||||
REQUIRE(device->GetButtonType(MouseButtonMiddle) == BT_BOOL);
|
||||
REQUIRE(device->GetButtonType(MouseButtonRight) == BT_BOOL);
|
||||
REQUIRE(device->GetButtonType(MouseAxisX) == BT_FLOAT);
|
||||
REQUIRE(device->GetButtonType(MouseAxisY) == BT_FLOAT);
|
||||
|
||||
REQUIRE(device->GetButtonByName("mouse_left") == MouseButtonLeft);
|
||||
REQUIRE(device->GetButtonByName("mouse_right") == MouseButtonRight);
|
||||
REQUIRE(device->GetButtonByName("mouse_11") == MouseButton11);
|
||||
REQUIRE(device->GetButtonByName("mouse_x") == MouseAxisX);
|
||||
REQUIRE(device->GetButtonByName("mouse_y") == MouseAxisY);
|
||||
|
||||
REQUIRE(device->GetInputState());
|
||||
REQUIRE(device->GetPreviousInputState());
|
||||
}
|
||||
|
||||
TEST_CASE("InputDevice/pad", "")
|
||||
{
|
||||
InputManager manager;
|
||||
|
||||
InputDevicePad* device = manager.CreateAndGetDevice<InputDevicePad>();
|
||||
|
||||
REQUIRE(device);
|
||||
REQUIRE(device->GetIndex() == 0);
|
||||
REQUIRE(device->GetDeviceId() != InvalidDeviceId);
|
||||
REQUIRE(device->GetType() == InputDevice::DT_PAD);
|
||||
REQUIRE(device->GetTypeName());
|
||||
|
||||
REQUIRE(device->IsValidButtonId(PadButtonLeftStickX));
|
||||
REQUIRE(device->IsValidButtonId(PadButtonLeftStickY));
|
||||
REQUIRE(device->IsValidButtonId(PadButtonLeft));
|
||||
REQUIRE(device->IsValidButtonId(PadButtonRight));
|
||||
REQUIRE(device->IsValidButtonId(PadButtonUp));
|
||||
REQUIRE(device->IsValidButtonId(PadButtonDown));
|
||||
REQUIRE(device->IsValidButtonId(PadButtonA));
|
||||
REQUIRE(device->IsValidButtonId(PadButtonB));
|
||||
REQUIRE(device->IsValidButtonId(PadButtonX));
|
||||
REQUIRE(device->IsValidButtonId(PadButtonY));
|
||||
REQUIRE(device->IsValidButtonId(PadButtonL1));
|
||||
REQUIRE(device->IsValidButtonId(PadButtonR1));
|
||||
|
||||
char buf[32];
|
||||
REQUIRE(device->GetButtonName(PadButtonLeftStickX, buf, 32) > 0);
|
||||
REQUIRE(device->GetButtonName(PadButtonB, buf, 32) > 0);
|
||||
REQUIRE(device->GetButtonName(PadButtonAxis19, buf, 32) > 0);
|
||||
REQUIRE(device->GetButtonName(PadButtonL2, buf, 32) > 0);
|
||||
REQUIRE(device->GetButtonName(PadButtonGyroscopeY, buf, 32) > 0);
|
||||
|
||||
REQUIRE(device->GetButtonType(PadButtonLeft) == BT_BOOL);
|
||||
REQUIRE(device->GetButtonType(PadButtonDown) == BT_BOOL);
|
||||
REQUIRE(device->GetButtonType(PadButtonA) == BT_BOOL);
|
||||
REQUIRE(device->GetButtonType(PadButtonB) == BT_BOOL);
|
||||
REQUIRE(device->GetButtonType(PadButtonL1) == BT_BOOL);
|
||||
REQUIRE(device->GetButtonType(PadButtonLeftStickX) == BT_FLOAT);
|
||||
REQUIRE(device->GetButtonType(PadButtonLeftStickY) == BT_FLOAT);
|
||||
REQUIRE(device->GetButtonType(PadButtonAxis15) == BT_FLOAT);
|
||||
|
||||
REQUIRE(device->GetButtonByName("pad_left_stick_x") == PadButtonLeftStickX);
|
||||
REQUIRE(device->GetButtonByName("pad_left_stick_y") == PadButtonLeftStickY);
|
||||
REQUIRE(device->GetButtonByName("pad_acceleration_x") == PadButtonAccelerationX);
|
||||
REQUIRE(device->GetButtonByName("pad_button_a") == PadButtonA);
|
||||
REQUIRE(device->GetButtonByName("pad_button_y") == PadButtonY);
|
||||
|
||||
REQUIRE(device->GetInputState());
|
||||
REQUIRE(device->GetPreviousInputState());
|
||||
}
|
||||
|
||||
TEST_CASE("InputDevice/touch", "")
|
||||
{
|
||||
InputManager manager;
|
||||
|
||||
InputDeviceTouch* device = manager.CreateAndGetDevice<InputDeviceTouch>();
|
||||
|
||||
REQUIRE(device);
|
||||
REQUIRE(device->GetIndex() == 0);
|
||||
REQUIRE(device->GetDeviceId() != InvalidDeviceId);
|
||||
REQUIRE(device->GetType() == InputDevice::DT_TOUCH);
|
||||
REQUIRE(device->GetTypeName());
|
||||
|
||||
REQUIRE(device->IsValidButtonId(Touch0Down));
|
||||
REQUIRE(device->IsValidButtonId(Touch0X));
|
||||
REQUIRE(device->IsValidButtonId(Touch0Y));
|
||||
REQUIRE(device->IsValidButtonId(Touch1Down));
|
||||
REQUIRE(device->IsValidButtonId(Touch1X));
|
||||
REQUIRE(device->IsValidButtonId(Touch1Y));
|
||||
|
||||
char buf[32];
|
||||
REQUIRE(device->GetButtonName(Touch0Down, buf, 32) > 0);
|
||||
REQUIRE(device->GetButtonName(Touch0X, buf, 32) > 0);
|
||||
REQUIRE(device->GetButtonName(Touch0Y, buf, 32) > 0);
|
||||
REQUIRE(device->GetButtonName(Touch2Down, buf, 32) > 0);
|
||||
|
||||
REQUIRE(device->GetButtonType(Touch0Down) == BT_BOOL);
|
||||
REQUIRE(device->GetButtonType(Touch0X) == BT_FLOAT);
|
||||
REQUIRE(device->GetButtonType(Touch0Y) == BT_FLOAT);
|
||||
REQUIRE(device->GetButtonType(Touch3Down) == BT_BOOL);
|
||||
REQUIRE(device->GetButtonType(Touch3X) == BT_FLOAT);
|
||||
REQUIRE(device->GetButtonType(Touch3Y) == BT_FLOAT);
|
||||
|
||||
REQUIRE(device->GetButtonByName("touch_0_down") == Touch0Down);
|
||||
REQUIRE(device->GetButtonByName("touch_0_x") == Touch0X);
|
||||
REQUIRE(device->GetButtonByName("touch_0_y") == Touch0Y);
|
||||
REQUIRE(device->GetButtonByName("touch_6_down") == Touch6Down);
|
||||
REQUIRE(device->GetButtonByName("touch_6_x") == Touch6X);
|
||||
REQUIRE(device->GetButtonByName("touch_6_y") == Touch6Y);
|
||||
|
||||
REQUIRE(device->GetInputState());
|
||||
REQUIRE(device->GetPreviousInputState());
|
||||
}
|
||||
|
||||
79
test/test_inputmanager.cpp
Normal file
79
test/test_inputmanager.cpp
Normal file
@@ -0,0 +1,79 @@
|
||||
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <gainput/gainput.h>
|
||||
|
||||
using namespace gainput;
|
||||
|
||||
TEST_CASE("InputManager/CreateDevice", "")
|
||||
{
|
||||
InputManager manager;
|
||||
|
||||
const DeviceId deviceId = manager.CreateDevice<InputDeviceKeyboard>();
|
||||
REQUIRE(deviceId != InvalidDeviceId);
|
||||
|
||||
InputDevice* device = manager.GetDevice(deviceId);
|
||||
REQUIRE(device);
|
||||
REQUIRE(device->GetType() == InputDevice::DT_KEYBOARD);
|
||||
REQUIRE(device->GetIndex() == 0);
|
||||
|
||||
const DeviceId deviceId2 = manager.CreateDevice<InputDeviceMouse>();
|
||||
REQUIRE(deviceId2 != InvalidDeviceId);
|
||||
|
||||
InputDevice* device2 = manager.GetDevice(deviceId2);
|
||||
REQUIRE(device2);
|
||||
REQUIRE(device2->GetType() == InputDevice::DT_MOUSE);
|
||||
REQUIRE(device2->GetIndex() == 0);
|
||||
|
||||
InputDevicePad* device3 = manager.CreateAndGetDevice<InputDevicePad>();
|
||||
REQUIRE(device3);
|
||||
REQUIRE(device3->GetType() == InputDevice::DT_PAD);
|
||||
REQUIRE(device3->GetIndex() == 0);
|
||||
REQUIRE(device3->GetDeviceId() != InvalidDeviceId);
|
||||
}
|
||||
|
||||
TEST_CASE("InputManager/FindDeviceId", "")
|
||||
{
|
||||
InputManager manager;
|
||||
const DeviceId deviceId = manager.CreateDevice<InputDeviceKeyboard>();
|
||||
const InputDevice* device = manager.GetDevice(deviceId);
|
||||
const DeviceId deviceId2 = manager.CreateDevice<InputDeviceMouse>();
|
||||
const InputDevice* device2 = manager.GetDevice(deviceId2);
|
||||
const DeviceId deviceId3 = manager.CreateDevice<InputDevicePad>();
|
||||
const InputDevice* device3 = manager.GetDevice(deviceId3);
|
||||
|
||||
REQUIRE(manager.FindDeviceId(device->GetTypeName(), device->GetIndex()) == deviceId);
|
||||
REQUIRE(manager.FindDeviceId(device->GetType(), device->GetIndex()) == deviceId);
|
||||
|
||||
REQUIRE(manager.FindDeviceId(device2->GetTypeName(), device2->GetIndex()) == deviceId2);
|
||||
REQUIRE(manager.FindDeviceId(device2->GetType(), device2->GetIndex()) == deviceId2);
|
||||
|
||||
REQUIRE(manager.FindDeviceId(device3->GetTypeName(), device3->GetIndex()) == deviceId3);
|
||||
REQUIRE(manager.FindDeviceId(device3->GetType(), device3->GetIndex()) == deviceId3);
|
||||
}
|
||||
|
||||
TEST_CASE("InputManager/GetDeviceCountByType", "")
|
||||
{
|
||||
InputManager manager;
|
||||
|
||||
for (int type = InputDevice::DT_MOUSE; type < InputDevice::DT_COUNT; ++type)
|
||||
{
|
||||
REQUIRE(manager.GetDeviceCountByType(InputDevice::DeviceType(type)) == 0);
|
||||
}
|
||||
|
||||
manager.CreateDevice<InputDeviceKeyboard>();
|
||||
manager.CreateDevice<InputDeviceMouse>();
|
||||
manager.CreateDevice<InputDevicePad>();
|
||||
|
||||
REQUIRE(manager.GetDeviceCountByType(InputDevice::DT_KEYBOARD) == 1);
|
||||
REQUIRE(manager.GetDeviceCountByType(InputDevice::DT_MOUSE) == 1);
|
||||
REQUIRE(manager.GetDeviceCountByType(InputDevice::DT_PAD) == 1);
|
||||
REQUIRE(manager.GetDeviceCountByType(InputDevice::DT_TOUCH) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("InputManager/GetAnyButtonDown", "")
|
||||
{
|
||||
InputManager manager;
|
||||
REQUIRE(manager.GetAnyButtonDown(0, 0) == 0);
|
||||
}
|
||||
|
||||
177
test/test_inputmap.cpp
Normal file
177
test/test_inputmap.cpp
Normal file
@@ -0,0 +1,177 @@
|
||||
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <gainput/gainput.h>
|
||||
|
||||
using namespace gainput;
|
||||
|
||||
enum TestButtons
|
||||
{
|
||||
ButtonA,
|
||||
ButtonStart = ButtonA,
|
||||
ButtonB,
|
||||
ButtonC,
|
||||
ButtonD,
|
||||
ButtonE,
|
||||
ButtonF,
|
||||
ButtonG,
|
||||
ButtonCount
|
||||
};
|
||||
|
||||
TEST_CASE("InputMap/create", "")
|
||||
{
|
||||
InputManager manager;
|
||||
InputMap map(manager, "testmap");
|
||||
|
||||
REQUIRE(&manager == &map.GetManager());
|
||||
REQUIRE(map.GetName());
|
||||
REQUIRE(strcmp(map.GetName(), "testmap") == 0);
|
||||
|
||||
for (int b = ButtonStart; b < ButtonCount; ++b)
|
||||
{
|
||||
REQUIRE(!map.IsMapped(b));
|
||||
}
|
||||
|
||||
InputMap map2(manager);
|
||||
REQUIRE(!map2.GetName());
|
||||
}
|
||||
|
||||
TEST_CASE("InputMap/map_bool", "")
|
||||
{
|
||||
InputManager manager;
|
||||
const DeviceId keyboardId = manager.CreateDevice<InputDeviceKeyboard>();
|
||||
const DeviceId mouseId = manager.CreateDevice<InputDeviceMouse>();
|
||||
InputMap map(manager, "testmap");
|
||||
|
||||
REQUIRE(map.MapBool(ButtonA, keyboardId, KeyA));
|
||||
REQUIRE(map.MapBool(ButtonA, keyboardId, KeyB));
|
||||
REQUIRE(map.MapBool(ButtonA, keyboardId, KeyEscape));
|
||||
REQUIRE(map.MapBool(ButtonA, mouseId, MouseButtonLeft));
|
||||
REQUIRE(map.IsMapped(ButtonA));
|
||||
|
||||
REQUIRE(map.MapBool(ButtonB, keyboardId, KeyF2));
|
||||
REQUIRE(map.MapBool(ButtonB, mouseId, MouseButtonLeft));
|
||||
REQUIRE(map.IsMapped(ButtonB));
|
||||
|
||||
map.Clear();
|
||||
for (int b = ButtonStart; b < ButtonCount; ++b)
|
||||
{
|
||||
REQUIRE(!map.IsMapped(b));
|
||||
}
|
||||
|
||||
REQUIRE(map.MapBool(ButtonA, mouseId, MouseButtonRight));
|
||||
REQUIRE(map.IsMapped(ButtonA));
|
||||
|
||||
map.Unmap(ButtonA);
|
||||
REQUIRE(!map.IsMapped(ButtonA));
|
||||
|
||||
DeviceButtonSpec mappings[32];
|
||||
REQUIRE(map.GetMappings(ButtonA, mappings, 32) == 0);
|
||||
|
||||
REQUIRE(map.MapBool(ButtonA, mouseId, MouseButtonMiddle));
|
||||
REQUIRE(map.MapBool(ButtonA, keyboardId, KeyD));
|
||||
REQUIRE(map.MapBool(ButtonD, keyboardId, KeyB));
|
||||
|
||||
REQUIRE(map.GetMappings(ButtonA, mappings, 32) == 2);
|
||||
REQUIRE(mappings[0].deviceId == mouseId);
|
||||
REQUIRE(mappings[0].buttonId == MouseButtonMiddle);
|
||||
REQUIRE(mappings[1].deviceId == keyboardId);
|
||||
REQUIRE(mappings[1].buttonId == KeyD);
|
||||
|
||||
char buf[32];
|
||||
REQUIRE(map.GetUserButtonName(ButtonA, buf, 32));
|
||||
|
||||
REQUIRE(map.GetUserButtonId(mouseId, MouseButtonMiddle) == ButtonA);
|
||||
REQUIRE(map.GetUserButtonId(keyboardId, KeyD) == ButtonA);
|
||||
REQUIRE(map.GetUserButtonId(keyboardId, KeyB) == ButtonD);
|
||||
}
|
||||
|
||||
TEST_CASE("InputMap/map_float", "")
|
||||
{
|
||||
InputManager manager;
|
||||
const DeviceId keyboardId = manager.CreateDevice<InputDeviceKeyboard>();
|
||||
const DeviceId mouseId = manager.CreateDevice<InputDeviceMouse>();
|
||||
const DeviceId padId = manager.CreateDevice<InputDevicePad>();
|
||||
InputMap map(manager, "testmap");
|
||||
|
||||
REQUIRE(map.MapFloat(ButtonA, keyboardId, KeyA));
|
||||
REQUIRE(map.MapFloat(ButtonA, keyboardId, KeyB));
|
||||
REQUIRE(map.MapFloat(ButtonA, keyboardId, KeyEscape));
|
||||
REQUIRE(map.MapFloat(ButtonA, mouseId, MouseButtonLeft));
|
||||
REQUIRE(map.MapFloat(ButtonA, mouseId, MouseAxisY));
|
||||
REQUIRE(map.MapFloat(ButtonA, padId, PadButtonLeftStickX));
|
||||
REQUIRE(map.IsMapped(ButtonA));
|
||||
|
||||
REQUIRE(map.MapFloat(ButtonB, keyboardId, KeyF2));
|
||||
REQUIRE(map.MapFloat(ButtonB, mouseId, MouseAxisX));
|
||||
REQUIRE(map.IsMapped(ButtonB));
|
||||
|
||||
map.Clear();
|
||||
for (int b = ButtonStart; b < ButtonCount; ++b)
|
||||
{
|
||||
REQUIRE(!map.IsMapped(b));
|
||||
}
|
||||
|
||||
REQUIRE(map.MapFloat(ButtonA, mouseId, MouseAxisX));
|
||||
REQUIRE(map.IsMapped(ButtonA));
|
||||
|
||||
map.Unmap(ButtonA);
|
||||
REQUIRE(!map.IsMapped(ButtonA));
|
||||
|
||||
DeviceButtonSpec mappings[32];
|
||||
REQUIRE(map.GetMappings(ButtonA, mappings, 32) == 0);
|
||||
|
||||
REQUIRE(map.MapFloat(ButtonA, mouseId, MouseAxisX));
|
||||
REQUIRE(map.MapFloat(ButtonA, keyboardId, KeyF5));
|
||||
REQUIRE(map.MapFloat(ButtonD, padId, PadButtonLeftStickY));
|
||||
|
||||
REQUIRE(map.GetMappings(ButtonA, mappings, 32) == 2);
|
||||
REQUIRE(mappings[0].deviceId == mouseId);
|
||||
REQUIRE(mappings[0].buttonId == MouseAxisX);
|
||||
REQUIRE(mappings[1].deviceId == keyboardId);
|
||||
REQUIRE(mappings[1].buttonId == KeyF5);
|
||||
|
||||
char buf[32];
|
||||
REQUIRE(map.GetUserButtonName(ButtonA, buf, 32));
|
||||
|
||||
REQUIRE(map.GetUserButtonId(mouseId, MouseAxisX) == ButtonA);
|
||||
REQUIRE(map.GetUserButtonId(keyboardId, KeyF5) == ButtonA);
|
||||
REQUIRE(map.GetUserButtonId(padId, PadButtonLeftStickY) == ButtonD);
|
||||
}
|
||||
|
||||
TEST_CASE("InputMap/SetDeadZone_SetUserButtonPolicy", "")
|
||||
{
|
||||
InputManager manager;
|
||||
const DeviceId keyboardId = manager.CreateDevice<InputDeviceKeyboard>();
|
||||
const DeviceId mouseId = manager.CreateDevice<InputDeviceMouse>();
|
||||
const DeviceId padId = manager.CreateDevice<InputDevicePad>();
|
||||
InputMap map(manager, "testmap");
|
||||
|
||||
for (int b = ButtonStart; b < ButtonCount; ++b)
|
||||
{
|
||||
REQUIRE(!map.SetDeadZone(b, 0.1f));
|
||||
REQUIRE(!map.SetUserButtonPolicy(b, InputMap::UBP_AVERAGE));
|
||||
}
|
||||
|
||||
REQUIRE(map.MapFloat(ButtonA, mouseId, MouseAxisX));
|
||||
|
||||
REQUIRE(map.SetDeadZone(ButtonA, 0.01f));
|
||||
REQUIRE(map.SetDeadZone(ButtonA, 0.0f));
|
||||
REQUIRE(map.SetDeadZone(ButtonA, 1.01f));
|
||||
REQUIRE(!map.SetDeadZone(ButtonF, 1.01f));
|
||||
|
||||
REQUIRE(map.SetUserButtonPolicy(ButtonA, InputMap::UBP_AVERAGE));
|
||||
REQUIRE(map.SetUserButtonPolicy(ButtonA, InputMap::UBP_MAX));
|
||||
REQUIRE(map.SetUserButtonPolicy(ButtonA, InputMap::UBP_MIN));
|
||||
REQUIRE(map.SetUserButtonPolicy(ButtonA, InputMap::UBP_FIRST_DOWN));
|
||||
|
||||
map.Clear();
|
||||
|
||||
for (int b = ButtonStart; b < ButtonCount; ++b)
|
||||
{
|
||||
REQUIRE(!map.SetDeadZone(b, 0.1f));
|
||||
REQUIRE(!map.SetUserButtonPolicy(b, InputMap::UBP_AVERAGE));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
133
test/test_inputrecording.cpp
Normal file
133
test/test_inputrecording.cpp
Normal file
@@ -0,0 +1,133 @@
|
||||
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <gainput/gainput.h>
|
||||
|
||||
using namespace gainput;
|
||||
|
||||
TEST_CASE("InputRecording/general", "")
|
||||
{
|
||||
InputRecording recording;
|
||||
|
||||
REQUIRE(recording.GetDuration() == 0);
|
||||
REQUIRE(recording.GetSerializedSize() > 0);
|
||||
|
||||
recording.AddChange(100, 0, 0, true);
|
||||
|
||||
REQUIRE(recording.GetDuration() == 100);
|
||||
|
||||
RecordedDeviceButtonChange change;
|
||||
|
||||
REQUIRE(!recording.GetNextChange(50, change));
|
||||
REQUIRE(recording.GetNextChange(100, change));
|
||||
REQUIRE(change.time == 100);
|
||||
REQUIRE(change.deviceId == 0);
|
||||
REQUIRE(change.buttonId == 0);
|
||||
REQUIRE(change.b == true);
|
||||
|
||||
REQUIRE(!recording.GetNextChange(1000, change));
|
||||
|
||||
recording.Reset();
|
||||
recording.AddChange(150, 5, 102, 0.8f);
|
||||
|
||||
REQUIRE(!recording.GetNextChange(50, change));
|
||||
REQUIRE(recording.GetNextChange(101, change));
|
||||
REQUIRE(recording.GetNextChange(160, change));
|
||||
REQUIRE(change.time == 150);
|
||||
REQUIRE(change.deviceId == 5);
|
||||
REQUIRE(change.buttonId == 102);
|
||||
REQUIRE(change.f == 0.8f);
|
||||
REQUIRE(!recording.GetNextChange(1000, change));
|
||||
|
||||
recording.Reset();
|
||||
recording.Clear();
|
||||
|
||||
REQUIRE(recording.GetDuration() == 0);
|
||||
REQUIRE(!recording.GetNextChange(10000, change));
|
||||
}
|
||||
|
||||
TEST_CASE("InputRecording/serialization", "")
|
||||
{
|
||||
InputManager manager;
|
||||
const DeviceId deviceId = manager.CreateDevice<InputDeviceMouse>();
|
||||
InputRecording recording;
|
||||
|
||||
recording.AddChange(500, deviceId, MouseButtonLeft, true);
|
||||
recording.AddChange(600, deviceId, MouseButtonMiddle, false);
|
||||
recording.AddChange(700, deviceId, MouseAxisX, 0.2f);
|
||||
|
||||
REQUIRE(recording.GetSerializedSize() > 0);
|
||||
|
||||
void* serializedData = malloc(recording.GetSerializedSize());
|
||||
recording.GetSerialized(manager, serializedData);
|
||||
|
||||
InputRecording recording2(manager, serializedData, recording.GetSerializedSize());
|
||||
|
||||
free(serializedData);
|
||||
|
||||
REQUIRE(recording.GetSerializedSize() == recording2.GetSerializedSize());
|
||||
REQUIRE(recording.GetDuration() == recording2.GetDuration());
|
||||
|
||||
RecordedDeviceButtonChange change, change2;
|
||||
|
||||
for (unsigned t = 500; t <= 700; t += 100)
|
||||
{
|
||||
REQUIRE(recording.GetNextChange(t, change));
|
||||
REQUIRE(recording2.GetNextChange(t, change2));
|
||||
REQUIRE(change.time == change2.time);
|
||||
REQUIRE(change.deviceId == change2.deviceId);
|
||||
REQUIRE(change.buttonId == change2.buttonId);
|
||||
if (t == 700)
|
||||
{
|
||||
REQUIRE(change.f == change2.f);
|
||||
}
|
||||
else
|
||||
{
|
||||
REQUIRE(change.b == change2.b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("InputPlayer", "")
|
||||
{
|
||||
InputManager manager;
|
||||
InputPlayer player(manager);
|
||||
|
||||
REQUIRE(!player.GetRecording());
|
||||
|
||||
InputRecording recording;;
|
||||
player.SetRecording(&recording);
|
||||
|
||||
REQUIRE(player.GetRecording() == &recording);
|
||||
|
||||
REQUIRE(!player.IsPlaying());
|
||||
player.Start();
|
||||
REQUIRE(player.IsPlaying());
|
||||
player.Stop();
|
||||
REQUIRE(!player.IsPlaying());
|
||||
}
|
||||
|
||||
TEST_CASE("InputRecorder", "")
|
||||
{
|
||||
InputManager manager;
|
||||
|
||||
InputRecorder recorder(manager);
|
||||
|
||||
REQUIRE(!recorder.IsRecording());
|
||||
recorder.Start();
|
||||
REQUIRE(recorder.IsRecording());
|
||||
recorder.Stop();
|
||||
REQUIRE(!recorder.IsRecording());
|
||||
|
||||
REQUIRE(recorder.GetRecording());
|
||||
|
||||
REQUIRE(recorder.IsDeviceToRecord(0));
|
||||
REQUIRE(recorder.IsDeviceToRecord(1));
|
||||
REQUIRE(recorder.IsDeviceToRecord(2358349));
|
||||
|
||||
recorder.AddDeviceToRecord(0);
|
||||
REQUIRE(recorder.IsDeviceToRecord(0));
|
||||
REQUIRE(!recorder.IsDeviceToRecord(1));
|
||||
REQUIRE(!recorder.IsDeviceToRecord(2358349));
|
||||
}
|
||||
|
||||
48
test/test_inputstate.cpp
Normal file
48
test/test_inputstate.cpp
Normal file
@@ -0,0 +1,48 @@
|
||||
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <gainput/gainput.h>
|
||||
|
||||
using namespace gainput;
|
||||
|
||||
const unsigned ButtonCount = 15;
|
||||
|
||||
TEST_CASE("InputState", "")
|
||||
{
|
||||
InputState state(GetDefaultAllocator(), ButtonCount);
|
||||
InputState state2(GetDefaultAllocator(), ButtonCount);
|
||||
|
||||
for (unsigned i = 0; i < ButtonCount; ++i)
|
||||
{
|
||||
REQUIRE(!state.GetBool(i));
|
||||
REQUIRE(state.GetFloat(i) == 0.0f);
|
||||
}
|
||||
|
||||
for (unsigned i = 0; i < ButtonCount; ++i)
|
||||
{
|
||||
const bool s = i & 1;
|
||||
state.Set(i, s);
|
||||
REQUIRE(state.GetBool(i) == s);
|
||||
}
|
||||
|
||||
state2 = state;
|
||||
for (unsigned i = 0; i < ButtonCount; ++i)
|
||||
{
|
||||
REQUIRE(state2.GetBool(i) == state.GetBool(i));
|
||||
}
|
||||
|
||||
float s = 0.0f;
|
||||
for (unsigned i = 0; i < ButtonCount; ++i)
|
||||
{
|
||||
state.Set(i, s);
|
||||
REQUIRE(state.GetFloat(i) == s);
|
||||
s += float(i)*0.0354f;
|
||||
}
|
||||
|
||||
state2 = state;
|
||||
for (unsigned i = 0; i < ButtonCount; ++i)
|
||||
{
|
||||
REQUIRE(state2.GetFloat(i) == state.GetFloat(i));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user