From c62e4c5dc7526ab6d4914c467d2ec24cce21b134 Mon Sep 17 00:00:00 2001 From: Karl Wiberg Date: Thu, 27 Feb 2020 22:23:06 +0100 Subject: [PATCH] Test copying of variable-sized ArrayView rvalues MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, only lvalues were tested. Bug: webrtc:11389 Change-Id: I4067c8bfc40c52de0622a6f58a5c7b7805b0fa7b Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/169346 Reviewed-by: Per Ã…hgren Commit-Queue: Karl Wiberg Cr-Commit-Position: refs/heads/master@{#30641} --- api/array_view_unittest.cc | 42 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/api/array_view_unittest.cc b/api/array_view_unittest.cc index 6fdd516544..06394047b0 100644 --- a/api/array_view_unittest.cc +++ b/api/array_view_unittest.cc @@ -82,7 +82,7 @@ TEST(ArrayViewTest, TestConstructFromPtrAndArray) { // ArrayView n(arr + 2, 2); } -TEST(ArrayViewTest, TestCopyConstructorVariable) { +TEST(ArrayViewTest, TestCopyConstructorVariableLvalue) { char arr[] = "Arrr!"; ArrayView x = arr; EXPECT_EQ(6u, x.size()); @@ -99,6 +99,23 @@ TEST(ArrayViewTest, TestCopyConstructorVariable) { // ArrayView v = z; // Compile error, because can't drop const. } +TEST(ArrayViewTest, TestCopyConstructorVariableRvalue) { + char arr[] = "Arrr!"; + ArrayView x = arr; + EXPECT_EQ(6u, x.size()); + EXPECT_EQ(arr, x.data()); + ArrayView y = std::move(x); // Copy non-const -> non-const. + EXPECT_EQ(6u, y.size()); + EXPECT_EQ(arr, y.data()); + ArrayView z = std::move(x); // Copy non-const -> const. + EXPECT_EQ(6u, z.size()); + EXPECT_EQ(arr, z.data()); + ArrayView w = std::move(z); // Copy const -> const. + EXPECT_EQ(6u, w.size()); + EXPECT_EQ(arr, w.data()); + // ArrayView v = std::move(z); // Error, because can't drop const. +} + TEST(ArrayViewTest, TestCopyConstructorFixed) { char arr[] = "Arrr!"; ArrayView x = arr; @@ -130,7 +147,7 @@ TEST(ArrayViewTest, TestCopyConstructorFixed) { // ArrayView vv = z; // Compile error, because can't drop const. } -TEST(ArrayViewTest, TestCopyAssignmentVariable) { +TEST(ArrayViewTest, TestCopyAssignmentVariableLvalue) { char arr[] = "Arrr!"; ArrayView x(arr); EXPECT_EQ(6u, x.size()); @@ -151,6 +168,27 @@ TEST(ArrayViewTest, TestCopyAssignmentVariable) { // v = z; // Compile error, because can't drop const. } +TEST(ArrayViewTest, TestCopyAssignmentVariableRvalue) { + char arr[] = "Arrr!"; + ArrayView x(arr); + EXPECT_EQ(6u, x.size()); + EXPECT_EQ(arr, x.data()); + ArrayView y; + y = std::move(x); // Copy non-const -> non-const. + EXPECT_EQ(6u, y.size()); + EXPECT_EQ(arr, y.data()); + ArrayView z; + z = std::move(x); // Copy non-const -> const. + EXPECT_EQ(6u, z.size()); + EXPECT_EQ(arr, z.data()); + ArrayView w; + w = std::move(z); // Copy const -> const. + EXPECT_EQ(6u, w.size()); + EXPECT_EQ(arr, w.data()); + // ArrayView v; + // v = std::move(z); // Compile error, because can't drop const. +} + TEST(ArrayViewTest, TestCopyAssignmentFixed) { char arr[] = "Arrr!"; char init[] = "Init!";