henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 15:54:43 | [diff] [blame] | 2 | * Copyright 2013 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 15:54:43 | [diff] [blame] | 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 9 | */ |
| 10 | |
Markus Handell | a1b8201 | 2021-05-26 16:56:30 | [diff] [blame] | 11 | #include "pc/proxy.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 12 | |
kwiberg | d1fe281 | 2016-04-27 13:47:29 | [diff] [blame] | 13 | #include <memory> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 14 | #include <string> |
| 15 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 16 | #include "rtc_base/gunit.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 17 | #include "rtc_base/ref_count.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 18 | #include "test/gmock.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 19 | |
| 20 | using ::testing::_; |
| 21 | using ::testing::DoAll; |
| 22 | using ::testing::Exactly; |
| 23 | using ::testing::InvokeWithoutArgs; |
| 24 | using ::testing::Return; |
| 25 | |
| 26 | namespace webrtc { |
| 27 | |
| 28 | // Interface used for testing here. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 29 | class FakeInterface : public rtc::RefCountInterface { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 30 | public: |
| 31 | virtual void VoidMethod0() = 0; |
| 32 | virtual std::string Method0() = 0; |
| 33 | virtual std::string ConstMethod0() const = 0; |
| 34 | virtual std::string Method1(std::string s) = 0; |
| 35 | virtual std::string ConstMethod1(std::string s) const = 0; |
| 36 | virtual std::string Method2(std::string s1, std::string s2) = 0; |
| 37 | |
| 38 | protected: |
deadbeef | d99a200 | 2017-01-18 16:55:23 | [diff] [blame] | 39 | virtual ~FakeInterface() {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 40 | }; |
| 41 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 42 | // Implementation of the test interface. |
| 43 | class Fake : public FakeInterface { |
| 44 | public: |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 45 | static rtc::scoped_refptr<Fake> Create() { |
Tommi | 87f7090 | 2021-04-27 12:43:08 | [diff] [blame] | 46 | return rtc::make_ref_counted<Fake>(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 47 | } |
deadbeef | d99a200 | 2017-01-18 16:55:23 | [diff] [blame] | 48 | // Used to verify destructor is called on the correct thread. |
Danil Chapovalov | 3a35312 | 2020-05-15 09:16:53 | [diff] [blame] | 49 | MOCK_METHOD(void, Destroy, ()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 50 | |
Danil Chapovalov | 3a35312 | 2020-05-15 09:16:53 | [diff] [blame] | 51 | MOCK_METHOD(void, VoidMethod0, (), (override)); |
| 52 | MOCK_METHOD(std::string, Method0, (), (override)); |
| 53 | MOCK_METHOD(std::string, ConstMethod0, (), (const, override)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 54 | |
Danil Chapovalov | 3a35312 | 2020-05-15 09:16:53 | [diff] [blame] | 55 | MOCK_METHOD(std::string, Method1, (std::string), (override)); |
| 56 | MOCK_METHOD(std::string, ConstMethod1, (std::string), (const, override)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 57 | |
Danil Chapovalov | 3a35312 | 2020-05-15 09:16:53 | [diff] [blame] | 58 | MOCK_METHOD(std::string, Method2, (std::string, std::string), (override)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 59 | |
| 60 | protected: |
| 61 | Fake() {} |
deadbeef | d99a200 | 2017-01-18 16:55:23 | [diff] [blame] | 62 | ~Fake() { Destroy(); } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 63 | }; |
| 64 | |
nisse | 72c8d2b | 2016-04-15 10:49:07 | [diff] [blame] | 65 | // Proxies for the test interface. |
| 66 | BEGIN_PROXY_MAP(Fake) |
Mirko Bonadei | 9d9b8de | 2021-02-26 08:51:26 | [diff] [blame] | 67 | PROXY_SECONDARY_THREAD_DESTRUCTOR() |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 68 | PROXY_METHOD0(void, VoidMethod0) |
| 69 | PROXY_METHOD0(std::string, Method0) |
| 70 | PROXY_CONSTMETHOD0(std::string, ConstMethod0) |
Mirko Bonadei | 9d9b8de | 2021-02-26 08:51:26 | [diff] [blame] | 71 | PROXY_SECONDARY_METHOD1(std::string, Method1, std::string) |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 72 | PROXY_CONSTMETHOD1(std::string, ConstMethod1, std::string) |
Mirko Bonadei | 9d9b8de | 2021-02-26 08:51:26 | [diff] [blame] | 73 | PROXY_SECONDARY_METHOD2(std::string, Method2, std::string, std::string) |
Markus Handell | 3d46d0b | 2021-05-27 19:42:57 | [diff] [blame] | 74 | END_PROXY_MAP(Fake) |
nisse | 72c8d2b | 2016-04-15 10:49:07 | [diff] [blame] | 75 | |
| 76 | // Preprocessor hack to get a proxy class a name different than FakeProxy. |
| 77 | #define FakeProxy FakeSignalingProxy |
deadbeef | a601f5c | 2016-06-06 21:27:39 | [diff] [blame] | 78 | #define FakeProxyWithInternal FakeSignalingProxyWithInternal |
Mirko Bonadei | 9d9b8de | 2021-02-26 08:51:26 | [diff] [blame] | 79 | BEGIN_PRIMARY_PROXY_MAP(Fake) |
| 80 | PROXY_PRIMARY_THREAD_DESTRUCTOR() |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 81 | PROXY_METHOD0(void, VoidMethod0) |
| 82 | PROXY_METHOD0(std::string, Method0) |
| 83 | PROXY_CONSTMETHOD0(std::string, ConstMethod0) |
| 84 | PROXY_METHOD1(std::string, Method1, std::string) |
| 85 | PROXY_CONSTMETHOD1(std::string, ConstMethod1, std::string) |
| 86 | PROXY_METHOD2(std::string, Method2, std::string, std::string) |
Markus Handell | 3d46d0b | 2021-05-27 19:42:57 | [diff] [blame] | 87 | END_PROXY_MAP(Fake) |
nisse | 72c8d2b | 2016-04-15 10:49:07 | [diff] [blame] | 88 | #undef FakeProxy |
| 89 | |
Mirko Bonadei | 6a489f2 | 2019-04-09 13:11:12 | [diff] [blame] | 90 | class SignalingProxyTest : public ::testing::Test { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 91 | public: |
nisse | 72c8d2b | 2016-04-15 10:49:07 | [diff] [blame] | 92 | // Checks that the functions are called on the right thread. |
| 93 | void CheckSignalingThread() { EXPECT_TRUE(signaling_thread_->IsCurrent()); } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 94 | |
| 95 | protected: |
nisse | 72c8d2b | 2016-04-15 10:49:07 | [diff] [blame] | 96 | void SetUp() override { |
tommi | e725159 | 2017-07-14 21:44:46 | [diff] [blame] | 97 | signaling_thread_ = rtc::Thread::Create(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 98 | ASSERT_TRUE(signaling_thread_->Start()); |
| 99 | fake_ = Fake::Create(); |
nisse | 72c8d2b | 2016-04-15 10:49:07 | [diff] [blame] | 100 | fake_signaling_proxy_ = |
| 101 | FakeSignalingProxy::Create(signaling_thread_.get(), fake_.get()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | protected: |
kwiberg | d1fe281 | 2016-04-27 13:47:29 | [diff] [blame] | 105 | std::unique_ptr<rtc::Thread> signaling_thread_; |
nisse | 72c8d2b | 2016-04-15 10:49:07 | [diff] [blame] | 106 | rtc::scoped_refptr<FakeInterface> fake_signaling_proxy_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 107 | rtc::scoped_refptr<Fake> fake_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 108 | }; |
| 109 | |
deadbeef | d99a200 | 2017-01-18 16:55:23 | [diff] [blame] | 110 | TEST_F(SignalingProxyTest, SignalingThreadDestructor) { |
| 111 | EXPECT_CALL(*fake_, Destroy()) |
| 112 | .Times(Exactly(1)) |
| 113 | .WillOnce( |
| 114 | InvokeWithoutArgs(this, &SignalingProxyTest::CheckSignalingThread)); |
| 115 | fake_ = nullptr; |
| 116 | fake_signaling_proxy_ = nullptr; |
| 117 | } |
| 118 | |
nisse | 72c8d2b | 2016-04-15 10:49:07 | [diff] [blame] | 119 | TEST_F(SignalingProxyTest, VoidMethod0) { |
| 120 | EXPECT_CALL(*fake_, VoidMethod0()) |
| 121 | .Times(Exactly(1)) |
| 122 | .WillOnce( |
| 123 | InvokeWithoutArgs(this, &SignalingProxyTest::CheckSignalingThread)); |
| 124 | fake_signaling_proxy_->VoidMethod0(); |
| 125 | } |
| 126 | |
| 127 | TEST_F(SignalingProxyTest, Method0) { |
| 128 | EXPECT_CALL(*fake_, Method0()) |
| 129 | .Times(Exactly(1)) |
| 130 | .WillOnce(DoAll( |
| 131 | InvokeWithoutArgs(this, &SignalingProxyTest::CheckSignalingThread), |
| 132 | Return("Method0"))); |
| 133 | EXPECT_EQ("Method0", fake_signaling_proxy_->Method0()); |
| 134 | } |
| 135 | |
| 136 | TEST_F(SignalingProxyTest, ConstMethod0) { |
| 137 | EXPECT_CALL(*fake_, ConstMethod0()) |
| 138 | .Times(Exactly(1)) |
| 139 | .WillOnce(DoAll( |
| 140 | InvokeWithoutArgs(this, &SignalingProxyTest::CheckSignalingThread), |
| 141 | Return("ConstMethod0"))); |
| 142 | EXPECT_EQ("ConstMethod0", fake_signaling_proxy_->ConstMethod0()); |
| 143 | } |
| 144 | |
| 145 | TEST_F(SignalingProxyTest, Method1) { |
| 146 | const std::string arg1 = "arg1"; |
| 147 | EXPECT_CALL(*fake_, Method1(arg1)) |
| 148 | .Times(Exactly(1)) |
| 149 | .WillOnce(DoAll( |
| 150 | InvokeWithoutArgs(this, &SignalingProxyTest::CheckSignalingThread), |
| 151 | Return("Method1"))); |
| 152 | EXPECT_EQ("Method1", fake_signaling_proxy_->Method1(arg1)); |
| 153 | } |
| 154 | |
| 155 | TEST_F(SignalingProxyTest, ConstMethod1) { |
| 156 | const std::string arg1 = "arg1"; |
| 157 | EXPECT_CALL(*fake_, ConstMethod1(arg1)) |
| 158 | .Times(Exactly(1)) |
| 159 | .WillOnce(DoAll( |
| 160 | InvokeWithoutArgs(this, &SignalingProxyTest::CheckSignalingThread), |
| 161 | Return("ConstMethod1"))); |
| 162 | EXPECT_EQ("ConstMethod1", fake_signaling_proxy_->ConstMethod1(arg1)); |
| 163 | } |
| 164 | |
| 165 | TEST_F(SignalingProxyTest, Method2) { |
| 166 | const std::string arg1 = "arg1"; |
| 167 | const std::string arg2 = "arg2"; |
| 168 | EXPECT_CALL(*fake_, Method2(arg1, arg2)) |
| 169 | .Times(Exactly(1)) |
| 170 | .WillOnce(DoAll( |
| 171 | InvokeWithoutArgs(this, &SignalingProxyTest::CheckSignalingThread), |
| 172 | Return("Method2"))); |
| 173 | EXPECT_EQ("Method2", fake_signaling_proxy_->Method2(arg1, arg2)); |
| 174 | } |
| 175 | |
Mirko Bonadei | 6a489f2 | 2019-04-09 13:11:12 | [diff] [blame] | 176 | class ProxyTest : public ::testing::Test { |
nisse | 72c8d2b | 2016-04-15 10:49:07 | [diff] [blame] | 177 | public: |
| 178 | // Checks that the functions are called on the right thread. |
deadbeef | d99a200 | 2017-01-18 16:55:23 | [diff] [blame] | 179 | void CheckSignalingThread() { EXPECT_TRUE(signaling_thread_->IsCurrent()); } |
nisse | 72c8d2b | 2016-04-15 10:49:07 | [diff] [blame] | 180 | void CheckWorkerThread() { EXPECT_TRUE(worker_thread_->IsCurrent()); } |
| 181 | |
| 182 | protected: |
| 183 | void SetUp() override { |
tommi | e725159 | 2017-07-14 21:44:46 | [diff] [blame] | 184 | signaling_thread_ = rtc::Thread::Create(); |
| 185 | worker_thread_ = rtc::Thread::Create(); |
deadbeef | d99a200 | 2017-01-18 16:55:23 | [diff] [blame] | 186 | ASSERT_TRUE(signaling_thread_->Start()); |
nisse | 72c8d2b | 2016-04-15 10:49:07 | [diff] [blame] | 187 | ASSERT_TRUE(worker_thread_->Start()); |
deadbeef | d99a200 | 2017-01-18 16:55:23 | [diff] [blame] | 188 | fake_ = Fake::Create(); |
nisse | 72c8d2b | 2016-04-15 10:49:07 | [diff] [blame] | 189 | fake_proxy_ = FakeProxy::Create(signaling_thread_.get(), |
| 190 | worker_thread_.get(), fake_.get()); |
| 191 | } |
| 192 | |
| 193 | protected: |
deadbeef | d99a200 | 2017-01-18 16:55:23 | [diff] [blame] | 194 | std::unique_ptr<rtc::Thread> signaling_thread_; |
kwiberg | d1fe281 | 2016-04-27 13:47:29 | [diff] [blame] | 195 | std::unique_ptr<rtc::Thread> worker_thread_; |
nisse | 72c8d2b | 2016-04-15 10:49:07 | [diff] [blame] | 196 | rtc::scoped_refptr<FakeInterface> fake_proxy_; |
deadbeef | d99a200 | 2017-01-18 16:55:23 | [diff] [blame] | 197 | rtc::scoped_refptr<Fake> fake_; |
nisse | 72c8d2b | 2016-04-15 10:49:07 | [diff] [blame] | 198 | }; |
| 199 | |
deadbeef | d99a200 | 2017-01-18 16:55:23 | [diff] [blame] | 200 | TEST_F(ProxyTest, WorkerThreadDestructor) { |
| 201 | EXPECT_CALL(*fake_, Destroy()) |
| 202 | .Times(Exactly(1)) |
| 203 | .WillOnce(InvokeWithoutArgs(this, &ProxyTest::CheckWorkerThread)); |
| 204 | fake_ = nullptr; |
| 205 | fake_proxy_ = nullptr; |
| 206 | } |
| 207 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 208 | TEST_F(ProxyTest, VoidMethod0) { |
| 209 | EXPECT_CALL(*fake_, VoidMethod0()) |
nisse | 72c8d2b | 2016-04-15 10:49:07 | [diff] [blame] | 210 | .Times(Exactly(1)) |
| 211 | .WillOnce(InvokeWithoutArgs(this, &ProxyTest::CheckSignalingThread)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 212 | fake_proxy_->VoidMethod0(); |
| 213 | } |
| 214 | |
| 215 | TEST_F(ProxyTest, Method0) { |
| 216 | EXPECT_CALL(*fake_, Method0()) |
nisse | 72c8d2b | 2016-04-15 10:49:07 | [diff] [blame] | 217 | .Times(Exactly(1)) |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 218 | .WillOnce(DoAll(InvokeWithoutArgs(this, &ProxyTest::CheckSignalingThread), |
| 219 | Return("Method0"))); |
| 220 | EXPECT_EQ("Method0", fake_proxy_->Method0()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | TEST_F(ProxyTest, ConstMethod0) { |
| 224 | EXPECT_CALL(*fake_, ConstMethod0()) |
nisse | 72c8d2b | 2016-04-15 10:49:07 | [diff] [blame] | 225 | .Times(Exactly(1)) |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 226 | .WillOnce(DoAll(InvokeWithoutArgs(this, &ProxyTest::CheckSignalingThread), |
| 227 | Return("ConstMethod0"))); |
| 228 | EXPECT_EQ("ConstMethod0", fake_proxy_->ConstMethod0()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 229 | } |
| 230 | |
nisse | 72c8d2b | 2016-04-15 10:49:07 | [diff] [blame] | 231 | TEST_F(ProxyTest, WorkerMethod1) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 232 | const std::string arg1 = "arg1"; |
| 233 | EXPECT_CALL(*fake_, Method1(arg1)) |
nisse | 72c8d2b | 2016-04-15 10:49:07 | [diff] [blame] | 234 | .Times(Exactly(1)) |
| 235 | .WillOnce(DoAll(InvokeWithoutArgs(this, &ProxyTest::CheckWorkerThread), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 236 | Return("Method1"))); |
| 237 | EXPECT_EQ("Method1", fake_proxy_->Method1(arg1)); |
| 238 | } |
| 239 | |
| 240 | TEST_F(ProxyTest, ConstMethod1) { |
| 241 | const std::string arg1 = "arg1"; |
| 242 | EXPECT_CALL(*fake_, ConstMethod1(arg1)) |
nisse | 72c8d2b | 2016-04-15 10:49:07 | [diff] [blame] | 243 | .Times(Exactly(1)) |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 244 | .WillOnce(DoAll(InvokeWithoutArgs(this, &ProxyTest::CheckSignalingThread), |
| 245 | Return("ConstMethod1"))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 246 | EXPECT_EQ("ConstMethod1", fake_proxy_->ConstMethod1(arg1)); |
| 247 | } |
| 248 | |
nisse | 72c8d2b | 2016-04-15 10:49:07 | [diff] [blame] | 249 | TEST_F(ProxyTest, WorkerMethod2) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 250 | const std::string arg1 = "arg1"; |
| 251 | const std::string arg2 = "arg2"; |
| 252 | EXPECT_CALL(*fake_, Method2(arg1, arg2)) |
nisse | 72c8d2b | 2016-04-15 10:49:07 | [diff] [blame] | 253 | .Times(Exactly(1)) |
| 254 | .WillOnce(DoAll(InvokeWithoutArgs(this, &ProxyTest::CheckWorkerThread), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 255 | Return("Method2"))); |
| 256 | EXPECT_EQ("Method2", fake_proxy_->Method2(arg1, arg2)); |
| 257 | } |
| 258 | |
deadbeef | d99a200 | 2017-01-18 16:55:23 | [diff] [blame] | 259 | // Interface for testing OWNED_PROXY_MAP. |
| 260 | class FooInterface { |
| 261 | public: |
| 262 | virtual ~FooInterface() {} |
| 263 | virtual void Bar() = 0; |
| 264 | }; |
| 265 | |
| 266 | class Foo : public FooInterface { |
| 267 | public: |
| 268 | Foo() {} |
Danil Chapovalov | 3a35312 | 2020-05-15 09:16:53 | [diff] [blame] | 269 | MOCK_METHOD(void, Bar, (), (override)); |
deadbeef | d99a200 | 2017-01-18 16:55:23 | [diff] [blame] | 270 | }; |
| 271 | |
| 272 | BEGIN_OWNED_PROXY_MAP(Foo) |
Mirko Bonadei | 9d9b8de | 2021-02-26 08:51:26 | [diff] [blame] | 273 | PROXY_PRIMARY_THREAD_DESTRUCTOR() |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 274 | PROXY_METHOD0(void, Bar) |
Markus Handell | 3d46d0b | 2021-05-27 19:42:57 | [diff] [blame] | 275 | END_PROXY_MAP(Foo) |
deadbeef | d99a200 | 2017-01-18 16:55:23 | [diff] [blame] | 276 | |
Mirko Bonadei | 6a489f2 | 2019-04-09 13:11:12 | [diff] [blame] | 277 | class OwnedProxyTest : public ::testing::Test { |
deadbeef | d99a200 | 2017-01-18 16:55:23 | [diff] [blame] | 278 | public: |
| 279 | OwnedProxyTest() |
tommi | e725159 | 2017-07-14 21:44:46 | [diff] [blame] | 280 | : signaling_thread_(rtc::Thread::Create()), |
| 281 | worker_thread_(rtc::Thread::Create()), |
| 282 | foo_(new Foo()), |
| 283 | foo_proxy_(FooProxy::Create(signaling_thread_.get(), |
| 284 | worker_thread_.get(), |
deadbeef | e814a0d | 2017-02-26 02:15:09 | [diff] [blame] | 285 | std::unique_ptr<FooInterface>(foo_))) { |
tommi | e725159 | 2017-07-14 21:44:46 | [diff] [blame] | 286 | signaling_thread_->Start(); |
| 287 | worker_thread_->Start(); |
deadbeef | d99a200 | 2017-01-18 16:55:23 | [diff] [blame] | 288 | } |
| 289 | |
tommi | e725159 | 2017-07-14 21:44:46 | [diff] [blame] | 290 | void CheckSignalingThread() { EXPECT_TRUE(signaling_thread_->IsCurrent()); } |
| 291 | void CheckWorkerThread() { EXPECT_TRUE(worker_thread_->IsCurrent()); } |
deadbeef | d99a200 | 2017-01-18 16:55:23 | [diff] [blame] | 292 | |
| 293 | protected: |
tommi | e725159 | 2017-07-14 21:44:46 | [diff] [blame] | 294 | std::unique_ptr<rtc::Thread> signaling_thread_; |
| 295 | std::unique_ptr<rtc::Thread> worker_thread_; |
deadbeef | d99a200 | 2017-01-18 16:55:23 | [diff] [blame] | 296 | Foo* foo_; // Owned by foo_proxy_, not this class. |
| 297 | std::unique_ptr<FooInterface> foo_proxy_; |
| 298 | }; |
| 299 | |
| 300 | // Just tests that a method can be invoked using an "owned proxy" (as opposed |
| 301 | // to normal ref-counted version). |
| 302 | TEST_F(OwnedProxyTest, BasicTest) { |
| 303 | EXPECT_CALL(*foo_, Bar()) |
| 304 | .Times(Exactly(1)) |
| 305 | .WillOnce(InvokeWithoutArgs(this, &OwnedProxyTest::CheckSignalingThread)); |
| 306 | foo_proxy_->Bar(); |
| 307 | } |
| 308 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 309 | } // namespace webrtc |