OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <algorithm> | 5 #include <algorithm> |
6 #include <ostream> | 6 #include <ostream> |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "mojo/public/tests/simple_bindings_support.h" | 9 #include "mojo/public/tests/simple_bindings_support.h" |
10 #include "mojom/sample_service.h" | 10 #include "mojom/sample_service.h" |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 continue; | 231 continue; |
232 } | 232 } |
233 | 233 |
234 if (i % 2 == 1) | 234 if (i % 2 == 1) |
235 std::cout << " "; | 235 std::cout << " "; |
236 if (i % 8 == 7) | 236 if (i % 8 == 7) |
237 std::cout << " "; | 237 std::cout << " "; |
238 } | 238 } |
239 } | 239 } |
240 | 240 |
241 class ServiceImpl : public ServiceStub { | 241 class ServiceImpl : public Service { |
242 public: | 242 public: |
243 virtual void Frobinate(const Foo& foo, int32_t baz, | 243 virtual void Frobinate(const Foo& foo, int32_t baz, |
244 mojo::ScopedMessagePipeHandle port) | 244 mojo::ScopedMessagePipeHandle port) |
245 MOJO_OVERRIDE { | 245 MOJO_OVERRIDE { |
246 // Users code goes here to handle the incoming Frobinate message. | 246 // Users code goes here to handle the incoming Frobinate message. |
247 | 247 |
248 // We mainly check that we're given the expected arguments. | 248 // We mainly check that we're given the expected arguments. |
249 CheckFoo(foo); | 249 CheckFoo(foo); |
250 EXPECT_EQ(BAZ_EXTRA, baz); | 250 EXPECT_EQ(BAZ_EXTRA, baz); |
251 | 251 |
(...skipping 14 matching lines...) Expand all Loading... |
266 | 266 |
267 if (g_dump_message_as_hex) { | 267 if (g_dump_message_as_hex) { |
268 DumpHex(reinterpret_cast<const uint8_t*>(message->data), | 268 DumpHex(reinterpret_cast<const uint8_t*>(message->data), |
269 message->data->header.num_bytes); | 269 message->data->header.num_bytes); |
270 } | 270 } |
271 | 271 |
272 // In the receiving process, an implementation of ServiceStub is known to | 272 // In the receiving process, an implementation of ServiceStub is known to |
273 // the system. It receives the incoming message. | 273 // the system. It receives the incoming message. |
274 ServiceImpl impl; | 274 ServiceImpl impl; |
275 | 275 |
276 ServiceStub* stub = &impl; | 276 ServiceStub stub(&impl); |
277 return stub->Accept(message); | 277 return stub.Accept(message); |
278 } | 278 } |
279 }; | 279 }; |
280 | 280 |
281 TEST(BindingsSampleTest, Basic) { | 281 TEST(BindingsSampleTest, Basic) { |
282 mojo::test::SimpleBindingsSupport bindings_support; | 282 mojo::test::SimpleBindingsSupport bindings_support; |
283 SimpleMessageReceiver receiver; | 283 SimpleMessageReceiver receiver; |
284 | 284 |
285 // User has a proxy to a Service somehow. | 285 // User has a proxy to a Service somehow. |
286 Service* service = new ServiceProxy(&receiver); | 286 Service* service = new ServiceProxy(&receiver); |
287 | 287 |
288 // User constructs a message to send. | 288 // User constructs a message to send. |
289 | 289 |
290 // Notice that it doesn't matter in what order the structs / arrays are | 290 // Notice that it doesn't matter in what order the structs / arrays are |
291 // allocated. Here, the various members of Foo are allocated before Foo is | 291 // allocated. Here, the various members of Foo are allocated before Foo is |
292 // allocated. | 292 // allocated. |
293 | 293 |
294 mojo::AllocationScope scope; | 294 mojo::AllocationScope scope; |
295 | 295 |
296 Foo foo = MakeFoo(); | 296 Foo foo = MakeFoo(); |
297 CheckFoo(foo); | 297 CheckFoo(foo); |
298 | 298 |
299 mojo::ScopedMessagePipeHandle port0, port1; | 299 mojo::ScopedMessagePipeHandle port0, port1; |
300 mojo::CreateMessagePipe(&port0, &port1); | 300 mojo::CreateMessagePipe(&port0, &port1); |
301 | 301 |
302 service->Frobinate(foo, Service::BAZ_EXTRA, port0.Pass()); | 302 service->Frobinate(foo, Service::BAZ_EXTRA, port0.Pass()); |
303 } | 303 } |
304 | 304 |
305 } // namespace sample | 305 } // namespace sample |
OLD | NEW |