aboutsummaryrefslogtreecommitdiff
path: root/src/test/InputTest.cpp
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-12-17 14:17:57 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-12-17 14:17:57 +0100
commit6d2174db28992b49ea266c653f6283c61ef071f0 (patch)
tree5d092c2792b89c5f806088d1a1d88419fe5b5c13 /src/test/InputTest.cpp
parent9957da232e7c96f7f88a7ab0edfa4aaf560d1c00 (diff)
parent3c99c73f3c1c31ba97f7e8c74f434c880f8a9036 (diff)
Merge branch 'wouter/inputSystem' of github.com:lonkaars/crepe
Diffstat (limited to 'src/test/InputTest.cpp')
-rw-r--r--src/test/InputTest.cpp34
1 files changed, 14 insertions, 20 deletions
diff --git a/src/test/InputTest.cpp b/src/test/InputTest.cpp
index 8b40cea..d893276 100644
--- a/src/test/InputTest.cpp
+++ b/src/test/InputTest.cpp
@@ -15,6 +15,7 @@
#include <crepe/api/Metadata.h>
#include <crepe/api/Transform.h>
#include <crepe/api/Vector2.h>
+#include <crepe/facade/SDLContext.h>
#include <gmock/gmock.h>
using namespace std;
@@ -43,7 +44,7 @@ protected:
//mediator.component_manager = mgr;
//event_manager.clear();
}
-
+ void TearDown() override {}
void simulate_mouse_click(int mouse_x, int mouse_y, Uint8 mouse_button) {
SDL_Event event;
@@ -70,8 +71,8 @@ TEST_F(InputTest, MouseDown) {
EventHandler<MousePressEvent> on_mouse_down = [&](const MousePressEvent & event) {
mouse_triggered = true;
//middle of the screen = 0,0
- EXPECT_EQ(event.mouse_x, 0);
- EXPECT_EQ(event.mouse_y, 0);
+ EXPECT_EQ(event.mouse_pos.x, 0);
+ EXPECT_EQ(event.mouse_pos.y, 0);
EXPECT_EQ(event.button, MouseButton::LEFT_MOUSE);
return false;
};
@@ -95,8 +96,8 @@ TEST_F(InputTest, MouseUp) {
bool function_triggered = false;
EventHandler<MouseReleaseEvent> on_mouse_release = [&](const MouseReleaseEvent & e) {
function_triggered = true;
- EXPECT_EQ(e.mouse_x, 0);
- EXPECT_EQ(e.mouse_y, 0);
+ EXPECT_EQ(e.mouse_pos.x, 0);
+ EXPECT_EQ(e.mouse_pos.y, 0);
EXPECT_EQ(e.button, MouseButton::LEFT_MOUSE);
return false;
};
@@ -119,10 +120,10 @@ TEST_F(InputTest, MouseMove) {
bool function_triggered = false;
EventHandler<MouseMoveEvent> on_mouse_move = [&](const MouseMoveEvent & e) {
function_triggered = true;
- EXPECT_EQ(e.mouse_x, 0);
- EXPECT_EQ(e.mouse_y, 0);
- EXPECT_EQ(e.delta_x, 10);
- EXPECT_EQ(e.delta_y, 10);
+ EXPECT_EQ(e.mouse_pos.x, 0);
+ EXPECT_EQ(e.mouse_pos.y, 0);
+ EXPECT_EQ(e.mouse_delta.x, 10);
+ EXPECT_EQ(e.mouse_delta.y, 10);
return false;
};
event_manager.subscribe<MouseMoveEvent>(on_mouse_move);
@@ -193,8 +194,8 @@ TEST_F(InputTest, MouseClick) {
EventHandler<MouseClickEvent> on_mouse_click = [&](const MouseClickEvent & event) {
on_click_triggered = true;
EXPECT_EQ(event.button, MouseButton::LEFT_MOUSE);
- EXPECT_EQ(event.mouse_x, 0);
- EXPECT_EQ(event.mouse_y, 0);
+ EXPECT_EQ(event.mouse_pos.x, 0);
+ EXPECT_EQ(event.mouse_pos.y, 0);
return false;
};
event_manager.subscribe<MouseClickEvent>(on_mouse_click);
@@ -209,14 +210,10 @@ TEST_F(InputTest, testButtonClick) {
GameObject button_obj = mgr.new_object("body", "person", vec2{0, 0}, 0, 1);
bool button_clicked = false;
std::function<void()> on_click = [&]() { button_clicked = true; };
- auto & button
- = button_obj.add_component<Button>(vec2{100, 100}, vec2{0, 0}, on_click, false);
+ auto & button = button_obj.add_component<Button>(vec2{100, 100}, vec2{0, 0}, on_click);
bool hover = false;
button.active = true;
-
- button.is_pressed = false;
- button.is_toggle = false;
this->simulate_mouse_click(999, 999, SDL_BUTTON_LEFT);
input_system.update();
event_manager.dispatch_events();
@@ -232,11 +229,8 @@ TEST_F(InputTest, testButtonHover) {
GameObject button_obj = mgr.new_object("body", "person", vec2{0, 0}, 0, 1);
bool button_clicked = false;
std::function<void()> on_click = [&]() { button_clicked = true; };
- auto & button
- = button_obj.add_component<Button>(vec2{100, 100}, vec2{0, 0}, on_click, false);
+ auto & button = button_obj.add_component<Button>(vec2{100, 100}, vec2{0, 0}, on_click);
button.active = true;
- button.is_pressed = false;
- button.is_toggle = false;
// Mouse not on button
SDL_Event event;