diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-05-08 20:16:32 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-11-07 16:41:37 +0000 |
commit | 112c02f40806f550370b3928f3c1965b5bee5262 (patch) | |
tree | dcee2ff5f436522f498e751e1c317145135f46e7 /test | |
parent | Import setValue, silence clang warning (diff) | |
download | ilt-112c02f40806f550370b3928f3c1965b5bee5262.tar.bz2 ilt-112c02f40806f550370b3928f3c1965b5bee5262.tar.xz ilt-112c02f40806f550370b3928f3c1965b5bee5262.zip |
Implement writing shared objects with @id
Diffstat (limited to 'test')
-rw-r--r-- | test/test-persistence.cpp | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/test/test-persistence.cpp b/test/test-persistence.cpp index ab16166..e13cb7a 100644 --- a/test/test-persistence.cpp +++ b/test/test-persistence.cpp @@ -39,6 +39,12 @@ struct SubObject : public AbsObject { dummy() const override { } + + [[nodiscard]] std::string + getId() const override + { + return "someid"; + } }; struct SubObject2 : public AbsObject { @@ -313,9 +319,8 @@ BOOST_AUTO_TEST_CASE(write_test_dfl) auto to = std::make_unique<TestObject>(); std::stringstream ss; Persistence::JsonWritePersistence {ss}.saveState(to); - // TODO We can omit writing explicit nulls BOOST_CHECK_EQUAL(ss.str(), - R"({"@typeid":"TestObject","flt":0,"str":"","bl":false,"pos":[0,0,0],"flts":[],"poss":[],"nest":[],"ptr":null,"aptr":null,"vptr":[]})"); + R"({"@typeid":"TestObject","flt":0,"str":"","bl":false,"pos":[0,0,0],"flts":[],"poss":[],"nest":[],"vptr":[]})"); } BOOST_FIXTURE_TEST_CASE(write_test_loaded, JPP) @@ -323,9 +328,8 @@ BOOST_FIXTURE_TEST_CASE(write_test_loaded, JPP) auto to = load_json<std::unique_ptr<TestObject>>(FIXTURESDIR "json/load_object.json"); std::stringstream ss; Persistence::JsonWritePersistence {ss}.saveState(to); - // TODO We can omit writing explicit nulls BOOST_CHECK_EQUAL(ss.str(), - R"({"@typeid":"TestObject","flt":3.14,"str":"Lovely string","bl":true,"pos":[3.14,6.28,1.57],"flts":[3.14,6.28,1.57,0,-1,-3.14],"poss":[[3.14,6.28,1.57],[0,-1,-3.14]],"nest":[[["a","b"],["c","d","e"]],[["f"]],[]],"ptr":{"@typeid":"TestObject","flt":3.14,"str":"Lovely string","bl":false,"pos":[0,0,0],"flts":[],"poss":[],"nest":[],"ptr":null,"aptr":null,"vptr":[]},"aptr":null,"vptr":[]})"); + R"({"@typeid":"TestObject","flt":3.14,"str":"Lovely string","bl":true,"pos":[3.14,6.28,1.57],"flts":[3.14,6.28,1.57,0,-1,-3.14],"poss":[[3.14,6.28,1.57],[0,-1,-3.14]],"nest":[[["a","b"],["c","d","e"]],[["f"]],[]],"ptr":{"@typeid":"TestObject","flt":3.14,"str":"Lovely string","bl":false,"pos":[0,0,0],"flts":[],"poss":[],"nest":[],"vptr":[]},"vptr":[]})"); } BOOST_FIXTURE_TEST_CASE(write_test_loaded_abs, JPP) @@ -333,20 +337,19 @@ BOOST_FIXTURE_TEST_CASE(write_test_loaded_abs, JPP) auto to = load_json<std::unique_ptr<TestObject>>(FIXTURESDIR "json/abs.json"); std::stringstream ss; Persistence::JsonWritePersistence {ss}.saveState(to); - // TODO We can omit writing explicit nulls BOOST_CHECK_EQUAL(ss.str(), - R"({"@typeid":"TestObject","flt":0,"str":"","bl":false,"pos":[0,0,0],"flts":[],"poss":[],"nest":[],"ptr":null,"aptr":{"@typeid":"SubObject","base":"set base","sub":"set sub"},"vptr":[]})"); + R"({"@typeid":"TestObject","flt":0,"str":"","bl":false,"pos":[0,0,0],"flts":[],"poss":[],"nest":[],"aptr":{"@typeid":"SubObject","base":"set base","sub":"set sub"},"vptr":[]})"); } BOOST_FIXTURE_TEST_CASE(write_test_loaded_shared, JPP) { auto to = load_json<std::unique_ptr<SharedTestObject>>(FIXTURESDIR "json/shared_ptr_same.json"); std::stringstream ss; + Persistence::seenSharedObjects.clear(); Persistence::JsonWritePersistence {ss}.saveState(to); - // TODO We can omit writing explicit nulls - // TODO Also not really implemented, but it runs :) - // BOOST_CHECK_EQUAL(ss.str(), - // R"({"@typeid":"SharedTestObject","sptr":{"@typeid":"SubObject","@id":"someid"},"ssptr":"someid"})"); + BOOST_CHECK_EQUAL(Persistence::seenSharedObjects.size(), 1); + BOOST_CHECK_EQUAL(ss.str(), + R"({"@typeid":"SharedTestObject","sptr":{"@typeid":"SubObject","@id":"someid","base":"","sub":""},"ssptr":"someid"})"); } BOOST_DATA_TEST_CASE(write_special_strings, TEST_STRINGS, exp, in) @@ -356,3 +359,13 @@ BOOST_DATA_TEST_CASE(write_special_strings, TEST_STRINGS, exp, in) Persistence::JsonWritePersistence {ss}.saveState(copy); BOOST_CHECK_EQUAL(ss.str(), exp); } + +BOOST_AUTO_TEST_CASE(get_default_id) +{ + SubObject2 so; + const auto id {so.getId()}; + BOOST_TEST_CONTEXT(id) { + auto ptr = std::stoul(id, nullptr, 16); + BOOST_CHECK_EQUAL(ptr, reinterpret_cast<decltype(ptr)>(&so)); + } +} |