// // not_null.t.h // pointers // // Created by Sam Jaffe on 12/2/16. // #include "pointer/not_null.hpp" #include #include "test_stubs.h" TEST(NonNullPtrTest, ThrowsIfNullptrIsSnuckIn) { EXPECT_THROW(not_null>(std::shared_ptr(nullptr)), null_pointer_exception); } TEST(NonNullPtrTest, ContainsInnerPtrForEquality) { std::shared_ptr i{new int}; not_null> n{i}; EXPECT_THAT(n.get(), i.get()); EXPECT_THAT(*n, *i); } TEST(NonNullPtrTest, CanModifyInnerValue) { std::shared_ptr i{new int(5)}; not_null> n{i}; EXPECT_THAT(*n, 5); *n = 4; EXPECT_THAT(*i, 4); } TEST(NonNullPtrTest, DoesNotDeleteRawPtr) { bool has_delete{false}; destructor_sentinal * test_struct = new destructor_sentinal{has_delete}; not_null{test_struct}; EXPECT_FALSE(has_delete); delete test_struct; EXPECT_TRUE(has_delete); }