Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(276)

Side by Side Diff: webrtc/base/bind_unittest.cc

Issue 2719683002: Rewrite rtc::Bind using variadic templates. (Closed)
Patch Set: Mention where sequence_generator comes from in a comment. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/base/bind.h.pump ('k') | webrtc/base/template_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 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 <type_traits>
12
11 #include "webrtc/base/bind.h" 13 #include "webrtc/base/bind.h"
12 #include "webrtc/base/gunit.h" 14 #include "webrtc/base/gunit.h"
13 15
14 #include "webrtc/base/refcount.h" 16 #include "webrtc/base/refcount.h"
15 17
16 namespace rtc { 18 namespace rtc {
17 19
18 namespace { 20 namespace {
19 21
20 struct LifeTimeCheck; 22 struct LifeTimeCheck;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 }; 66 };
65 67
66 int Return42() { return 42; } 68 int Return42() { return 42; }
67 int Negate(int a) { return -a; } 69 int Negate(int a) { return -a; }
68 int Multiply(int a, int b) { return a * b; } 70 int Multiply(int a, int b) { return a * b; }
69 71
70 } // namespace 72 } // namespace
71 73
72 // Try to catch any problem with scoped_refptr type deduction in rtc::Bind at 74 // Try to catch any problem with scoped_refptr type deduction in rtc::Bind at
73 // compile time. 75 // compile time.
74 static_assert(
75 is_same<
76 rtc::remove_reference<const scoped_refptr<RefCountInterface>&>::type,
77 const scoped_refptr<RefCountInterface>>::value,
78 "const scoped_refptr& should be captured by value");
79
80 static_assert(is_same<rtc::remove_reference<const scoped_refptr<F>&>::type,
81 const scoped_refptr<F>>::value,
82 "const scoped_refptr& should be captured by value");
83
84 static_assert(
85 is_same<rtc::remove_reference<const int&>::type, const int>::value,
86 "const int& should be captured as const int");
87
88 static_assert(is_same<rtc::remove_reference<const F&>::type, const F>::value,
89 "const F& should be captured as const F");
90
91 static_assert(is_same<rtc::remove_reference<F&>::type, F>::value,
92 "F& should be captured as F");
93
94 #define EXPECT_IS_CAPTURED_AS_PTR(T) \ 76 #define EXPECT_IS_CAPTURED_AS_PTR(T) \
95 static_assert(is_same<detail::PointerType<T>::type, T*>::value, \ 77 static_assert(is_same<detail::PointerType<T>::type, T*>::value, \
96 "PointerType") 78 "PointerType")
97 #define EXPECT_IS_CAPTURED_AS_SCOPED_REFPTR(T) \ 79 #define EXPECT_IS_CAPTURED_AS_SCOPED_REFPTR(T) \
98 static_assert( \ 80 static_assert( \
99 is_same<detail::PointerType<T>::type, scoped_refptr<T>>::value, \ 81 is_same<detail::PointerType<T>::type, scoped_refptr<T>>::value, \
100 "PointerType") 82 "PointerType")
101 83
102 EXPECT_IS_CAPTURED_AS_PTR(void); 84 EXPECT_IS_CAPTURED_AS_PTR(void);
103 EXPECT_IS_CAPTURED_AS_PTR(int); 85 EXPECT_IS_CAPTURED_AS_PTR(int);
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 // modified to a non-reference capture. 211 // modified to a non-reference capture.
230 TEST(BindTest, RefArgument) { 212 TEST(BindTest, RefArgument) {
231 const int x = 42; 213 const int x = 42;
232 EXPECT_EQ(&x, Ref(x)); 214 EXPECT_EQ(&x, Ref(x));
233 // Bind() should make a copy of |x|, i.e. the pointers should be different. 215 // Bind() should make a copy of |x|, i.e. the pointers should be different.
234 auto functor = Bind(&Ref, x); 216 auto functor = Bind(&Ref, x);
235 EXPECT_NE(&x, functor()); 217 EXPECT_NE(&x, functor());
236 } 218 }
237 219
238 } // namespace rtc 220 } // namespace rtc
OLDNEW
« no previous file with comments | « webrtc/base/bind.h.pump ('k') | webrtc/base/template_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698