aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-12-11 13:58:19 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-12-11 13:58:19 +0100
commitd228d4b3856606ad4395723b2703759a0ebe9832 (patch)
treebfd3019ca2c9bec258fffca9a9204ddc88768264 /src/test
parent770496ee9d0e45480c0e0f8951adb8eee247bfe1 (diff)
parentc45b60941b82dec2097d958b396a117b1634eada (diff)
Merge branch 'master' into loek/replay
Diffstat (limited to 'src/test')
-rw-r--r--src/test/CMakeLists.txt2
-rw-r--r--src/test/SaveManagerTest.cpp40
-rw-r--r--src/test/ScriptSaveManagerTest.cpp35
3 files changed, 77 insertions, 0 deletions
diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt
index a0bb56d..28a4f8b 100644
--- a/src/test/CMakeLists.txt
+++ b/src/test/CMakeLists.txt
@@ -19,6 +19,8 @@ target_sources(test_main PUBLIC
ScriptEventTest.cpp
ScriptSceneTest.cpp
Profiling.cpp
+ SaveManagerTest.cpp
+ ScriptSaveManagerTest.cpp
ScriptECSTest.cpp
ReplayManagerTest.cpp
)
diff --git a/src/test/SaveManagerTest.cpp b/src/test/SaveManagerTest.cpp
new file mode 100644
index 0000000..e9b0c29
--- /dev/null
+++ b/src/test/SaveManagerTest.cpp
@@ -0,0 +1,40 @@
+#include <gtest/gtest.h>
+
+#include <crepe/ValueBroker.h>
+#include <crepe/facade/DB.h>
+#include <crepe/manager/SaveManager.h>
+
+using namespace std;
+using namespace crepe;
+using namespace testing;
+
+class SaveManagerTest : public Test {
+ Mediator m;
+ class TestSaveManager : public SaveManager {
+ using SaveManager::SaveManager;
+
+ // in-memory database for testing
+ DB db{};
+ virtual DB & get_db() override { return this->db; }
+ };
+
+public:
+ TestSaveManager mgr{m};
+};
+
+TEST_F(SaveManagerTest, ReadWrite) {
+ ASSERT_FALSE(mgr.has("foo"));
+ mgr.set<string>("foo", "bar");
+ ASSERT_TRUE(mgr.has("foo"));
+
+ ValueBroker value = mgr.get<string>("foo");
+ EXPECT_EQ(value.get(), "bar");
+}
+
+TEST_F(SaveManagerTest, DefaultValue) {
+ ValueBroker value = mgr.get<int>("foo", 3);
+
+ ASSERT_EQ(value.get(), 3);
+ value.set(5);
+ ASSERT_EQ(value.get(), 5);
+}
diff --git a/src/test/ScriptSaveManagerTest.cpp b/src/test/ScriptSaveManagerTest.cpp
new file mode 100644
index 0000000..64403c4
--- /dev/null
+++ b/src/test/ScriptSaveManagerTest.cpp
@@ -0,0 +1,35 @@
+#include <gtest/gtest.h>
+
+// stupid hack to allow access to private/protected members under test
+#define private public
+#define protected public
+
+#include <crepe/facade/DB.h>
+#include <crepe/manager/SaveManager.h>
+
+#include "ScriptTest.h"
+
+using namespace std;
+using namespace crepe;
+using namespace testing;
+
+class ScriptSaveManagerTest : public ScriptTest {
+public:
+ class TestSaveManager : public SaveManager {
+ using SaveManager::SaveManager;
+
+ // in-memory database for testing
+ DB db{};
+ virtual DB & get_db() override { return this->db; }
+ };
+
+ TestSaveManager save_mgr{mediator};
+};
+
+TEST_F(ScriptSaveManagerTest, GetSaveManager) {
+ MyScript & script = this->script;
+
+ SaveManager & mgr = script.get_save_manager();
+
+ EXPECT_EQ(&mgr, &save_mgr);
+}