| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2015 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include <algorithm> | 11 #include <algorithm> |
| 12 #include <string> | 12 #include <string> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "webrtc/base/array_view.h" | 15 #include "webrtc/base/array_view.h" |
| 16 #include "webrtc/base/buffer.h" | 16 #include "webrtc/base/buffer.h" |
| 17 #include "webrtc/base/checks.h" | 17 #include "webrtc/base/checks.h" |
| 18 #include "webrtc/base/gunit.h" | 18 #include "webrtc/base/gunit.h" |
| 19 #include "webrtc/test/gmock.h" |
| 19 | 20 |
| 20 namespace rtc { | 21 namespace rtc { |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 25 using ::testing::ElementsAre; |
| 26 using ::testing::IsEmpty; |
| 27 |
| 24 template <typename T> | 28 template <typename T> |
| 25 void Call(ArrayView<T>) {} | 29 void Call(ArrayView<T>) {} |
| 26 | 30 |
| 27 } // namespace | 31 } // namespace |
| 28 | 32 |
| 29 TEST(ArrayViewTest, TestConstructFromPtrAndArray) { | 33 TEST(ArrayViewTest, TestConstructFromPtrAndArray) { |
| 30 char arr[] = "Arrr!"; | 34 char arr[] = "Arrr!"; |
| 31 const char carr[] = "Carrr!"; | 35 const char carr[] = "Carrr!"; |
| 32 Call<const char>(arr); | 36 Call<const char>(arr); |
| 33 Call<const char>(carr); | 37 Call<const char>(carr); |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 TEST(ArrayViewTest, TestCompare) { | 229 TEST(ArrayViewTest, TestCompare) { |
| 226 int a[] = {1, 2, 3}; | 230 int a[] = {1, 2, 3}; |
| 227 int b[] = {1, 2, 3}; | 231 int b[] = {1, 2, 3}; |
| 228 EXPECT_EQ(ArrayView<int>(a), ArrayView<int>(a)); | 232 EXPECT_EQ(ArrayView<int>(a), ArrayView<int>(a)); |
| 229 EXPECT_EQ(ArrayView<int>(), ArrayView<int>()); | 233 EXPECT_EQ(ArrayView<int>(), ArrayView<int>()); |
| 230 EXPECT_NE(ArrayView<int>(a), ArrayView<int>(b)); | 234 EXPECT_NE(ArrayView<int>(a), ArrayView<int>(b)); |
| 231 EXPECT_NE(ArrayView<int>(a), ArrayView<int>()); | 235 EXPECT_NE(ArrayView<int>(a), ArrayView<int>()); |
| 232 EXPECT_NE(ArrayView<int>(a), ArrayView<int>(a, 2)); | 236 EXPECT_NE(ArrayView<int>(a), ArrayView<int>(a, 2)); |
| 233 } | 237 } |
| 234 | 238 |
| 239 TEST(ArrayViewTest, TestSubView) { |
| 240 int a[] = {1, 2, 3}; |
| 241 ArrayView<int> av(a); |
| 242 |
| 243 EXPECT_EQ(av.subview(0), av); |
| 244 |
| 245 EXPECT_THAT(av.subview(1), ElementsAre(2, 3)); |
| 246 EXPECT_THAT(av.subview(2), ElementsAre(3)); |
| 247 EXPECT_THAT(av.subview(3), IsEmpty()); |
| 248 EXPECT_THAT(av.subview(4), IsEmpty()); |
| 249 |
| 250 EXPECT_THAT(av.subview(1, 0), IsEmpty()); |
| 251 EXPECT_THAT(av.subview(1, 1), ElementsAre(2)); |
| 252 EXPECT_THAT(av.subview(1, 2), ElementsAre(2, 3)); |
| 253 EXPECT_THAT(av.subview(1, 3), ElementsAre(2, 3)); |
| 254 } |
| 255 |
| 235 } // namespace rtc | 256 } // namespace rtc |
| OLD | NEW |