1515#include < functional>
1616#include < gtest/gtest.h>
1717
18+ #include " test_serialize.h"
1819#include " test_utils.h"
1920
2021#include " models/gp.h"
21- #include < cereal/archives/json.hpp>
22- #include < cereal/types/polymorphic.hpp>
2322
2423CEREAL_REGISTER_TYPE_WITH_NAME (albatross::MockModel, " mock_model_name" );
2524
@@ -58,17 +57,6 @@ using DoubleRegressionModelPointer = std::unique_ptr<RegressionModel<double>>;
5857 * the variants using TYPED_TEST.
5958 */
6059
61- template <typename X> struct SerializableType {
62- using RepresentationType = X;
63- virtual RepresentationType create () const {
64- RepresentationType obj;
65- return obj;
66- }
67- virtual bool are_equal (const X &lhs, const X &rhs) const {
68- return lhs == rhs;
69- };
70- };
71-
7260struct EmptyEigenVectorXd : public SerializableType <Eigen::VectorXd> {
7361 Eigen::VectorXd create () const override {
7462 Eigen::VectorXd x;
@@ -358,10 +346,8 @@ class FitGaussianProcess
358346 };
359347};
360348
361- template <typename Serializable>
362- struct PolymorphicSerializeTest : public ::testing::Test {
363- typedef typename Serializable::RepresentationType Representation;
364- };
349+ REGISTER_TYPED_TEST_CASE_P (SerializeTest, test_roundtrip_serialize_json,
350+ test_roundtrip_serialize_binary);
365351
366352typedef ::testing::Types<
367353 LDLT, EigenMatrix3d, SerializableType<Eigen::Matrix2i>, EmptyEigenVectorXd,
@@ -374,68 +360,6 @@ typedef ::testing::Types<
374360 FitLinearSerializablePointer, UnfitGaussianProcess, FitGaussianProcess>
375361 ToTest;
376362
377- TYPED_TEST_CASE (PolymorphicSerializeTest, ToTest);
378-
379- TYPED_TEST (PolymorphicSerializeTest, test_roundtrip_serialize_json) {
380- TypeParam model_and_rep;
381- using X = typename TypeParam::RepresentationType;
382- const X original = model_and_rep.create ();
383-
384- // Serialize it
385- std::ostringstream os;
386- {
387- cereal::JSONOutputArchive oarchive (os);
388- oarchive (original);
389- }
390- // Deserialize it.
391- std::istringstream is (os.str ());
392- X deserialized;
393- {
394- cereal::JSONInputArchive iarchive (is);
395- iarchive (deserialized);
396- }
397- // Make sure the original and deserialized representations are
398- // equivalent.
399- EXPECT_TRUE (model_and_rep.are_equal (original, deserialized));
400- // Reserialize the deserialized object
401- std::ostringstream os_again;
402- {
403- cereal::JSONOutputArchive oarchive (os_again);
404- oarchive (deserialized);
405- }
406- // And make sure the serialized strings are the same,
407- EXPECT_EQ (os_again.str (), os.str ());
408- }
409-
410- TYPED_TEST (PolymorphicSerializeTest, test_roundtrip_serialize_binary) {
411- TypeParam model_and_rep;
412- using X = typename TypeParam::RepresentationType;
413- const X original = model_and_rep.create ();
414-
415- // Serialize it
416- std::ostringstream os;
417- {
418- cereal::BinaryOutputArchive oarchive (os);
419- oarchive (original);
420- }
421- // Deserialize it.
422- std::istringstream is (os.str ());
423- X deserialized;
424- {
425- cereal::BinaryInputArchive iarchive (is);
426- iarchive (deserialized);
427- }
428- // Make sure the original and deserialized representations are
429- // equivalent.
430- EXPECT_TRUE (model_and_rep.are_equal (original, deserialized));
431- // Reserialize the deserialized object
432- std::ostringstream os_again;
433- {
434- cereal::BinaryOutputArchive oarchive (os_again);
435- oarchive (deserialized);
436- }
437- // And make sure the serialized strings are the same,
438- EXPECT_EQ (os_again.str (), os.str ());
439- }
363+ INSTANTIATE_TYPED_TEST_CASE_P (Albatross, SerializeTest, ToTest);
440364
441365} // namespace albatross
0 commit comments