// // const_ptr.t.h // pointers // // Created by Sam Jaffe on 1/5/17. // #include "pointers/const_propogating_ptr.hpp" #include "pointers/const_ptr.hpp" #include #include "test_stubs.h" using namespace pointers; TEST(ConstPtrTest, NonConstCPCallConstMethods) { std::shared_ptr p{new const_tracking_stub}; const_ptr> cp{p}; EXPECT_TRUE(cp->is_const()); } TEST(ConstPtrTest, ConstCPCallConstMethods) { std::shared_ptr p{new const_tracking_stub}; const_ptr> const cp{p}; EXPECT_TRUE(cp->is_const()); } TEST(ConstPtrTest, CanConstructFromConstPropogatingPtr) { std::shared_ptr p{new const_tracking_stub}; const_propogating_ptr> cpp{p}; const_ptr> cp{p}; EXPECT_THAT(cp.get(), cpp.get()); EXPECT_FALSE(cpp->is_const()); EXPECT_TRUE(cp->is_const()); } TEST(ConstPtrTest, DoesNotDeleteRawPtr) { bool has_delete{false}; destructor_sentinal * test_struct = new destructor_sentinal{has_delete}; const_ptr{test_struct}; EXPECT_FALSE(has_delete); delete test_struct; EXPECT_TRUE(has_delete); }