summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-04-17 23:59:42 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2021-11-07 16:41:37 +0000
commit1d8a75f050f54ccb837ac13530d53c03fca38798 (patch)
treee2fda09ddf8e0f9b0e917da7d34e0fa056025a9b /test
parentSecond swing persistance (diff)
downloadilt-1d8a75f050f54ccb837ac13530d53c03fca38798.tar.bz2
ilt-1d8a75f050f54ccb837ac13530d53c03fca38798.tar.xz
ilt-1d8a75f050f54ccb837ac13530d53c03fca38798.zip
Move json persistance into lib
Diffstat (limited to 'test')
-rw-r--r--test/test-persistance.cpp87
1 files changed, 2 insertions, 85 deletions
diff --git a/test/test-persistance.cpp b/test/test-persistance.cpp
index b6bde3f..101c2d2 100644
--- a/test/test-persistance.cpp
+++ b/test/test-persistance.cpp
@@ -2,96 +2,13 @@
#include <boost/test/unit_test.hpp>
-#include <functional>
#include <glm/glm.hpp>
#include <iosfwd>
-#include <jsonParse.h>
+#include <jsonParse-persistance.h>
#include <memory>
-#include <persistance.h>
#include <string>
#include <vector>
-struct TestObject;
-
-namespace Persistanace {
- struct JsonLoadPersistanceStore : public json::jsonParser {
- explicit JsonLoadPersistanceStore(std::istream & in) : json::jsonParser {&in} { }
-
- Stack stk;
-
- inline SelectionPtr &
- current()
- {
- return stk.top();
- }
-
- template<typename T>
- void
- loadState(std::unique_ptr<T> & t)
- {
- stk.push(std::make_unique<SelectionT<std::unique_ptr<T>>>(std::ref(t)));
- yy_push_state(0);
- yylex();
- }
- void
- BeginObject() override
- {
- stk.push(current()->BeginObject());
- }
- void
- BeginArray() override
- {
- current()->BeginArray(stk);
- }
- template<typename T>
- inline void
- PushValue(T && value)
- {
- current()->beforeValue(stk);
- (*current())(value);
- stk.pop();
- }
- void
- PushBoolean(bool value) override
- {
- PushValue(value);
- }
- void
- PushNumber(float value) override
- {
- PushValue(value);
- }
- void
- PushNull() override
- {
- PushValue(nullptr);
- }
- void
- PushText(std::string && value) override
- {
- PushValue(value);
- }
- void
- PushKey(std::string && k) override
- {
- stk.push(current()->select(k));
- }
- void
- EndArray() override
- {
- stk.pop();
- }
- void
- EndObject() override
- {
- stk.pop();
- }
- };
-}
-
-#define STORE_TYPE store.persistType(typeid(*this))
-#define STORE_MEMBER(mbr) store.persistValue(#mbr, mbr)
-
struct TestObject : public Persistanace::Persistable {
TestObject() = default;
@@ -132,7 +49,7 @@ BOOST_AUTO_TEST_CASE(load_object)
{
Persistanace::Persistable::addFactory("TestObject", std::make_unique<TestObject>);
std::stringstream ss {input};
- Persistanace::JsonLoadPersistanceStore jlps {ss};
+ Persistanace::JsonParsePersistance jlps {ss};
std::unique_ptr<TestObject> to;
jlps.loadState(to);