Test copying of variable-sized ArrayView rvalues

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 <peah@webrtc.org>
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#30641}
diff --git a/api/array_view_unittest.cc b/api/array_view_unittest.cc
index 6fdd516..0639404 100644
--- a/api/array_view_unittest.cc
+++ b/api/array_view_unittest.cc
@@ -82,7 +82,7 @@
   // ArrayView<float> n(arr + 2, 2);
 }
 
-TEST(ArrayViewTest, TestCopyConstructorVariable) {
+TEST(ArrayViewTest, TestCopyConstructorVariableLvalue) {
   char arr[] = "Arrr!";
   ArrayView<char> x = arr;
   EXPECT_EQ(6u, x.size());
@@ -99,6 +99,23 @@
   // ArrayView<char> v = z;  // Compile error, because can't drop const.
 }
 
+TEST(ArrayViewTest, TestCopyConstructorVariableRvalue) {
+  char arr[] = "Arrr!";
+  ArrayView<char> x = arr;
+  EXPECT_EQ(6u, x.size());
+  EXPECT_EQ(arr, x.data());
+  ArrayView<char> y = std::move(x);  // Copy non-const -> non-const.
+  EXPECT_EQ(6u, y.size());
+  EXPECT_EQ(arr, y.data());
+  ArrayView<const char> z = std::move(x);  // Copy non-const -> const.
+  EXPECT_EQ(6u, z.size());
+  EXPECT_EQ(arr, z.data());
+  ArrayView<const char> w = std::move(z);  // Copy const -> const.
+  EXPECT_EQ(6u, w.size());
+  EXPECT_EQ(arr, w.data());
+  // ArrayView<char> v = std::move(z);  // Error, because can't drop const.
+}
+
 TEST(ArrayViewTest, TestCopyConstructorFixed) {
   char arr[] = "Arrr!";
   ArrayView<char, 6> x = arr;
@@ -130,7 +147,7 @@
   // ArrayView<char> vv = z;  // Compile error, because can't drop const.
 }
 
-TEST(ArrayViewTest, TestCopyAssignmentVariable) {
+TEST(ArrayViewTest, TestCopyAssignmentVariableLvalue) {
   char arr[] = "Arrr!";
   ArrayView<char> x(arr);
   EXPECT_EQ(6u, x.size());
@@ -151,6 +168,27 @@
   // v = z;  // Compile error, because can't drop const.
 }
 
+TEST(ArrayViewTest, TestCopyAssignmentVariableRvalue) {
+  char arr[] = "Arrr!";
+  ArrayView<char> x(arr);
+  EXPECT_EQ(6u, x.size());
+  EXPECT_EQ(arr, x.data());
+  ArrayView<char> y;
+  y = std::move(x);  // Copy non-const -> non-const.
+  EXPECT_EQ(6u, y.size());
+  EXPECT_EQ(arr, y.data());
+  ArrayView<const char> z;
+  z = std::move(x);  // Copy non-const -> const.
+  EXPECT_EQ(6u, z.size());
+  EXPECT_EQ(arr, z.data());
+  ArrayView<const char> w;
+  w = std::move(z);  // Copy const -> const.
+  EXPECT_EQ(6u, w.size());
+  EXPECT_EQ(arr, w.data());
+  // ArrayView<char> v;
+  // v = std::move(z);  // Compile error, because can't drop const.
+}
+
 TEST(ArrayViewTest, TestCopyAssignmentFixed) {
   char arr[] = "Arrr!";
   char init[] = "Init!";