From 6365d1744b405cec48317e9597a80533acab0798 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Tue, 2 Jan 2018 08:53:02 -0800 Subject: Changes imported from Abseil "staging" branch: - d1a8e5ddbf9f96a4ca020260b21e03820c5ff966 Remove references to the non-existing StringPrintf API to... by Abseil Team - 64a422bc1620b29247a81fab2b08a7f23dfc1461 Add a copy and move constructor to FixedArray. This does... by Jon Cohen GitOrigin-RevId: d1a8e5ddbf9f96a4ca020260b21e03820c5ff966 Change-Id: I4388bdf1260702f2847307abbac4bf265e8cf90f --- absl/container/fixed_array_test.cc | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'absl/container/fixed_array_test.cc') diff --git a/absl/container/fixed_array_test.cc b/absl/container/fixed_array_test.cc index 9e88eab0..b6782f51 100644 --- a/absl/container/fixed_array_test.cc +++ b/absl/container/fixed_array_test.cc @@ -27,6 +27,8 @@ #include "absl/base/internal/exception_testing.h" #include "absl/memory/memory.h" +using ::testing::ElementsAreArray; + namespace { // Helper routine to determine if a absl::FixedArray used stack allocation. @@ -89,6 +91,41 @@ class ThreeInts { int ThreeInts::counter = 0; +TEST(FixedArrayTest, CopyCtor) { + absl::FixedArray on_stack(5); + std::iota(on_stack.begin(), on_stack.end(), 0); + absl::FixedArray stack_copy = on_stack; + EXPECT_THAT(stack_copy, ElementsAreArray(on_stack)); + EXPECT_TRUE(IsOnStack(stack_copy)); + + absl::FixedArray allocated(15); + std::iota(allocated.begin(), allocated.end(), 0); + absl::FixedArray alloced_copy = allocated; + EXPECT_THAT(alloced_copy, ElementsAreArray(allocated)); + EXPECT_FALSE(IsOnStack(alloced_copy)); +} + +TEST(FixedArrayTest, MoveCtor) { + absl::FixedArray, 10> on_stack(5); + for (int i = 0; i < 5; ++i) { + on_stack[i] = absl::make_unique(i); + } + + absl::FixedArray, 10> stack_copy = std::move(on_stack); + for (int i = 0; i < 5; ++i) EXPECT_EQ(*(stack_copy[i]), i); + EXPECT_EQ(stack_copy.size(), on_stack.size()); + + absl::FixedArray, 10> allocated(15); + for (int i = 0; i < 15; ++i) { + allocated[i] = absl::make_unique(i); + } + + absl::FixedArray, 10> alloced_copy = + std::move(allocated); + for (int i = 0; i < 15; ++i) EXPECT_EQ(*(alloced_copy[i]), i); + EXPECT_EQ(allocated.size(), alloced_copy.size()); +} + TEST(FixedArrayTest, SmallObjects) { // Small object arrays { -- cgit v1.2.3