| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2013 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 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 virtual std::string Method0() = 0; | 33 virtual std::string Method0() = 0; |
| 34 virtual std::string ConstMethod0() const = 0; | 34 virtual std::string ConstMethod0() const = 0; |
| 35 virtual std::string Method1(std::string s) = 0; | 35 virtual std::string Method1(std::string s) = 0; |
| 36 virtual std::string ConstMethod1(std::string s) const = 0; | 36 virtual std::string ConstMethod1(std::string s) const = 0; |
| 37 virtual std::string Method2(std::string s1, std::string s2) = 0; | 37 virtual std::string Method2(std::string s1, std::string s2) = 0; |
| 38 | 38 |
| 39 protected: | 39 protected: |
| 40 ~FakeInterface() {} | 40 ~FakeInterface() {} |
| 41 }; | 41 }; |
| 42 | 42 |
| 43 // Proxy for the test interface. | |
| 44 BEGIN_PROXY_MAP(Fake) | |
| 45 PROXY_METHOD0(void, VoidMethod0) | |
| 46 PROXY_METHOD0(std::string, Method0) | |
| 47 PROXY_CONSTMETHOD0(std::string, ConstMethod0) | |
| 48 PROXY_METHOD1(std::string, Method1, std::string) | |
| 49 PROXY_CONSTMETHOD1(std::string, ConstMethod1, std::string) | |
| 50 PROXY_METHOD2(std::string, Method2, std::string, std::string) | |
| 51 END_PROXY() | |
| 52 | |
| 53 // Implementation of the test interface. | 43 // Implementation of the test interface. |
| 54 class Fake : public FakeInterface { | 44 class Fake : public FakeInterface { |
| 55 public: | 45 public: |
| 56 static rtc::scoped_refptr<Fake> Create() { | 46 static rtc::scoped_refptr<Fake> Create() { |
| 57 return new rtc::RefCountedObject<Fake>(); | 47 return new rtc::RefCountedObject<Fake>(); |
| 58 } | 48 } |
| 59 | 49 |
| 60 MOCK_METHOD0(VoidMethod0, void()); | 50 MOCK_METHOD0(VoidMethod0, void()); |
| 61 MOCK_METHOD0(Method0, std::string()); | 51 MOCK_METHOD0(Method0, std::string()); |
| 62 MOCK_CONST_METHOD0(ConstMethod0, std::string()); | 52 MOCK_CONST_METHOD0(ConstMethod0, std::string()); |
| 63 | 53 |
| 64 MOCK_METHOD1(Method1, std::string(std::string)); | 54 MOCK_METHOD1(Method1, std::string(std::string)); |
| 65 MOCK_CONST_METHOD1(ConstMethod1, std::string(std::string)); | 55 MOCK_CONST_METHOD1(ConstMethod1, std::string(std::string)); |
| 66 | 56 |
| 67 MOCK_METHOD2(Method2, std::string(std::string, std::string)); | 57 MOCK_METHOD2(Method2, std::string(std::string, std::string)); |
| 68 | 58 |
| 69 protected: | 59 protected: |
| 70 Fake() {} | 60 Fake() {} |
| 71 ~Fake() {} | 61 ~Fake() {} |
| 72 }; | 62 }; |
| 73 | 63 |
| 74 class ProxyTest: public testing::Test { | 64 // Proxies for the test interface. |
| 65 BEGIN_PROXY_MAP(Fake) |
| 66 PROXY_METHOD0(void, VoidMethod0) |
| 67 PROXY_METHOD0(std::string, Method0) |
| 68 PROXY_CONSTMETHOD0(std::string, ConstMethod0) |
| 69 PROXY_WORKER_METHOD1(std::string, Method1, std::string) |
| 70 PROXY_CONSTMETHOD1(std::string, ConstMethod1, std::string) |
| 71 PROXY_WORKER_METHOD2(std::string, Method2, std::string, std::string) |
| 72 END_PROXY() |
| 73 |
| 74 // Preprocessor hack to get a proxy class a name different than FakeProxy. |
| 75 #define FakeProxy FakeSignalingProxy |
| 76 BEGIN_SIGNALING_PROXY_MAP(Fake) |
| 77 PROXY_METHOD0(void, VoidMethod0) |
| 78 PROXY_METHOD0(std::string, Method0) |
| 79 PROXY_CONSTMETHOD0(std::string, ConstMethod0) |
| 80 PROXY_METHOD1(std::string, Method1, std::string) |
| 81 PROXY_CONSTMETHOD1(std::string, ConstMethod1, std::string) |
| 82 PROXY_METHOD2(std::string, Method2, std::string, std::string) |
| 83 END_SIGNALING_PROXY() |
| 84 #undef FakeProxy |
| 85 |
| 86 class SignalingProxyTest : public testing::Test { |
| 75 public: | 87 public: |
| 76 // Checks that the functions is called on the |signaling_thread_|. | 88 // Checks that the functions are called on the right thread. |
| 77 void CheckThread() { | 89 void CheckSignalingThread() { EXPECT_TRUE(signaling_thread_->IsCurrent()); } |
| 78 EXPECT_EQ(rtc::Thread::Current(), signaling_thread_.get()); | |
| 79 } | |
| 80 | 90 |
| 81 protected: | 91 protected: |
| 82 virtual void SetUp() { | 92 void SetUp() override { |
| 83 signaling_thread_.reset(new rtc::Thread()); | 93 signaling_thread_.reset(new rtc::Thread()); |
| 84 ASSERT_TRUE(signaling_thread_->Start()); | 94 ASSERT_TRUE(signaling_thread_->Start()); |
| 85 fake_ = Fake::Create(); | 95 fake_ = Fake::Create(); |
| 86 fake_proxy_ = FakeProxy::Create(signaling_thread_.get(), fake_.get()); | 96 fake_signaling_proxy_ = |
| 97 FakeSignalingProxy::Create(signaling_thread_.get(), fake_.get()); |
| 87 } | 98 } |
| 88 | 99 |
| 89 protected: | 100 protected: |
| 90 rtc::scoped_ptr<rtc::Thread> signaling_thread_; | 101 rtc::scoped_ptr<rtc::Thread> signaling_thread_; |
| 102 rtc::scoped_refptr<FakeInterface> fake_signaling_proxy_; |
| 103 rtc::scoped_refptr<Fake> fake_; |
| 104 }; |
| 105 |
| 106 TEST_F(SignalingProxyTest, VoidMethod0) { |
| 107 EXPECT_CALL(*fake_, VoidMethod0()) |
| 108 .Times(Exactly(1)) |
| 109 .WillOnce( |
| 110 InvokeWithoutArgs(this, &SignalingProxyTest::CheckSignalingThread)); |
| 111 fake_signaling_proxy_->VoidMethod0(); |
| 112 } |
| 113 |
| 114 TEST_F(SignalingProxyTest, Method0) { |
| 115 EXPECT_CALL(*fake_, Method0()) |
| 116 .Times(Exactly(1)) |
| 117 .WillOnce(DoAll( |
| 118 InvokeWithoutArgs(this, &SignalingProxyTest::CheckSignalingThread), |
| 119 Return("Method0"))); |
| 120 EXPECT_EQ("Method0", fake_signaling_proxy_->Method0()); |
| 121 } |
| 122 |
| 123 TEST_F(SignalingProxyTest, ConstMethod0) { |
| 124 EXPECT_CALL(*fake_, ConstMethod0()) |
| 125 .Times(Exactly(1)) |
| 126 .WillOnce(DoAll( |
| 127 InvokeWithoutArgs(this, &SignalingProxyTest::CheckSignalingThread), |
| 128 Return("ConstMethod0"))); |
| 129 EXPECT_EQ("ConstMethod0", fake_signaling_proxy_->ConstMethod0()); |
| 130 } |
| 131 |
| 132 TEST_F(SignalingProxyTest, Method1) { |
| 133 const std::string arg1 = "arg1"; |
| 134 EXPECT_CALL(*fake_, Method1(arg1)) |
| 135 .Times(Exactly(1)) |
| 136 .WillOnce(DoAll( |
| 137 InvokeWithoutArgs(this, &SignalingProxyTest::CheckSignalingThread), |
| 138 Return("Method1"))); |
| 139 EXPECT_EQ("Method1", fake_signaling_proxy_->Method1(arg1)); |
| 140 } |
| 141 |
| 142 TEST_F(SignalingProxyTest, ConstMethod1) { |
| 143 const std::string arg1 = "arg1"; |
| 144 EXPECT_CALL(*fake_, ConstMethod1(arg1)) |
| 145 .Times(Exactly(1)) |
| 146 .WillOnce(DoAll( |
| 147 InvokeWithoutArgs(this, &SignalingProxyTest::CheckSignalingThread), |
| 148 Return("ConstMethod1"))); |
| 149 EXPECT_EQ("ConstMethod1", fake_signaling_proxy_->ConstMethod1(arg1)); |
| 150 } |
| 151 |
| 152 TEST_F(SignalingProxyTest, Method2) { |
| 153 const std::string arg1 = "arg1"; |
| 154 const std::string arg2 = "arg2"; |
| 155 EXPECT_CALL(*fake_, Method2(arg1, arg2)) |
| 156 .Times(Exactly(1)) |
| 157 .WillOnce(DoAll( |
| 158 InvokeWithoutArgs(this, &SignalingProxyTest::CheckSignalingThread), |
| 159 Return("Method2"))); |
| 160 EXPECT_EQ("Method2", fake_signaling_proxy_->Method2(arg1, arg2)); |
| 161 } |
| 162 |
| 163 class ProxyTest : public SignalingProxyTest { |
| 164 public: |
| 165 // Checks that the functions are called on the right thread. |
| 166 void CheckWorkerThread() { EXPECT_TRUE(worker_thread_->IsCurrent()); } |
| 167 |
| 168 protected: |
| 169 void SetUp() override { |
| 170 SignalingProxyTest::SetUp(); |
| 171 worker_thread_.reset(new rtc::Thread()); |
| 172 ASSERT_TRUE(worker_thread_->Start()); |
| 173 fake_proxy_ = FakeProxy::Create(signaling_thread_.get(), |
| 174 worker_thread_.get(), fake_.get()); |
| 175 } |
| 176 |
| 177 protected: |
| 178 rtc::scoped_ptr<rtc::Thread> worker_thread_; |
| 91 rtc::scoped_refptr<FakeInterface> fake_proxy_; | 179 rtc::scoped_refptr<FakeInterface> fake_proxy_; |
| 92 rtc::scoped_refptr<Fake> fake_; | |
| 93 }; | 180 }; |
| 94 | 181 |
| 95 TEST_F(ProxyTest, VoidMethod0) { | 182 TEST_F(ProxyTest, VoidMethod0) { |
| 96 EXPECT_CALL(*fake_, VoidMethod0()) | 183 EXPECT_CALL(*fake_, VoidMethod0()) |
| 97 .Times(Exactly(1)) | 184 .Times(Exactly(1)) |
| 98 .WillOnce(InvokeWithoutArgs(this, &ProxyTest::CheckThread)); | 185 .WillOnce(InvokeWithoutArgs(this, &ProxyTest::CheckSignalingThread)); |
| 99 fake_proxy_->VoidMethod0(); | 186 fake_proxy_->VoidMethod0(); |
| 100 } | 187 } |
| 101 | 188 |
| 102 TEST_F(ProxyTest, Method0) { | 189 TEST_F(ProxyTest, Method0) { |
| 103 EXPECT_CALL(*fake_, Method0()) | 190 EXPECT_CALL(*fake_, Method0()) |
| 104 .Times(Exactly(1)) | 191 .Times(Exactly(1)) |
| 105 .WillOnce( | 192 .WillOnce( |
| 106 DoAll(InvokeWithoutArgs(this, &ProxyTest::CheckThread), | 193 DoAll(InvokeWithoutArgs(this, &ProxyTest::CheckSignalingThread), |
| 107 Return("Method0"))); | 194 Return("Method0"))); |
| 108 EXPECT_EQ("Method0", | 195 EXPECT_EQ("Method0", |
| 109 fake_proxy_->Method0()); | 196 fake_proxy_->Method0()); |
| 110 } | 197 } |
| 111 | 198 |
| 112 TEST_F(ProxyTest, ConstMethod0) { | 199 TEST_F(ProxyTest, ConstMethod0) { |
| 113 EXPECT_CALL(*fake_, ConstMethod0()) | 200 EXPECT_CALL(*fake_, ConstMethod0()) |
| 114 .Times(Exactly(1)) | 201 .Times(Exactly(1)) |
| 115 .WillOnce( | 202 .WillOnce( |
| 116 DoAll(InvokeWithoutArgs(this, &ProxyTest::CheckThread), | 203 DoAll(InvokeWithoutArgs(this, &ProxyTest::CheckSignalingThread), |
| 117 Return("ConstMethod0"))); | 204 Return("ConstMethod0"))); |
| 118 EXPECT_EQ("ConstMethod0", | 205 EXPECT_EQ("ConstMethod0", |
| 119 fake_proxy_->ConstMethod0()); | 206 fake_proxy_->ConstMethod0()); |
| 120 } | 207 } |
| 121 | 208 |
| 122 TEST_F(ProxyTest, Method1) { | 209 TEST_F(ProxyTest, WorkerMethod1) { |
| 123 const std::string arg1 = "arg1"; | 210 const std::string arg1 = "arg1"; |
| 124 EXPECT_CALL(*fake_, Method1(arg1)) | 211 EXPECT_CALL(*fake_, Method1(arg1)) |
| 125 .Times(Exactly(1)) | 212 .Times(Exactly(1)) |
| 126 .WillOnce( | 213 .WillOnce(DoAll(InvokeWithoutArgs(this, &ProxyTest::CheckWorkerThread), |
| 127 DoAll(InvokeWithoutArgs(this, &ProxyTest::CheckThread), | |
| 128 Return("Method1"))); | 214 Return("Method1"))); |
| 129 EXPECT_EQ("Method1", fake_proxy_->Method1(arg1)); | 215 EXPECT_EQ("Method1", fake_proxy_->Method1(arg1)); |
| 130 } | 216 } |
| 131 | 217 |
| 132 TEST_F(ProxyTest, ConstMethod1) { | 218 TEST_F(ProxyTest, ConstMethod1) { |
| 133 const std::string arg1 = "arg1"; | 219 const std::string arg1 = "arg1"; |
| 134 EXPECT_CALL(*fake_, ConstMethod1(arg1)) | 220 EXPECT_CALL(*fake_, ConstMethod1(arg1)) |
| 135 .Times(Exactly(1)) | 221 .Times(Exactly(1)) |
| 136 .WillOnce( | 222 .WillOnce( |
| 137 DoAll(InvokeWithoutArgs(this, &ProxyTest::CheckThread), | 223 DoAll(InvokeWithoutArgs(this, &ProxyTest::CheckSignalingThread), |
| 138 Return("ConstMethod1"))); | 224 Return("ConstMethod1"))); |
| 139 EXPECT_EQ("ConstMethod1", fake_proxy_->ConstMethod1(arg1)); | 225 EXPECT_EQ("ConstMethod1", fake_proxy_->ConstMethod1(arg1)); |
| 140 } | 226 } |
| 141 | 227 |
| 142 TEST_F(ProxyTest, Method2) { | 228 TEST_F(ProxyTest, WorkerMethod2) { |
| 143 const std::string arg1 = "arg1"; | 229 const std::string arg1 = "arg1"; |
| 144 const std::string arg2 = "arg2"; | 230 const std::string arg2 = "arg2"; |
| 145 EXPECT_CALL(*fake_, Method2(arg1, arg2)) | 231 EXPECT_CALL(*fake_, Method2(arg1, arg2)) |
| 146 .Times(Exactly(1)) | 232 .Times(Exactly(1)) |
| 147 .WillOnce( | 233 .WillOnce(DoAll(InvokeWithoutArgs(this, &ProxyTest::CheckWorkerThread), |
| 148 DoAll(InvokeWithoutArgs(this, &ProxyTest::CheckThread), | |
| 149 Return("Method2"))); | 234 Return("Method2"))); |
| 150 EXPECT_EQ("Method2", fake_proxy_->Method2(arg1, arg2)); | 235 EXPECT_EQ("Method2", fake_proxy_->Method2(arg1, arg2)); |
| 151 } | 236 } |
| 152 | 237 |
| 153 } // namespace webrtc | 238 } // namespace webrtc |
| OLD | NEW |