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 | |
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, ""); | |
38 static_assert(!DS<Test1<char*, size_t>, int>::value, ""); | |
39 | |
40 struct Test2 { | |
41 int* data; | |
42 size_t size; | |
43 }; | |
44 static_assert(!DS<Test2, int>::value, ""); | |
45 | |
46 struct Test3 { | |
47 int* data(); | |
48 }; | |
49 static_assert(!DS<Test3, int>::value, ""); | |
50 | |
51 class Test4 { | |
52 int* data(); | |
53 size_t size(); | |
54 }; | |
55 static_assert(!DS<Test3, int>::value, ""); | |
ossu
2016/09/05 09:32:27
Surely, this should be DS<Test4, int>::value!
kwiberg-webrtc
2016/09/05 09:40:18
Yes...
ossu
2016/09/05 09:50:44
Ah, so it's supposed to be false because data and
kwiberg-webrtc
2016/09/05 10:11:16
Added comments.
| |
56 | |
57 } // namespace test_has_data_and_size | |
58 | |
23 template <typename T> | 59 template <typename T> |
24 void Call(ArrayView<T>) {} | 60 void Call(ArrayView<T>) {} |
61 | |
25 } // namespace | 62 } // namespace |
26 | 63 |
27 TEST(ArrayViewTest, TestConstructFromPtrAndArray) { | 64 TEST(ArrayViewTest, TestConstructFromPtrAndArray) { |
28 char arr[] = "Arrr!"; | 65 char arr[] = "Arrr!"; |
29 const char carr[] = "Carrr!"; | 66 const char carr[] = "Carrr!"; |
30 Call<const char>(arr); | 67 Call<const char>(arr); |
31 Call<const char>(carr); | 68 Call<const char>(carr); |
32 Call<char>(arr); | 69 Call<char>(arr); |
33 // Call<char>(carr); // Compile error, because can't drop const. | 70 // Call<char>(carr); // Compile error, because can't drop const. |
34 // Call<int>(arr); // Compile error, because incompatible types. | 71 // Call<int>(arr); // Compile error, because incompatible types. |
(...skipping 189 matching lines...) Loading... | |
224 int a[] = {1, 2, 3}; | 261 int a[] = {1, 2, 3}; |
225 int b[] = {1, 2, 3}; | 262 int b[] = {1, 2, 3}; |
226 EXPECT_EQ(ArrayView<int>(a), ArrayView<int>(a)); | 263 EXPECT_EQ(ArrayView<int>(a), ArrayView<int>(a)); |
227 EXPECT_EQ(ArrayView<int>(), ArrayView<int>()); | 264 EXPECT_EQ(ArrayView<int>(), ArrayView<int>()); |
228 EXPECT_NE(ArrayView<int>(a), ArrayView<int>(b)); | 265 EXPECT_NE(ArrayView<int>(a), ArrayView<int>(b)); |
229 EXPECT_NE(ArrayView<int>(a), ArrayView<int>()); | 266 EXPECT_NE(ArrayView<int>(a), ArrayView<int>()); |
230 EXPECT_NE(ArrayView<int>(a), ArrayView<int>(a, 2)); | 267 EXPECT_NE(ArrayView<int>(a), ArrayView<int>(a, 2)); |
231 } | 268 } |
232 | 269 |
233 } // namespace rtc | 270 } // namespace rtc |
OLD | NEW |