add unit tests for std::shared_ptr<const T>

This commit is contained in:
Christoph Weiss 2017-08-16 18:12:21 +02:00
parent 015ed43eed
commit 673add1212

View File

@ -38,6 +38,7 @@ void test_memory()
{
std::shared_ptr<int> o_xptr1 = std::make_shared<int>(random_value<int>(gen));
std::shared_ptr<int> o_xptr2 = o_xptr1;
std::shared_ptr<const int> o_xptr3 = o_xptr1;
std::shared_ptr<int> o_yptr1 = std::make_shared<int>(random_value<int>(gen));
std::shared_ptr<int> o_yptr2 = o_yptr1;
std::shared_ptr<int> o_nullptr1;
@ -47,13 +48,14 @@ void test_memory()
{
OArchive oar(os);
oar( o_xptr1, o_xptr2 );
oar( o_xptr1, o_xptr2, o_xptr3 );
oar( o_yptr1, o_yptr2 );
oar( o_nullptr1, o_nullptr2 );
}
std::shared_ptr<int> i_xptr1;
std::shared_ptr<int> i_xptr2;
std::shared_ptr<const int> i_xptr3;
std::shared_ptr<int> i_yptr1;
std::shared_ptr<int> i_yptr2;
std::shared_ptr<int> i_nullptr1;
@ -63,20 +65,27 @@ void test_memory()
{
IArchive iar(is);
iar( i_xptr1, i_xptr2);
iar( i_xptr1, i_xptr2, i_xptr3 );
iar( i_yptr1, i_yptr2);
iar( i_nullptr1, i_nullptr2 );
}
CHECK_EQ(o_xptr1.get(), o_xptr2.get());
CHECK_EQ(o_xptr1.get(), o_xptr3.get());
CHECK_EQ(i_xptr1.get(), i_xptr2.get());
CHECK_EQ(i_xptr1.get(), i_xptr3.get());
CHECK_EQ(*i_xptr1, *i_xptr2);
CHECK_EQ(*i_xptr1, *i_xptr3);
CHECK_EQ(o_yptr1.get(), o_yptr2.get());
CHECK_EQ(i_yptr1.get(), i_yptr2.get());
CHECK_EQ(*i_yptr1, *i_yptr2);
CHECK_UNARY_FALSE(i_nullptr1);
CHECK_UNARY_FALSE(i_nullptr2);
CHECK_EQ(*i_xptr1, *o_xptr1);
CHECK_EQ(*i_xptr2, *o_xptr2);
CHECK_EQ(*i_xptr3, *o_xptr3);
}
}
@ -88,7 +97,7 @@ class TestClass
private:
friend class cereal::access;
TestClass() { };
TestClass() = default;
template<class Archive>
void serialize(Archive & ar) { ar(x); }