diff options
-rw-r--r-- | test/Jamfile.jam | 2 | ||||
-rw-r--r-- | test/test-persistence.cpp | 83 | ||||
-rw-r--r-- | test/testStructures.cpp | 49 | ||||
-rw-r--r-- | test/testStructures.h | 52 |
4 files changed, 103 insertions, 83 deletions
diff --git a/test/Jamfile.jam b/test/Jamfile.jam index 907632e..e5781e1 100644 --- a/test/Jamfile.jam +++ b/test/Jamfile.jam @@ -48,7 +48,7 @@ run test-maths.cpp ; run test-lib.cpp ; run test-geo.cpp ; run test-network.cpp ; -run test-persistence.cpp : -- : [ sequence.insertion-sort [ glob fixtures/json/*.json fixtures/json/bad/*.json ] ] ; +run test-persistence.cpp : -- : [ sequence.insertion-sort [ glob fixtures/json/*.json fixtures/json/bad/*.json ] ] : <library>test ; run test-text.cpp ; run test-enumDetails.cpp ; run test-render.cpp : : : <library>test ; diff --git a/test/test-persistence.cpp b/test/test-persistence.cpp index 7bca91a..a72c481 100644 --- a/test/test-persistence.cpp +++ b/test/test-persistence.cpp @@ -3,6 +3,7 @@ #include <boost/test/data/test_case.hpp> #include <boost/test/unit_test.hpp> +#include "testStructures.h" #include <filesystem> #include <glm/glm.hpp> #include <iosfwd> @@ -14,75 +15,6 @@ #include <tuple> #include <vector> -struct AbsObject : public Persistence::Persistable { - std::string base; - - bool - persist(Persistence::PersistenceStore & store) override - { - return STORE_TYPE && STORE_MEMBER(base); - } - - virtual void dummy() const = 0; -}; - -struct SubObject : public AbsObject { - std::string sub; - - bool - persist(Persistence::PersistenceStore & store) override - { - return STORE_TYPE && AbsObject::persist(store) && STORE_MEMBER(sub); - } - - void - dummy() const override - { - } - - [[nodiscard]] std::string - getId() const override - { - return "someid"; - } -}; - -struct SubObject2 : public AbsObject { - bool - persist(Persistence::PersistenceStore & store) override - { - return STORE_TYPE && AbsObject::persist(store); - } - - void - dummy() const override - { - } -}; - -struct TestObject : public Persistence::Persistable { - TestObject() = default; - - float flt {}; - std::string str {}; - bool bl {}; - glm::vec3 pos {}; - std::vector<float> flts; - std::vector<glm::vec3> poss; - std::vector<std::vector<std::vector<std::string>>> nest; - std::unique_ptr<TestObject> ptr; - std::unique_ptr<AbsObject> aptr; - std::vector<std::unique_ptr<TestObject>> vptr; - - bool - persist(Persistence::PersistenceStore & store) override - { - return STORE_TYPE && STORE_MEMBER(flt) && STORE_MEMBER(str) && STORE_MEMBER(bl) && STORE_MEMBER(pos) - && STORE_MEMBER(flts) && STORE_MEMBER(poss) && STORE_MEMBER(nest) && STORE_MEMBER(ptr) - && STORE_MEMBER(aptr) && STORE_MEMBER(vptr); - } -}; - struct JPP { template<typename T> T @@ -214,19 +146,6 @@ BOOST_FIXTURE_TEST_CASE(test_conversion, JPP) BOOST_CHECK_EQUAL(to->flt, 3.14F); } -struct SharedTestObject : public Persistence::Persistable { - SharedTestObject() = default; - - std::shared_ptr<AbsObject> sptr; - std::shared_ptr<SubObject> ssptr; - - bool - persist(Persistence::PersistenceStore & store) override - { - return STORE_TYPE && STORE_MEMBER(sptr) && STORE_MEMBER(ssptr); - } -}; - BOOST_FIXTURE_TEST_CASE(load_shared_object_diff, JPP) { auto to = load_json<std::unique_ptr<SharedTestObject>>(FIXTURESDIR "json/shared_ptr_diff.json"); diff --git a/test/testStructures.cpp b/test/testStructures.cpp new file mode 100644 index 0000000..8305078 --- /dev/null +++ b/test/testStructures.cpp @@ -0,0 +1,49 @@ +#include "testStructures.h" + +bool +AbsObject::persist(Persistence::PersistenceStore & store) +{ + return STORE_TYPE && STORE_MEMBER(base); +} + +bool +SubObject::persist(Persistence::PersistenceStore & store) +{ + return STORE_TYPE && AbsObject::persist(store) && STORE_MEMBER(sub); +} + +void +SubObject::dummy() const +{ +} + +std::string +SubObject::getId() const +{ + return "someid"; +} + +bool +SubObject2::persist(Persistence::PersistenceStore & store) +{ + return STORE_TYPE && AbsObject::persist(store); +} + +void +SubObject2::dummy() const +{ +} + +bool +TestObject::persist(Persistence::PersistenceStore & store) +{ + return STORE_TYPE && STORE_MEMBER(flt) && STORE_MEMBER(str) && STORE_MEMBER(bl) && STORE_MEMBER(pos) + && STORE_MEMBER(flts) && STORE_MEMBER(poss) && STORE_MEMBER(nest) && STORE_MEMBER(ptr) && STORE_MEMBER(aptr) + && STORE_MEMBER(vptr); +} + +bool +SharedTestObject::persist(Persistence::PersistenceStore & store) +{ + return STORE_TYPE && STORE_MEMBER(sptr) && STORE_MEMBER(ssptr); +} diff --git a/test/testStructures.h b/test/testStructures.h new file mode 100644 index 0000000..666562e --- /dev/null +++ b/test/testStructures.h @@ -0,0 +1,52 @@ +#pragma once + +#include <persistence.h> + +struct AbsObject : public Persistence::Persistable { + std::string base; + + bool persist(Persistence::PersistenceStore & store) override; + + virtual void dummy() const = 0; +}; + +struct SubObject : public AbsObject { + std::string sub; + + bool persist(Persistence::PersistenceStore & store) override; + + void dummy() const override; + + [[nodiscard]] std::string getId() const override; +}; + +struct SubObject2 : public AbsObject { + bool persist(Persistence::PersistenceStore & store) override; + void dummy() const override; +}; + +struct TestObject : public Persistence::Persistable { + TestObject() = default; + + float flt {}; + std::string str {}; + bool bl {}; + glm::vec3 pos {}; + std::vector<float> flts; + std::vector<glm::vec3> poss; + std::vector<std::vector<std::vector<std::string>>> nest; + std::unique_ptr<TestObject> ptr; + std::unique_ptr<AbsObject> aptr; + std::vector<std::unique_ptr<TestObject>> vptr; + + bool persist(Persistence::PersistenceStore & store) override; +}; + +struct SharedTestObject : public Persistence::Persistable { + SharedTestObject() = default; + + std::shared_ptr<AbsObject> sptr; + std::shared_ptr<SubObject> ssptr; + + bool persist(Persistence::PersistenceStore & store) override; +}; |