From c21b0f14a33f4c3121e643d45517965895211080 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 5 Mar 2023 03:28:53 +0000 Subject: Move persistence test objects to test library --- test/Jamfile.jam | 2 +- test/test-persistence.cpp | 83 +---------------------------------------------- test/testStructures.cpp | 49 ++++++++++++++++++++++++++++ test/testStructures.h | 52 +++++++++++++++++++++++++++++ 4 files changed, 103 insertions(+), 83 deletions(-) create mode 100644 test/testStructures.cpp create mode 100644 test/testStructures.h 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 ] ] : test ; run test-text.cpp ; run test-enumDetails.cpp ; run test-render.cpp : : : 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 #include +#include "testStructures.h" #include #include #include @@ -14,75 +15,6 @@ #include #include -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 flts; - std::vector poss; - std::vector>> nest; - std::unique_ptr ptr; - std::unique_ptr aptr; - std::vector> 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 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 sptr; - std::shared_ptr 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>(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 + +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 flts; + std::vector poss; + std::vector>> nest; + std::unique_ptr ptr; + std::unique_ptr aptr; + std::vector> vptr; + + bool persist(Persistence::PersistenceStore & store) override; +}; + +struct SharedTestObject : public Persistence::Persistable { + SharedTestObject() = default; + + std::shared_ptr sptr; + std::shared_ptr ssptr; + + bool persist(Persistence::PersistenceStore & store) override; +}; -- cgit v1.2.3