test_observer_ptr.cpp 746 B

123456789101112131415161718192021222324252627
  1. // This file is part of OpenCV project.
  2. // It is subject to the license terms in the LICENSE file found in the top-level directory
  3. // of this distribution and at http://opencv.org/license.html.
  4. #include "test_precomp.hpp"
  5. #include "../src/util/observer_ptr.hpp"
  6. namespace opencv_test { namespace {
  7. /**
  8. * Verifies that assigning `nullptr` and a nonzero value to a `cvv::util::ObserverPtr<Int>`
  9. * (from /src/util/observer_ptr.hpp) work and that `isNull()` and `getPtr()` return the correct result.
  10. */
  11. using cvv::util::ObserverPtr;
  12. TEST(ObserverPtrTest, ConstructionAssignment)
  13. {
  14. ObserverPtr<int> ptr = nullptr;
  15. EXPECT_TRUE(ptr.isNull());
  16. int x = 3;
  17. ptr = x;
  18. EXPECT_FALSE(ptr.isNull());
  19. EXPECT_EQ(&x, ptr.getPtr());
  20. }
  21. }} // namespace