diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-03-05 03:28:53 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-03-05 03:28:53 +0000 |
commit | c21b0f14a33f4c3121e643d45517965895211080 (patch) | |
tree | 31f8c5083c3ca87db93a7783693759d5e8480726 /test | |
parent | Unify asset factory perf tests as it's now a combined load/create operation (diff) | |
download | ilt-c21b0f14a33f4c3121e643d45517965895211080.tar.bz2 ilt-c21b0f14a33f4c3121e643d45517965895211080.tar.xz ilt-c21b0f14a33f4c3121e643d45517965895211080.zip |
Move persistence test objects to test library
Diffstat (limited to 'test')
-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; +}; |