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 | 19 |
20 namespace rtc { | 20 namespace rtc { |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 namespace test_has_data_and_size { | |
25 | |
26 template <typename C, typename T> | |
27 using DS = internal::HasDataAndSize<C, T>; | |
28 | |
29 template <typename DR, typename SR> | |
30 struct Test1 { | |
31 DR data(); | |
32 SR size(); | |
33 }; | |
34 static_assert(DS<Test1<int*, int>, int>::value, ""); | |
35 static_assert(DS<Test1<int*, int>, const int>::value, ""); | |
36 static_assert(DS<Test1<const int*, int>, const int>::value, ""); | |
37 static_assert(!DS<Test1<const int*, int>, int>::value, ""); // Wrong const. | |
38 static_assert(!DS<Test1<char*, size_t>, int>::value, ""); // Wrong ptr type. | |
39 | |
40 struct Test2 { | |
41 int* data; | |
42 size_t size; | |
43 }; | |
44 static_assert(!DS<Test2, int>::value, ""); // Because they aren't methods. | |
45 | |
46 struct Test3 { | |
47 int* data(); | |
48 }; | |
49 static_assert(!DS<Test3, int>::value, ""); // Because .size() is missing. | |
50 | |
51 class Test4 { | |
52 int* data(); | |
53 size_t size(); | |
54 }; | |
55 static_assert(!DS<Test4, int>::value, ""); // Because methods are private. | |
56 | |
57 } // namespace test_has_data_and_size | |
58 | |
59 template <typename T> | 24 template <typename T> |
60 void Call(ArrayView<T>) {} | 25 void Call(ArrayView<T>) {} |
61 | 26 |
62 } // namespace | 27 } // namespace |
63 | 28 |
64 TEST(ArrayViewTest, TestConstructFromPtrAndArray) { | 29 TEST(ArrayViewTest, TestConstructFromPtrAndArray) { |
65 char arr[] = "Arrr!"; | 30 char arr[] = "Arrr!"; |
66 const char carr[] = "Carrr!"; | 31 const char carr[] = "Carrr!"; |
67 Call<const char>(arr); | 32 Call<const char>(arr); |
68 Call<const char>(carr); | 33 Call<const char>(carr); |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 int a[] = {1, 2, 3}; | 226 int a[] = {1, 2, 3}; |
262 int b[] = {1, 2, 3}; | 227 int b[] = {1, 2, 3}; |
263 EXPECT_EQ(ArrayView<int>(a), ArrayView<int>(a)); | 228 EXPECT_EQ(ArrayView<int>(a), ArrayView<int>(a)); |
264 EXPECT_EQ(ArrayView<int>(), ArrayView<int>()); | 229 EXPECT_EQ(ArrayView<int>(), ArrayView<int>()); |
265 EXPECT_NE(ArrayView<int>(a), ArrayView<int>(b)); | 230 EXPECT_NE(ArrayView<int>(a), ArrayView<int>(b)); |
266 EXPECT_NE(ArrayView<int>(a), ArrayView<int>()); | 231 EXPECT_NE(ArrayView<int>(a), ArrayView<int>()); |
267 EXPECT_NE(ArrayView<int>(a), ArrayView<int>(a, 2)); | 232 EXPECT_NE(ArrayView<int>(a), ArrayView<int>(a, 2)); |
268 } | 233 } |
269 | 234 |
270 } // namespace rtc | 235 } // namespace rtc |
OLD | NEW |