From 2a2a3391ff0b449602825c3182af33c2ff52abc0 Mon Sep 17 00:00:00 2001
From: Loek Le Blansch <loek@pipeframe.xyz>
Date: Thu, 28 Nov 2024 11:19:33 +0100
Subject: add test for Script::set_next_scene

---
 src/test/ScriptTest.h | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
 create mode 100644 src/test/ScriptTest.h

(limited to 'src/test/ScriptTest.h')

diff --git a/src/test/ScriptTest.h b/src/test/ScriptTest.h
new file mode 100644
index 0000000..9a71ba7
--- /dev/null
+++ b/src/test/ScriptTest.h
@@ -0,0 +1,29 @@
+#pragma once
+
+#include <gtest/gtest.h>
+#include <gmock/gmock.h>
+
+#include <crepe/manager/ComponentManager.h>
+#include <crepe/system/ScriptSystem.h>
+#include <crepe/api/BehaviorScript.h>
+#include <crepe/api/Script.h>
+
+class ScriptTest : public testing::Test {
+protected:
+	crepe::Mediator mediator;
+public:
+	crepe::ComponentManager component_manager{mediator};
+	crepe::ScriptSystem system{mediator};
+
+	class MyScript : public crepe::Script {
+		// NOTE: explicitly stating `public:` is not required on actual scripts
+	public:
+		MOCK_METHOD(void, init, (), (override));
+		MOCK_METHOD(void, update, (), (override));
+	};
+
+	crepe::OptionalRef<crepe::BehaviorScript> behaviorscript;
+	crepe::OptionalRef<MyScript> script;
+
+	virtual void SetUp();
+};
-- 
cgit v1.2.3


From 2d5721820063031b65d64b1b2b1b4797b71935af Mon Sep 17 00:00:00 2001
From: Loek Le Blansch <loek@pipeframe.xyz>
Date: Sat, 30 Nov 2024 16:41:22 +0100
Subject: `make format`

---
 src/crepe/api/LoopManager.cpp          | 5 +----
 src/crepe/api/LoopManager.h            | 2 +-
 src/crepe/api/Scene.h                  | 3 ++-
 src/crepe/api/Script.cpp               | 1 -
 src/crepe/api/Script.h                 | 4 ++--
 src/crepe/manager/ComponentManager.cpp | 2 +-
 src/crepe/manager/Manager.cpp          | 3 +--
 src/crepe/manager/Manager.h            | 3 +--
 src/crepe/manager/Mediator.h           | 4 ++--
 src/crepe/manager/SaveManager.cpp      | 4 ++--
 src/crepe/system/PhysicsSystem.cpp     | 2 +-
 src/crepe/system/RenderSystem.cpp      | 2 +-
 src/crepe/system/ScriptSystem.cpp      | 2 +-
 src/test/ECSTest.cpp                   | 3 ++-
 src/test/EventTest.cpp                 | 6 ++----
 src/test/ParticleTest.cpp              | 3 ++-
 src/test/PhysicsTest.cpp               | 3 ++-
 src/test/RenderSystemTest.cpp          | 3 ++-
 src/test/SceneManagerTest.cpp          | 7 ++++---
 src/test/ScriptEventTest.cpp           | 7 +++----
 src/test/ScriptSceneTest.cpp           | 3 +--
 src/test/ScriptTest.cpp                | 3 +--
 src/test/ScriptTest.h                  | 8 +++++---
 23 files changed, 40 insertions(+), 43 deletions(-)

(limited to 'src/test/ScriptTest.h')

diff --git a/src/crepe/api/LoopManager.cpp b/src/crepe/api/LoopManager.cpp
index b277185..731cfb7 100644
--- a/src/crepe/api/LoopManager.cpp
+++ b/src/crepe/api/LoopManager.cpp
@@ -22,9 +22,7 @@ LoopManager::LoopManager() {
 	this->load_system<ScriptSystem>();
 }
 
