aboutsummaryrefslogtreecommitdiff
path: root/src/test/SaveManagerTest.cpp
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-12-11 18:54:56 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-12-11 18:54:56 +0100
commit904b853a277c3fcd0f84561b6e45bcbd4f0b25c6 (patch)
tree84b8b3d3c29471e4edc2707444b21ac406ee2799 /src/test/SaveManagerTest.cpp
parent876746db205b259430b6b438227c986dbf0cb59d (diff)
parent30c17c98e54c1534664de08ca3838c40c859d166 (diff)
merge master
Diffstat (limited to 'src/test/SaveManagerTest.cpp')
-rw-r--r--src/test/SaveManagerTest.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/test/SaveManagerTest.cpp b/src/test/SaveManagerTest.cpp
new file mode 100644
index 0000000..0209f6a
--- /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"));
+
+ string value = mgr.get<string>("foo");
+ EXPECT_EQ(value, "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);
+}