summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/fixtures/json/shared_ptr1.json11
-rw-r--r--test/fixtures/json/shared_ptr2.json8
-rw-r--r--test/test-persistance.cpp34
3 files changed, 53 insertions, 0 deletions
diff --git a/test/fixtures/json/shared_ptr1.json b/test/fixtures/json/shared_ptr1.json
new file mode 100644
index 0000000..bb18e33
--- /dev/null
+++ b/test/fixtures/json/shared_ptr1.json
@@ -0,0 +1,11 @@
+{
+ "@typeid": "SharedTestObject",
+ "sptr": {
+ "@typeid": "SubObject",
+ "@id": "someid"
+ },
+ "ssptr": {
+ "@typeid": "SubObject",
+ "@id": "some other id"
+ }
+}
diff --git a/test/fixtures/json/shared_ptr2.json b/test/fixtures/json/shared_ptr2.json
new file mode 100644
index 0000000..4115493
--- /dev/null
+++ b/test/fixtures/json/shared_ptr2.json
@@ -0,0 +1,8 @@
+{
+ "@typeid": "SharedTestObject",
+ "sptr": {
+ "@typeid": "SubObject",
+ "@id": "someid"
+ },
+ "ssptr": "someid"
+}
diff --git a/test/test-persistance.cpp b/test/test-persistance.cpp
index a4fda31..2c06c48 100644
--- a/test/test-persistance.cpp
+++ b/test/test-persistance.cpp
@@ -68,6 +68,7 @@ struct JPP : public Persistanace::JsonParsePersistance {
BOOST_TEST_CONTEXT(path) {
std::ifstream ss {path};
auto to = loadState<T>(ss);
+ Persistanace::sharedObjects.clear();
BOOST_CHECK(stk.empty());
BOOST_REQUIRE(to);
return to;
@@ -177,3 +178,36 @@ BOOST_FIXTURE_TEST_CASE(load_vector_ptr, JPP)
BOOST_CHECK(!to->vptr.at(2));
BOOST_CHECK(to->vptr.at(3)->str.empty());
}
+
+struct SharedTestObject : public Persistanace::Persistable {
+ SharedTestObject() = default;
+
+ std::shared_ptr<AbsObject> sptr;
+ std::shared_ptr<SubObject> ssptr;
+
+ bool
+ persist(Persistanace::PersistanceStore & store) override
+ {
+ return STORE_TYPE && STORE_MEMBER(sptr) && STORE_MEMBER(ssptr);
+ }
+};
+
+BOOST_FIXTURE_TEST_CASE(load_shared_object1, JPP)
+{
+ auto to = load_json<std::unique_ptr<SharedTestObject>>(FIXTURESDIR "json/shared_ptr1.json");
+ BOOST_CHECK(to->sptr);
+ BOOST_CHECK(to->ssptr);
+ BOOST_CHECK_NE(to->sptr, to->ssptr);
+ BOOST_CHECK_EQUAL(to->sptr.use_count(), 1);
+ BOOST_CHECK_EQUAL(to->ssptr.use_count(), 1);
+}
+
+BOOST_FIXTURE_TEST_CASE(load_shared_object2, JPP)
+{
+ auto to = load_json<std::unique_ptr<SharedTestObject>>(FIXTURESDIR "json/shared_ptr2.json");
+ BOOST_CHECK(to->sptr);
+ BOOST_CHECK(to->ssptr);
+ BOOST_CHECK_EQUAL(to->sptr, to->ssptr);
+ BOOST_CHECK_EQUAL(to->sptr.use_count(), 2);
+ BOOST_CHECK_EQUAL(to->ssptr.use_count(), 2);
+}