diff options
Diffstat (limited to 'core/fxcrt/cfx_retain_ptr_unittest.cpp')
-rw-r--r-- | core/fxcrt/cfx_retain_ptr_unittest.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/core/fxcrt/cfx_retain_ptr_unittest.cpp b/core/fxcrt/cfx_retain_ptr_unittest.cpp index f097b4b28c..fc0309467c 100644 --- a/core/fxcrt/cfx_retain_ptr_unittest.cpp +++ b/core/fxcrt/cfx_retain_ptr_unittest.cpp @@ -5,6 +5,7 @@ #include "core/fxcrt/cfx_retain_ptr.h" #include <utility> +#include <vector> #include "testing/fx_string_testhelpers.h" #include "testing/gtest/include/gtest/gtest.h" @@ -275,3 +276,26 @@ TEST(fxcrt, RetainPtrMakeRetained) { } EXPECT_TRUE(ptr->HasOneRef()); } + +TEST(fxcrt, RetainPtrVectorMove) { + // Proves move ctor is selected by std::vector over copy/delete, this + // may require the ctor to be marked "noexcept". + PseudoRetainable obj; + { + CFX_RetainPtr<PseudoRetainable> ptr(&obj); + std::vector<CFX_RetainPtr<PseudoRetainable>> vec1; + vec1.push_back(std::move(ptr)); + EXPECT_EQ(1, obj.retain_count()); + EXPECT_EQ(0, obj.release_count()); + + std::vector<CFX_RetainPtr<PseudoRetainable>> vec2 = std::move(vec1); + EXPECT_EQ(1, obj.retain_count()); + EXPECT_EQ(0, obj.release_count()); + + vec2.resize(4096); + EXPECT_EQ(1, obj.retain_count()); + EXPECT_EQ(0, obj.release_count()); + } + EXPECT_EQ(1, obj.retain_count()); + EXPECT_EQ(1, obj.release_count()); +} |