194 lines
5.2 KiB
C++
194 lines
5.2 KiB
C++
#include <gtest/gtest.h>
|
|
#include <XCEngine/Input/InputManager.h>
|
|
#include <XCEngine/Input/InputModule.h>
|
|
#include <XCEngine/Input/Platform/WindowsInputModule.h>
|
|
#include <XCEngine/Math/Vector2.h>
|
|
#include <XCEngine/Containers/String.h>
|
|
|
|
using namespace XCEngine::Input;
|
|
using namespace XCEngine::Math;
|
|
using namespace XCEngine::Containers;
|
|
using namespace XCEngine::Input::Platform;
|
|
|
|
namespace {
|
|
|
|
TEST(WindowsInputModule, Construction) {
|
|
WindowsInputModule module;
|
|
}
|
|
|
|
TEST(WindowsInputModule, InitializeShutdown) {
|
|
WindowsInputModule module;
|
|
module.Initialize(nullptr);
|
|
module.Shutdown();
|
|
}
|
|
|
|
TEST(WindowsInputModule, HandleKeyDown) {
|
|
InputManager::Get().Initialize(nullptr);
|
|
|
|
WindowsInputModule module;
|
|
module.Initialize(nullptr);
|
|
|
|
EXPECT_FALSE(InputManager::Get().IsKeyDown(KeyCode::A));
|
|
|
|
module.HandleMessage(0, 0x0100, 'A', 0);
|
|
|
|
EXPECT_TRUE(InputManager::Get().IsKeyDown(KeyCode::A));
|
|
|
|
module.Shutdown();
|
|
InputManager::Get().Shutdown();
|
|
}
|
|
|
|
TEST(WindowsInputModule, HandleKeyUp) {
|
|
InputManager::Get().Initialize(nullptr);
|
|
|
|
WindowsInputModule module;
|
|
module.Initialize(nullptr);
|
|
|
|
module.HandleMessage(0, 0x0100, 'A', 0);
|
|
EXPECT_TRUE(InputManager::Get().IsKeyDown(KeyCode::A));
|
|
|
|
module.HandleMessage(0, 0x0101, 'A', 0);
|
|
EXPECT_FALSE(InputManager::Get().IsKeyDown(KeyCode::A));
|
|
|
|
module.Shutdown();
|
|
InputManager::Get().Shutdown();
|
|
}
|
|
|
|
TEST(WindowsInputModule, HandleMouseMove) {
|
|
InputManager::Get().Initialize(nullptr);
|
|
|
|
WindowsInputModule module;
|
|
module.Initialize(nullptr);
|
|
|
|
module.HandleMessage(0, 0x0200, 0, 0x00320078);
|
|
|
|
Vector2 pos = InputManager::Get().GetMousePosition();
|
|
EXPECT_EQ(pos.x, 120.0f);
|
|
EXPECT_EQ(pos.y, 50.0f);
|
|
|
|
module.Shutdown();
|
|
InputManager::Get().Shutdown();
|
|
}
|
|
|
|
TEST(WindowsInputModule, HandleLeftMouseButtonDown) {
|
|
InputManager::Get().Initialize(nullptr);
|
|
|
|
WindowsInputModule module;
|
|
module.Initialize(nullptr);
|
|
|
|
module.HandleMessage(0, 0x0201, 0, 0x00320078);
|
|
|
|
EXPECT_TRUE(InputManager::Get().IsMouseButtonDown(MouseButton::Left));
|
|
|
|
module.Shutdown();
|
|
InputManager::Get().Shutdown();
|
|
}
|
|
|
|
TEST(WindowsInputModule, HandleLeftMouseButtonUp) {
|
|
InputManager::Get().Initialize(nullptr);
|
|
|
|
WindowsInputModule module;
|
|
module.Initialize(nullptr);
|
|
|
|
module.HandleMessage(0, 0x0201, 0, 0x00320078);
|
|
EXPECT_TRUE(InputManager::Get().IsMouseButtonDown(MouseButton::Left));
|
|
|
|
module.HandleMessage(0, 0x0202, 0, 0x00320078);
|
|
EXPECT_FALSE(InputManager::Get().IsMouseButtonDown(MouseButton::Left));
|
|
|
|
module.Shutdown();
|
|
InputManager::Get().Shutdown();
|
|
}
|
|
|
|
TEST(WindowsInputModule, HandleRightMouseButton) {
|
|
InputManager::Get().Initialize(nullptr);
|
|
|
|
WindowsInputModule module;
|
|
module.Initialize(nullptr);
|
|
|
|
module.HandleMessage(0, 0x0204, 0, 0x00320078);
|
|
EXPECT_TRUE(InputManager::Get().IsMouseButtonDown(MouseButton::Right));
|
|
|
|
module.HandleMessage(0, 0x0205, 0, 0x00320078);
|
|
EXPECT_FALSE(InputManager::Get().IsMouseButtonDown(MouseButton::Right));
|
|
|
|
module.Shutdown();
|
|
InputManager::Get().Shutdown();
|
|
}
|
|
|
|
TEST(WindowsInputModule, HandleMiddleMouseButton) {
|
|
InputManager::Get().Initialize(nullptr);
|
|
|
|
WindowsInputModule module;
|
|
module.Initialize(nullptr);
|
|
|
|
module.HandleMessage(0, 0x0207, 0, 0x00320078);
|
|
EXPECT_TRUE(InputManager::Get().IsMouseButtonDown(MouseButton::Middle));
|
|
|
|
module.HandleMessage(0, 0x0208, 0, 0x00320078);
|
|
EXPECT_FALSE(InputManager::Get().IsMouseButtonDown(MouseButton::Middle));
|
|
|
|
module.Shutdown();
|
|
InputManager::Get().Shutdown();
|
|
}
|
|
|
|
TEST(WindowsInputModule, HandleMouseWheel) {
|
|
InputManager::Get().Initialize(nullptr);
|
|
|
|
WindowsInputModule module;
|
|
module.Initialize(nullptr);
|
|
|
|
module.HandleMessage(0, 0x020A, 0x00030000, 0x00780078);
|
|
|
|
float scrollDelta = InputManager::Get().GetMouseScrollDelta();
|
|
EXPECT_EQ(scrollDelta, 0.025f);
|
|
|
|
module.Shutdown();
|
|
InputManager::Get().Shutdown();
|
|
}
|
|
|
|
TEST(WindowsInputModule, HandleTextInput) {
|
|
InputManager::Get().Initialize(nullptr);
|
|
|
|
WindowsInputModule module;
|
|
module.Initialize(nullptr);
|
|
|
|
bool eventFired = false;
|
|
char capturedChar = 0;
|
|
|
|
uint64_t id = InputManager::Get().OnTextInput().Subscribe([&eventFired, &capturedChar](const TextInputEvent& e) {
|
|
eventFired = true;
|
|
capturedChar = e.character;
|
|
});
|
|
|
|
module.HandleMessage(0, 0x0102, 'X', 0);
|
|
|
|
EXPECT_TRUE(eventFired);
|
|
EXPECT_EQ(capturedChar, 'X');
|
|
|
|
InputManager::Get().OnTextInput().Unsubscribe(id);
|
|
module.Shutdown();
|
|
InputManager::Get().Shutdown();
|
|
}
|
|
|
|
TEST(WindowsInputModule, MultipleModules) {
|
|
InputManager::Get().Initialize(nullptr);
|
|
|
|
WindowsInputModule module1;
|
|
WindowsInputModule module2;
|
|
|
|
module1.Initialize(nullptr);
|
|
module2.Initialize(nullptr);
|
|
|
|
module1.HandleMessage(0, 0x0100, 'A', 0);
|
|
EXPECT_TRUE(InputManager::Get().IsKeyDown(KeyCode::A));
|
|
|
|
module2.HandleMessage(0, 0x0100, 'B', 0);
|
|
EXPECT_TRUE(InputManager::Get().IsKeyDown(KeyCode::B));
|
|
|
|
module1.Shutdown();
|
|
module2.Shutdown();
|
|
InputManager::Get().Shutdown();
|
|
}
|
|
|
|
} // namespace
|