summaryrefslogtreecommitdiff
path: root/absl/container
diff options
context:
space:
mode:
Diffstat (limited to 'absl/container')
-rw-r--r--absl/container/inlined_vector_test.cc50
1 files changed, 46 insertions, 4 deletions
diff --git a/absl/container/inlined_vector_test.cc b/absl/container/inlined_vector_test.cc
index 898b40db..808f97cc 100644
--- a/absl/container/inlined_vector_test.cc
+++ b/absl/container/inlined_vector_test.cc
@@ -15,6 +15,7 @@
#include "absl/container/inlined_vector.h"
#include <algorithm>
+#include <cstddef>
#include <forward_list>
#include <iterator>
#include <list>
@@ -51,15 +52,13 @@ using testing::ElementsAre;
using testing::ElementsAreArray;
using testing::Eq;
using testing::Gt;
+using testing::Pointee;
using testing::Pointwise;
using testing::PrintToString;
+using testing::SizeIs;
using IntVec = absl::InlinedVector<int, 8>;
-MATCHER_P(SizeIs, n, "") {
- return testing::ExplainMatchResult(n, arg.size(), result_listener);
-}
-
MATCHER_P(CapacityIs, n, "") {
return testing::ExplainMatchResult(n, arg.capacity(), result_listener);
}
@@ -262,6 +261,49 @@ TEST(IntVec, Hardened) {
#endif
}
+// Move construction of a container of unique pointers should work fine, with no
+// leaks, despite the fact that unique pointers are trivially relocatable but
+// not trivially destructible.
+TEST(UniquePtr, MoveConstruct) {
+ for (size_t size = 0; size < 16; ++size) {
+ SCOPED_TRACE(size);
+
+ absl::InlinedVector<std::unique_ptr<size_t>, 2> a;
+ for (size_t i = 0; i < size; ++i) {
+ a.push_back(std::make_unique<size_t>(i));
+ }
+
+ absl::InlinedVector<std::unique_ptr<size_t>, 2> b(std::move(a));
+
+ ASSERT_THAT(b, SizeIs(size));
+ for (size_t i = 0; i < size; ++i) {
+ ASSERT_THAT(b[i], Pointee(i));
+ }
+ }
+}
+
+// Move assignment of a container of unique pointers should work fine, with no
+// leaks, despite the fact that unique pointers are trivially relocatable but
+// not trivially destructible.
+TEST(UniquePtr, MoveAssign) {
+ for (size_t size = 0; size < 16; ++size) {
+ SCOPED_TRACE(size);
+
+ absl::InlinedVector<std::unique_ptr<size_t>, 2> a;
+ for (size_t i = 0; i < size; ++i) {
+ a.push_back(std::make_unique<size_t>(i));
+ }
+
+ absl::InlinedVector<std::unique_ptr<size_t>, 2> b;
+ b = std::move(a);
+
+ ASSERT_THAT(b, SizeIs(size));
+ for (size_t i = 0; i < size; ++i) {
+ ASSERT_THAT(b[i], Pointee(i));
+ }
+ }
+}
+
// At the end of this test loop, the elements between [erase_begin, erase_end)
// should have reference counts == 0, and all others elements should have
// reference counts == 1.