OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/at_exit.h" | 5 #include "base/at_exit.h" |
6 #include "base/macros.h" | 6 #include "base/macros.h" |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "mojo/public/cpp/bindings/callback.h" | 8 #include "mojo/public/cpp/bindings/callback.h" |
9 #include "mojo/services/public/interfaces/network/network_service.mojom.h" | 9 #include "mojo/services/public/interfaces/network/network_service.mojom.h" |
10 #include "mojo/services/public/interfaces/network/udp_socket.mojom.h" | 10 #include "mojo/services/public/interfaces/network/udp_socket.mojom.h" |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 public: | 124 public: |
125 TestCallback() { | 125 TestCallback() { |
126 Initialize(new State()); | 126 Initialize(new State()); |
127 } | 127 } |
128 ~TestCallback() {} | 128 ~TestCallback() {} |
129 | 129 |
130 const NetworkErrorPtr& result() const { return result_; } | 130 const NetworkErrorPtr& result() const { return result_; } |
131 | 131 |
132 private: | 132 private: |
133 struct State: public StateBase { | 133 struct State: public StateBase { |
134 virtual ~State() {} | 134 ~State() override {} |
135 | 135 |
136 virtual void Run(NetworkErrorPtr result) const override { | 136 void Run(NetworkErrorPtr result) const override { |
137 if (test_callback_) { | 137 if (test_callback_) { |
138 TestCallback* callback = static_cast<TestCallback*>(test_callback_); | 138 TestCallback* callback = static_cast<TestCallback*>(test_callback_); |
139 callback->result_ = result.Pass(); | 139 callback->result_ = result.Pass(); |
140 } | 140 } |
141 NotifyRun(); | 141 NotifyRun(); |
142 } | 142 } |
143 }; | 143 }; |
144 | 144 |
145 NetworkErrorPtr result_; | 145 NetworkErrorPtr result_; |
146 }; | 146 }; |
147 | 147 |
148 class TestCallbackWithAddress | 148 class TestCallbackWithAddress |
149 : public TestCallbackBase<Callback<void(NetworkErrorPtr, NetAddressPtr)>> { | 149 : public TestCallbackBase<Callback<void(NetworkErrorPtr, NetAddressPtr)>> { |
150 public: | 150 public: |
151 TestCallbackWithAddress() { | 151 TestCallbackWithAddress() { |
152 Initialize(new State()); | 152 Initialize(new State()); |
153 } | 153 } |
154 ~TestCallbackWithAddress() {} | 154 ~TestCallbackWithAddress() {} |
155 | 155 |
156 const NetworkErrorPtr& result() const { return result_; } | 156 const NetworkErrorPtr& result() const { return result_; } |
157 const NetAddressPtr& net_address() const { return net_address_; } | 157 const NetAddressPtr& net_address() const { return net_address_; } |
158 | 158 |
159 private: | 159 private: |
160 struct State : public StateBase { | 160 struct State : public StateBase { |
161 virtual ~State() {} | 161 ~State() override {} |
162 | 162 |
163 virtual void Run(NetworkErrorPtr result, | 163 void Run(NetworkErrorPtr result, NetAddressPtr net_address) const override { |
164 NetAddressPtr net_address) const override { | |
165 if (test_callback_) { | 164 if (test_callback_) { |
166 TestCallbackWithAddress* callback = | 165 TestCallbackWithAddress* callback = |
167 static_cast<TestCallbackWithAddress*>(test_callback_); | 166 static_cast<TestCallbackWithAddress*>(test_callback_); |
168 callback->result_ = result.Pass(); | 167 callback->result_ = result.Pass(); |
169 callback->net_address_ = net_address.Pass(); | 168 callback->net_address_ = net_address.Pass(); |
170 } | 169 } |
171 NotifyRun(); | 170 NotifyRun(); |
172 } | 171 } |
173 }; | 172 }; |
174 | 173 |
175 NetworkErrorPtr result_; | 174 NetworkErrorPtr result_; |
176 NetAddressPtr net_address_; | 175 NetAddressPtr net_address_; |
177 }; | 176 }; |
178 | 177 |
179 class TestCallbackWithUint32 | 178 class TestCallbackWithUint32 |
180 : public TestCallbackBase<Callback<void(uint32_t)>> { | 179 : public TestCallbackBase<Callback<void(uint32_t)>> { |
181 public: | 180 public: |
182 TestCallbackWithUint32() : result_(0) { | 181 TestCallbackWithUint32() : result_(0) { |
183 Initialize(new State()); | 182 Initialize(new State()); |
184 } | 183 } |
185 ~TestCallbackWithUint32() {} | 184 ~TestCallbackWithUint32() {} |
186 | 185 |
187 uint32_t result() const { return result_; } | 186 uint32_t result() const { return result_; } |
188 | 187 |
189 private: | 188 private: |
190 struct State : public StateBase { | 189 struct State : public StateBase { |
191 virtual ~State() {} | 190 ~State() override {} |
192 | 191 |
193 virtual void Run(uint32_t result) const override { | 192 void Run(uint32_t result) const override { |
194 if (test_callback_) { | 193 if (test_callback_) { |
195 TestCallbackWithUint32* callback = | 194 TestCallbackWithUint32* callback = |
196 static_cast<TestCallbackWithUint32*>(test_callback_); | 195 static_cast<TestCallbackWithUint32*>(test_callback_); |
197 callback->result_ = result; | 196 callback->result_ = result; |
198 } | 197 } |
199 NotifyRun(); | 198 NotifyRun(); |
200 } | 199 } |
201 }; | 200 }; |
202 | 201 |
203 uint32_t result_; | 202 uint32_t result_; |
(...skipping 19 matching lines...) Expand all Loading... |
223 NetworkErrorPtr result; | 222 NetworkErrorPtr result; |
224 NetAddressPtr addr; | 223 NetAddressPtr addr; |
225 Array<uint8_t> data; | 224 Array<uint8_t> data; |
226 }; | 225 }; |
227 | 226 |
228 class UDPSocketClientImpl : public UDPSocketClient { | 227 class UDPSocketClientImpl : public UDPSocketClient { |
229 public: | 228 public: |
230 | 229 |
231 UDPSocketClientImpl() : run_loop_(nullptr), expected_receive_count_(0) {} | 230 UDPSocketClientImpl() : run_loop_(nullptr), expected_receive_count_(0) {} |
232 | 231 |
233 virtual ~UDPSocketClientImpl() { | 232 ~UDPSocketClientImpl() override { |
234 while (!results_.empty()) { | 233 while (!results_.empty()) { |
235 delete results_.front(); | 234 delete results_.front(); |
236 results_.pop(); | 235 results_.pop(); |
237 } | 236 } |
238 } | 237 } |
239 | 238 |
240 virtual void OnReceived(NetworkErrorPtr result, | 239 void OnReceived(NetworkErrorPtr result, |
241 NetAddressPtr src_addr, | 240 NetAddressPtr src_addr, |
242 Array<uint8_t> data) override { | 241 Array<uint8_t> data) override { |
243 ReceiveResult* entry = new ReceiveResult(); | 242 ReceiveResult* entry = new ReceiveResult(); |
244 entry->result = result.Pass(); | 243 entry->result = result.Pass(); |
245 entry->addr = src_addr.Pass(); | 244 entry->addr = src_addr.Pass(); |
246 entry->data = data.Pass(); | 245 entry->data = data.Pass(); |
247 | 246 |
248 results_.push(entry); | 247 results_.push(entry); |
249 | 248 |
250 if (results_.size() == expected_receive_count_ && run_loop_) { | 249 if (results_.size() == expected_receive_count_ && run_loop_) { |
251 expected_receive_count_ = 0; | 250 expected_receive_count_ = 0; |
252 run_loop_->Quit(); | 251 run_loop_->Quit(); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 | 376 |
378 EXPECT_EQ(static_cast<int>(kDatagramSize), result->result->code); | 377 EXPECT_EQ(static_cast<int>(kDatagramSize), result->result->code); |
379 EXPECT_TRUE(AreEqualArrays( | 378 EXPECT_TRUE(AreEqualArrays( |
380 CreateTestMessage(static_cast<uint8_t>(i), kDatagramSize), | 379 CreateTestMessage(static_cast<uint8_t>(i), kDatagramSize), |
381 result->data)); | 380 result->data)); |
382 } | 381 } |
383 } | 382 } |
384 | 383 |
385 } // namespace service | 384 } // namespace service |
386 } // namespace mojo | 385 } // namespace mojo |
OLD | NEW |