const_propogating_ptr_test.cxx 970 B

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