const_ptr_test.cxx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //
  2. // const_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 "pointers/const_ptr.hpp"
  9. #include <gmock/gmock.h>
  10. #include "test_stubs.h"
  11. using namespace pointers;
  12. TEST(ConstPtrTest, NonConstCPCallConstMethods) {
  13. std::shared_ptr<const_tracking_stub> p{new const_tracking_stub};
  14. const_ptr<std::shared_ptr<const_tracking_stub>> cp{p};
  15. EXPECT_TRUE(cp->is_const());
  16. }
  17. TEST(ConstPtrTest, ConstCPCallConstMethods) {
  18. std::shared_ptr<const_tracking_stub> p{new const_tracking_stub};
  19. const_ptr<std::shared_ptr<const_tracking_stub>> const cp{p};
  20. EXPECT_TRUE(cp->is_const());
  21. }
  22. TEST(ConstPtrTest, CanConstructFromConstPropogatingPtr) {
  23. std::shared_ptr<const_tracking_stub> p{new const_tracking_stub};
  24. const_propogating_ptr<std::shared_ptr<const_tracking_stub>> cpp{p};
  25. const_ptr<std::shared_ptr<const_tracking_stub>> cp{p};
  26. EXPECT_THAT(cp.get(), cpp.get());
  27. EXPECT_FALSE(cpp->is_const());
  28. EXPECT_TRUE(cp->is_const());
  29. }
  30. TEST(ConstPtrTest, DoesNotDeleteRawPtr) {
  31. bool has_delete{false};
  32. destructor_sentinal * test_struct = new destructor_sentinal{has_delete};
  33. const_ptr<destructor_sentinal *>{test_struct};
  34. EXPECT_FALSE(has_delete);
  35. delete test_struct;
  36. EXPECT_TRUE(has_delete);
  37. }