summaryrefslogtreecommitdiff
path: root/core/fxcrt/cfx_retain_ptr_unittest.cpp
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2017-03-28 14:09:43 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-03-28 21:28:39 +0000
commit3bb57514867a2bd10ba535e0b06de566a58d8085 (patch)
tree8c3019986ee23a0bec05955f861cee3b73b3770d /core/fxcrt/cfx_retain_ptr_unittest.cpp
parent022ded02d2c23a8d043bbcb3d3f37dab12636759 (diff)
downloadpdfium-3bb57514867a2bd10ba535e0b06de566a58d8085.tar.xz
Ensure that CFX_RetainPtr move ctor is used by std::vector.
Add a test for one of our types that fails unless this is the case. Mark all our other move ctors as |noexcept|. Change-Id: Ib106f219183d5abf94504af420a43c94b8f40e22 Reviewed-on: https://pdfium-review.googlesource.com/3251 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core/fxcrt/cfx_retain_ptr_unittest.cpp')
-rw-r--r--core/fxcrt/cfx_retain_ptr_unittest.cpp24
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());
+}