Skip to content

Commit

Permalink
#143: tests: move new test to virtual serialize test
Browse files Browse the repository at this point in the history
  • Loading branch information
lifflander committed Oct 19, 2020
1 parent d528d0c commit c3ffe4f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 35 deletions.
35 changes: 0 additions & 35 deletions tests/unit/test_footprinter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -529,39 +529,4 @@ TEST_F(TestFootprinter, test_virtual_serialize) {
}
}

struct HolderBase {
checkpoint_virtual_serialize_root()

virtual ~HolderBase() = default;

template <typename Serializer>
void serialize(Serializer& s) {}
};

template <typename ObjT>
struct HolderObjBase : HolderBase {
checkpoint_virtual_serialize_derived_from(HolderBase)

virtual ObjT* get() = 0;

template <typename Serializer>
void serialize(Serializer& s) {}
};

template <typename ObjT>
struct HolderBasic final : HolderObjBase<ObjT> {
checkpoint_virtual_serialize_derived_from(HolderObjBase<ObjT>)

ObjT* get() override { return obj_; }
ObjT* obj_ = nullptr;

template <typename Serializer>
void serialize(Serializer& s) {}
};

TEST_F(TestFootprinter, test_virtual_serialize_templated) {
std::unique_ptr<HolderBase> ptr = std::make_unique<HolderBasic<int>>();
checkpoint::getMemoryFootprint(ptr);
}

}}} // end namespace checkpoint::tests::unit
43 changes: 43 additions & 0 deletions tests/unit/test_virtual_serialize.cc
Original file line number Diff line number Diff line change
Expand Up @@ -612,4 +612,47 @@ INSTANTIATE_TYPED_TEST_CASE_P(
test_virtual_serialize_inst, TestVirtualSerialize, ConstructTypes,
);

////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

// Test for virtual serialize with an abstract class

using TestVirtualSerializeTemplated = TestHarness;

struct HolderBase {
checkpoint_virtual_serialize_root()

virtual ~HolderBase() = default;

template <typename Serializer>
void serialize(Serializer& s) {}
};

template <typename ObjT>
struct HolderObjBase : HolderBase {
checkpoint_virtual_serialize_derived_from(HolderBase)

virtual ObjT* get() = 0;

template <typename Serializer>
void serialize(Serializer& s) {}
};

template <typename ObjT>
struct HolderBasic final : HolderObjBase<ObjT> {
checkpoint_virtual_serialize_derived_from(HolderObjBase<ObjT>)

ObjT* get() override { return obj_; }
ObjT* obj_ = nullptr;

template <typename Serializer>
void serialize(Serializer& s) {}
};

TEST_F(TestVirtualSerializeTemplated, test_virtual_serialize_templated) {
std::unique_ptr<HolderBase> ptr = std::make_unique<HolderBasic<int>>();
checkpoint::getSize(ptr);
}

}}} // end namespace checkpoint::tests::unit

0 comments on commit c3ffe4f

Please sign in to comment.