aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-11-27 14:59:03 +0100
committerWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-11-27 14:59:03 +0100
commit9d60b7b70abd832dc229c59114e465d457fcd0a3 (patch)
treee8f072ccb8e3a24a42295e53afac1892eda039ab /src/test
parent6e9879896e620e6113c11e48f23a5f71b4fc87f0 (diff)
make format
Diffstat (limited to 'src/test')
-rw-r--r--src/test/EventTest.cpp74
-rw-r--r--src/test/InputTest.cpp26
2 files changed, 49 insertions, 51 deletions
diff --git a/src/test/EventTest.cpp b/src/test/EventTest.cpp
index 4af0830..c75bcc1 100644
--- a/src/test/EventTest.cpp
+++ b/src/test/EventTest.cpp
@@ -154,44 +154,44 @@ TEST_F(EventManagerTest, EventManagerTest_callback_propagation) {
}
TEST_F(EventManagerTest, EventManagerTest_queue_dispatch) {
- EventManager & event_manager = EventManager::get_instance();
- bool triggered1 = false;
- bool triggered2 = false;
- int test_channel = 1;
-
- // Adjusted to use KeyPressEvent with repeat as the first variable
- EventHandler<KeyPressEvent> key_handler1 = [&](const KeyPressEvent & e) {
- triggered1 = true;
- EXPECT_EQ(e.repeat, false); // Expecting repeat to be false
- EXPECT_EQ(e.key, Keycode::A); // Adjust expected key code
- return false; // Allows propagation
- };
-
- EventHandler<KeyPressEvent> key_handler2 = [&](const KeyPressEvent & e) {
- triggered2 = true;
- EXPECT_EQ(e.repeat, false); // Expecting repeat to be false
- EXPECT_EQ(e.key, Keycode::A); // Adjust expected key code
- return false; // Allows propagation
- };
-
- // Subscribe handlers to KeyPressEvent
- event_manager.subscribe<KeyPressEvent>(key_handler1);
- event_manager.subscribe<KeyPressEvent>(key_handler2, test_channel);
-
- // Queue a KeyPressEvent instead of KeyDownEvent
- event_manager.queue_event<KeyPressEvent>(
- KeyPressEvent{.repeat = false, .key = Keycode::A}); // Adjust event with repeat flag first
-
- event_manager.queue_event<KeyPressEvent>(
- KeyPressEvent{.repeat = false, .key = Keycode::A}, // Adjust event for second subscription
- test_channel);
-
- event_manager.dispatch_events();
-
- EXPECT_TRUE(triggered1);
- EXPECT_TRUE(triggered2);
-}
+ EventManager & event_manager = EventManager::get_instance();
+ bool triggered1 = false;
+ bool triggered2 = false;
+ int test_channel = 1;
+ // Adjusted to use KeyPressEvent with repeat as the first variable
+ EventHandler<KeyPressEvent> key_handler1 = [&](const KeyPressEvent & e) {
+ triggered1 = true;
+ EXPECT_EQ(e.repeat, false); // Expecting repeat to be false
+ EXPECT_EQ(e.key, Keycode::A); // Adjust expected key code
+ return false; // Allows propagation
+ };
+
+ EventHandler<KeyPressEvent> key_handler2 = [&](const KeyPressEvent & e) {
+ triggered2 = true;
+ EXPECT_EQ(e.repeat, false); // Expecting repeat to be false
+ EXPECT_EQ(e.key, Keycode::A); // Adjust expected key code
+ return false; // Allows propagation
+ };
+
+ // Subscribe handlers to KeyPressEvent
+ event_manager.subscribe<KeyPressEvent>(key_handler1);
+ event_manager.subscribe<KeyPressEvent>(key_handler2, test_channel);
+
+ // Queue a KeyPressEvent instead of KeyDownEvent
+ event_manager.queue_event<KeyPressEvent>(KeyPressEvent{
+ .repeat = false, .key = Keycode::A}); // Adjust event with repeat flag first
+
+ event_manager.queue_event<KeyPressEvent>(
+ KeyPressEvent{.repeat = false,
+ .key = Keycode::A}, // Adjust event for second subscription
+ test_channel);
+
+ event_manager.dispatch_events();
+
+ EXPECT_TRUE(triggered1);
+ EXPECT_TRUE(triggered2);
+}
TEST_F(EventManagerTest, EventManagerTest_unsubscribe) {
EventManager & event_manager = EventManager::get_instance();
diff --git a/src/test/InputTest.cpp b/src/test/InputTest.cpp
index 0e3e097..d6ebb6f 100644
--- a/src/test/InputTest.cpp
+++ b/src/test/InputTest.cpp
@@ -20,14 +20,12 @@ using namespace crepe;
class InputTest : public ::testing::Test {
public:
ComponentManager mgr{};
- InputSystem input_system{mgr}; // Initializes the InputSystem with the ComponentManager
+ InputSystem input_system{mgr}; // Initializes the InputSystem with the ComponentManager
- EventManager& event_manager = EventManager::get_instance();
+ EventManager & event_manager = EventManager::get_instance();
protected:
- void SetUp() override {
- event_manager.clear();
- }
+ void SetUp() override { event_manager.clear(); }
void simulate_mouse_click(int mouse_x, int mouse_y, Uint8 mouse_button) {
SDL_Event event;
@@ -52,7 +50,7 @@ protected:
TEST_F(InputTest, MouseDown) {
bool mouse_triggered = false;
- EventHandler<MousePressEvent> on_mouse_down = [&](const MousePressEvent& event) {
+ EventHandler<MousePressEvent> on_mouse_down = [&](const MousePressEvent & event) {
mouse_triggered = true;
EXPECT_EQ(event.mouse_x, 10);
EXPECT_EQ(event.mouse_y, 10);
@@ -76,7 +74,7 @@ TEST_F(InputTest, MouseDown) {
TEST_F(InputTest, MouseUp) {
bool function_triggered = false;
- EventHandler<MouseReleaseEvent> on_mouse_release = [&](const MouseReleaseEvent& e) {
+ EventHandler<MouseReleaseEvent> on_mouse_release = [&](const MouseReleaseEvent & e) {
function_triggered = true;
EXPECT_EQ(e.mouse_x, 10);
EXPECT_EQ(e.mouse_y, 10);
@@ -100,7 +98,7 @@ TEST_F(InputTest, MouseUp) {
TEST_F(InputTest, MouseMove) {
bool function_triggered = false;
- EventHandler<MouseMoveEvent> on_mouse_move = [&](const MouseMoveEvent& e) {
+ EventHandler<MouseMoveEvent> on_mouse_move = [&](const MouseMoveEvent & e) {
function_triggered = true;
EXPECT_EQ(e.mouse_x, 10);
EXPECT_EQ(e.mouse_y, 10);
@@ -128,7 +126,7 @@ TEST_F(InputTest, KeyDown) {
bool function_triggered = false;
// Define event handler for KeyPressEvent
- EventHandler<KeyPressEvent> on_key_press = [&](const KeyPressEvent& event) {
+ EventHandler<KeyPressEvent> on_key_press = [&](const KeyPressEvent & event) {
function_triggered = true;
EXPECT_EQ(event.key, Keycode::B); // Validate the key is 'B'
EXPECT_EQ(event.repeat, true); // Validate repeat flag
@@ -153,7 +151,7 @@ TEST_F(InputTest, KeyDown) {
TEST_F(InputTest, KeyUp) {
bool function_triggered = false;
- EventHandler<KeyReleaseEvent> on_key_release = [&](const KeyReleaseEvent& event) {
+ EventHandler<KeyReleaseEvent> on_key_release = [&](const KeyReleaseEvent & event) {
function_triggered = true;
EXPECT_EQ(event.key, Keycode::B);
return false;
@@ -173,7 +171,7 @@ TEST_F(InputTest, KeyUp) {
TEST_F(InputTest, MouseClick) {
bool on_click_triggered = false;
- EventHandler<MouseClickEvent> on_mouse_click = [&](const MouseClickEvent& event) {
+ EventHandler<MouseClickEvent> on_mouse_click = [&](const MouseClickEvent & event) {
on_click_triggered = true;
EXPECT_EQ(event.button, MouseButton::LEFT_MOUSE);
EXPECT_EQ(event.mouse_x, 10);
@@ -190,8 +188,8 @@ TEST_F(InputTest, MouseClick) {
TEST_F(InputTest, testButtonClick) {
GameObject obj = mgr.new_object("body", "person", vec2{0, 0}, 0, 1);
-
- auto& button = obj.add_component<Button>(100,100);
+
+ auto & button = obj.add_component<Button>(100, 100);
bool button_clicked = false;
bool hover = false;
button.active = true;
@@ -212,7 +210,7 @@ TEST_F(InputTest, testButtonClick) {
TEST_F(InputTest, testButtonHover) {
GameObject obj = mgr.new_object("body", "person", vec2{0, 0}, 0, 1);
- auto& button = obj.add_component<Button>(100,100);
+ auto & button = obj.add_component<Button>(100, 100);
bool button_clicked = false;
button.active = true;
button.width = 100;