const_propogating_ptr_test.cxx 998 B

12345678910111213141516171819202122232425262728293031323334353637
  1. //
  2. // const_propogating_ptr.t.h
  3. // pointers
  4. //
  5. // Created by Sam Jaffe on 1/5/17.
  6. //
  7. #include "pointers/const_propogating_ptr.hpp"
  8. #include <memory>
  9. #include <gmock/gmock.h>
  10. #include "test_stubs.h"
  11. using namespace pointers;
  12. TEST(ConstPropogatingPtrTest, NonConstCPPCallsNonConstMethods) {
  13. std::shared_ptr<const_tracking_stub> p{new const_tracking_stub};
  14. const_propogating_ptr<std::shared_ptr<const_tracking_stub>> cp{p};
  15. EXPECT_FALSE(cp->is_const());
  16. }
  17. TEST(ConstPropogatingPtrTest, ConstCPPCallsConstMethods) {
  18. std::shared_ptr<const_tracking_stub> p{new const_tracking_stub};
  19. const_propogating_ptr<std::shared_ptr<const_tracking_stub>> const cp{p};
  20. EXPECT_TRUE(cp->is_const());
  21. }
  22. TEST(ConstPropogatingPtrTest, DoesNotDeleteRawPtr) {
  23. bool has_delete{false};
  24. destructor_sentinal * test_struct = new destructor_sentinal{has_delete};
  25. const_propogating_ptr<destructor_sentinal *>{test_struct};
  26. EXPECT_FALSE(has_delete);
  27. delete test_struct;
  28. EXPECT_TRUE(has_delete);
  29. }