-void LoopManager::process_input() {
-	this->sdl_context.handle_events(this->game_running);
-}
+void LoopManager::process_input() { this->sdl_context.handle_events(this->game_running); }
 
 void LoopManager::start() {
 	this->setup();
@@ -69,4 +67,3 @@ void LoopManager::render() {
 }
 
 void LoopManager::update() {}
-
diff --git a/src/crepe/api/LoopManager.h b/src/crepe/api/LoopManager.h
index 6ea5ccc..d8910a0 100644
--- a/src/crepe/api/LoopManager.h
+++ b/src/crepe/api/LoopManager.h
@@ -2,10 +2,10 @@
 
 #include <memory>
 
+#include "../facade/SDLContext.h"
 #include "../manager/ComponentManager.h"
 #include "../manager/SceneManager.h"
 #include "../system/System.h"
-#include "../facade/SDLContext.h"
 
 #include "LoopTimer.h"
 
diff --git a/src/crepe/api/Scene.h b/src/crepe/api/Scene.h
index 66dad17..9f1e8ce 100644
--- a/src/crepe/api/Scene.h
+++ b/src/crepe/api/Scene.h
@@ -2,8 +2,8 @@
 
 #include <string>
 
-#include "../util/OptionalRef.h"
 #include "../manager/Mediator.h"
+#include "../util/OptionalRef.h"
 
 namespace crepe {
 
@@ -37,6 +37,7 @@ public:
 
 	// TODO: Late references should ALWAYS be private! This is currently kept as-is so unit tests
 	// keep passing, but this reference should not be directly accessible by the user!!!
+
 protected:
 	/**
 	 * \name Late references
diff --git a/src/crepe/api/Script.cpp b/src/crepe/api/Script.cpp
index a27838e..4091fd4 100644
--- a/src/crepe/api/Script.cpp
+++ b/src/crepe/api/Script.cpp
@@ -25,4 +25,3 @@ void Script::set_next_scene(const string & name) {
 	SceneManager & mgr = mediator.scene_manager;
 	mgr.set_next_scene(name);
 }
-
diff --git a/src/crepe/api/Script.h b/src/crepe/api/Script.h
index e1f86b2..1b339b0 100644
--- a/src/crepe/api/Script.h
+++ b/src/crepe/api/Script.h
@@ -2,10 +2,10 @@
 
 #include <vector>
 
+#include "../manager/EventManager.h"
+#include "../manager/Mediator.h"
 #include "../types.h"
 #include "../util/OptionalRef.h"
-#include "../manager/Mediator.h"
-#include "../manager/EventManager.h"
 
 namespace crepe {
 
diff --git a/src/crepe/manager/ComponentManager.cpp b/src/crepe/manager/ComponentManager.cpp
index 5a96158..80cf8b4 100644
--- a/src/crepe/manager/ComponentManager.cpp
+++ b/src/crepe/manager/ComponentManager.cpp
@@ -1,6 +1,6 @@
 #include "../api/GameObject.h"
-#include "../util/Log.h"
 #include "../types.h"
+#include "../util/Log.h"
 
 #include "ComponentManager.h"
 
diff --git a/src/crepe/manager/Manager.cpp b/src/crepe/manager/Manager.cpp
index fe7c936..1182785 100644
--- a/src/crepe/manager/Manager.cpp
+++ b/src/crepe/manager/Manager.cpp
@@ -2,5 +2,4 @@
 
 using namespace crepe;
 
-Manager::Manager(Mediator & mediator) : mediator(mediator) { }
-
+Manager::Manager(Mediator & mediator) : mediator(mediator) {}
diff --git a/src/crepe/manager/Manager.h b/src/crepe/manager/Manager.h
index 9adfd0b..4f21ef4 100644
--- a/src/crepe/manager/Manager.h
+++ b/src/crepe/manager/Manager.h
@@ -13,5 +13,4 @@ protected:
 	Mediator & mediator;
 };
 
-}
-
+} // namespace crepe
diff --git a/src/crepe/manager/Mediator.h b/src/crepe/manager/Mediator.h
index a91509e..71bd1c9 100644
--- a/src/crepe/manager/Mediator.h
+++ b/src/crepe/manager/Mediator.h
@@ -3,8 +3,8 @@
 #include "../util/OptionalRef.h"
 
 // TODO: remove these singletons:
-#include "SaveManager.h"
 #include "EventManager.h"
+#include "SaveManager.h"
 
 namespace crepe {
 
@@ -30,4 +30,4 @@ struct Mediator {
 	OptionalRef<EventManager> event_manager = EventManager::get_instance();
 };
 
-}
+} // namespace crepe
diff --git a/src/crepe/manager/SaveManager.cpp b/src/crepe/manager/SaveManager.cpp
index 121d017..d4ed1c1 100644
--- a/src/crepe/manager/SaveManager.cpp
+++ b/src/crepe/manager/SaveManager.cpp
@@ -1,7 +1,7 @@
+#include "../ValueBroker.h"
+#include "../api/Config.h"
 #include "../facade/DB.h"
 #include "../util/Log.h"
-#include "../api/Config.h"
-#include "../ValueBroker.h"
 
 #include "SaveManager.h"
 
diff --git a/src/crepe/system/PhysicsSystem.cpp b/src/crepe/system/PhysicsSystem.cpp
index eba9dfa..bebcf3d 100644
--- a/src/crepe/system/PhysicsSystem.cpp
+++ b/src/crepe/system/PhysicsSystem.cpp
@@ -1,10 +1,10 @@
 #include <cmath>
 
-#include "../manager/ComponentManager.h"
 #include "../api/Config.h"
 #include "../api/Rigidbody.h"
 #include "../api/Transform.h"
 #include "../api/Vector2.h"
+#include "../manager/ComponentManager.h"
 
 #include "PhysicsSystem.h"
 
diff --git a/src/crepe/system/RenderSystem.cpp b/src/crepe/system/RenderSystem.cpp
index 4e97b3e..0ad685c 100644
--- a/src/crepe/system/RenderSystem.cpp
+++ b/src/crepe/system/RenderSystem.cpp
@@ -5,12 +5,12 @@
 #include <stdexcept>
 #include <vector>
 
-#include "../manager/ComponentManager.h"
 #include "../api/Camera.h"
 #include "../api/ParticleEmitter.h"
 #include "../api/Sprite.h"
 #include "../api/Transform.h"
 #include "../facade/SDLContext.h"
+#include "../manager/ComponentManager.h"
 
 #include "RenderSystem.h"
 
diff --git a/src/crepe/system/ScriptSystem.cpp b/src/crepe/system/ScriptSystem.cpp
index 2e16eb0..d6b2ca1 100644
--- a/src/crepe/system/ScriptSystem.cpp
+++ b/src/crepe/system/ScriptSystem.cpp
@@ -1,6 +1,6 @@
-#include "../manager/ComponentManager.h"
 #include "../api/BehaviorScript.h"
 #include "../api/Script.h"
+#include "../manager/ComponentManager.h"
 
 #include "ScriptSystem.h"
 
diff --git a/src/test/ECSTest.cpp b/src/test/ECSTest.cpp
index 22c4fe7..3e6c61c 100644
--- a/src/test/ECSTest.cpp
+++ b/src/test/ECSTest.cpp
@@ -2,17 +2,18 @@
 
 #define protected public
 
-#include <crepe/manager/ComponentManager.h>
 #include <crepe/api/GameObject.h>
 #include <crepe/api/Metadata.h>
 #include <crepe/api/Transform.h>
 #include <crepe/api/Vector2.h>
+#include <crepe/manager/ComponentManager.h>
 
 using namespace std;
 using namespace crepe;
 
 class ECSTest : public ::testing::Test {
 	Mediator m;
+
 public:
 	ComponentManager mgr{m};
 };
diff --git a/src/test/EventTest.cpp b/src/test/EventTest.cpp
index 350dd07..dccd554 100644
--- a/src/test/EventTest.cpp
+++ b/src/test/EventTest.cpp
@@ -2,9 +2,9 @@
 #include <gtest/gtest.h>
 
 #include <crepe/api/Event.h>
-#include <crepe/manager/EventManager.h>
 #include <crepe/api/IKeyListener.h>
 #include <crepe/api/IMouseListener.h>
+#include <crepe/manager/EventManager.h>
 
 using namespace std;
 using namespace std::chrono_literals;
@@ -37,9 +37,7 @@ public:
 };
 
 TEST_F(EventManagerTest, EventSubscription) {
-	EventHandler<KeyPressEvent> key_handler = [](const KeyPressEvent & e) {
-		return true;
-	};
+	EventHandler<KeyPressEvent> key_handler = [](const KeyPressEvent & e) { return true; };
 
 	// Subscribe to KeyPressEvent
 	EventManager::get_instance().subscribe<KeyPressEvent>(key_handler, 1);
diff --git a/src/test/ParticleTest.cpp b/src/test/ParticleTest.cpp
index 4e9fa4e..a659fe5 100644
--- a/src/test/ParticleTest.cpp
+++ b/src/test/ParticleTest.cpp
@@ -1,4 +1,3 @@
-#include <crepe/manager/ComponentManager.h>
 #include <crepe/Particle.h>
 #include <crepe/api/Config.h>
 #include <crepe/api/GameObject.h>
@@ -7,6 +6,7 @@
 #include <crepe/api/Sprite.h>
 #include <crepe/api/Texture.h>
 #include <crepe/api/Transform.h>
+#include <crepe/manager/ComponentManager.h>
 #include <crepe/system/ParticleSystem.h>
 #include <gtest/gtest.h>
 #include <math.h>
@@ -17,6 +17,7 @@ using namespace crepe;
 
 class ParticlesTest : public ::testing::Test {
 	Mediator m;
+
 public:
 	ComponentManager component_manager{m};
 	ParticleSystem particle_system{m};
diff --git a/src/test/PhysicsTest.cpp b/src/test/PhysicsTest.cpp
index 01b7c51..43af8e4 100644
--- a/src/test/PhysicsTest.cpp
+++ b/src/test/PhysicsTest.cpp
@@ -1,8 +1,8 @@
-#include <crepe/manager/ComponentManager.h>
 #include <crepe/api/Config.h>
 #include <crepe/api/GameObject.h>
 #include <crepe/api/Rigidbody.h>
 #include <crepe/api/Transform.h>
+#include <crepe/manager/ComponentManager.h>
 #include <crepe/system/PhysicsSystem.h>
 #include <gtest/gtest.h>
 
@@ -12,6 +12,7 @@ using namespace crepe;
 
 class PhysicsTest : public ::testing::Test {
 	Mediator m;
+
 public:
 	ComponentManager component_manager{m};
 	PhysicsSystem system{m};
diff --git a/src/test/RenderSystemTest.cpp b/src/test/RenderSystemTest.cpp
index 3528e46..c105dcb 100644
--- a/src/test/RenderSystemTest.cpp
+++ b/src/test/RenderSystemTest.cpp
@@ -7,11 +7,11 @@
 #define protected public
 
 #include <crepe/api/Camera.h>
-#include <crepe/manager/ComponentManager.h>
 #include <crepe/api/Color.h>
 #include <crepe/api/GameObject.h>
 #include <crepe/api/Sprite.h>
 #include <crepe/api/Texture.h>
+#include <crepe/manager/ComponentManager.h>
 
 #include <crepe/system/RenderSystem.h>
 
@@ -21,6 +21,7 @@ using namespace testing;
 
 class RenderSystemTest : public Test {
 	Mediator m;
+
 public:
 	ComponentManager mgr{m};
 	RenderSystem sys{m};
diff --git a/src/test/SceneManagerTest.cpp b/src/test/SceneManagerTest.cpp
index d027d89..9bb260c 100644
--- a/src/test/SceneManagerTest.cpp
+++ b/src/test/SceneManagerTest.cpp
@@ -1,13 +1,13 @@
 #include <gtest/gtest.h>
 
-#include <crepe/types.h>
-#include <crepe/manager/SceneManager.h>
-#include <crepe/manager/ComponentManager.h>
 #include <crepe/api/GameObject.h>
 #include <crepe/api/Metadata.h>
 #include <crepe/api/Scene.h>
 #include <crepe/api/Transform.h>
 #include <crepe/api/Vector2.h>
+#include <crepe/manager/ComponentManager.h>
+#include <crepe/manager/SceneManager.h>
+#include <crepe/types.h>
 
 using namespace std;
 using namespace crepe;
@@ -57,6 +57,7 @@ private:
 
 class SceneManagerTest : public ::testing::Test {
 	Mediator m;
+
 public:
 	ComponentManager component_mgr{m};
 	SceneManager scene_mgr{m};
diff --git a/src/test/ScriptEventTest.cpp b/src/test/ScriptEventTest.cpp
index 7a9abbb..5da31e7 100644
--- a/src/test/ScriptEventTest.cpp
+++ b/src/test/ScriptEventTest.cpp
@@ -4,13 +4,13 @@
 #define private public
 #define protected public
 
-#include <crepe/manager/ComponentManager.h>
-#include <crepe/manager/EventManager.h>
 #include <crepe/api/BehaviorScript.h>
 #include <crepe/api/Event.h>
 #include <crepe/api/GameObject.h>
 #include <crepe/api/Script.h>
 #include <crepe/api/Vector2.h>
+#include <crepe/manager/ComponentManager.h>
+#include <crepe/manager/EventManager.h>
 #include <crepe/system/ScriptSystem.h>
 
 #include "ScriptTest.h"
@@ -32,7 +32,7 @@ TEST_F(ScriptEventTest, Inactive) {
 	EventManager & evmgr = this->event_manager;
 
 	unsigned event_count = 0;
-	script.subscribe<MyEvent>([&](const MyEvent &){
+	script.subscribe<MyEvent>([&](const MyEvent &) {
 		event_count++;
 		return true;
 	});
@@ -48,4 +48,3 @@ TEST_F(ScriptEventTest, Inactive) {
 	evmgr.trigger_event<MyEvent>();
 	EXPECT_EQ(1, event_count);
 }
-
diff --git a/src/test/ScriptSceneTest.cpp b/src/test/ScriptSceneTest.cpp
index f96ae8b..9ee1e52 100644
--- a/src/test/ScriptSceneTest.cpp
+++ b/src/test/ScriptSceneTest.cpp
@@ -4,8 +4,8 @@
 #define private public
 #define protected public
 
-#include <crepe/manager/SceneManager.h>
 #include "ScriptTest.h"
+#include <crepe/manager/SceneManager.h>
 
 using namespace std;
 using namespace crepe;
@@ -28,4 +28,3 @@ TEST_F(ScriptSceneTest, Inactive) {
 	script.set_next_scene(non_default_value);
 	EXPECT_EQ(non_default_value, scene_manager.next_scene);
 }
-
diff --git a/src/test/ScriptTest.cpp b/src/test/ScriptTest.cpp
index 6d0d5fb..1d2d6dd 100644
--- a/src/test/ScriptTest.cpp
+++ b/src/test/ScriptTest.cpp
@@ -1,5 +1,5 @@
-#include <gtest/gtest.h>
 #include <gmock/gmock.h>
+#include <gtest/gtest.h>
 
 // stupid hack to allow access to private/protected members under test
 #define private public
@@ -75,4 +75,3 @@ TEST_F(ScriptTest, UpdateInactive) {
 		system.update();
 	}
 }
-
diff --git a/src/test/ScriptTest.h b/src/test/ScriptTest.h
index 9a71ba7..1bbfdd3 100644
--- a/src/test/ScriptTest.h
+++ b/src/test/ScriptTest.h
@@ -1,22 +1,24 @@
 #pragma once
 
-#include <gtest/gtest.h>
 #include <gmock/gmock.h>
+#include <gtest/gtest.h>
 
-#include <crepe/manager/ComponentManager.h>
-#include <crepe/system/ScriptSystem.h>
 #include <crepe/api/BehaviorScript.h>
 #include <crepe/api/Script.h>
+#include <crepe/manager/ComponentManager.h>
+#include <crepe/system/ScriptSystem.h>
 
 class ScriptTest : public testing::Test {
 protected:
 	crepe::Mediator mediator;
+
 public:
 	crepe::ComponentManager component_manager{mediator};
 	crepe::ScriptSystem system{mediator};
 
 	class MyScript : public crepe::Script {
 		// NOTE: explicitly stating `public:` is not required on actual scripts
+
 	public:
 		MOCK_METHOD(void, init, (), (override));
 		MOCK_METHOD(void, update, (), (override));
-- 
cgit v1.2.3