| 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <ostream> | 6 #include <ostream> |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "mojo/public/cpp/environment/environment.h" | 9 #include "mojo/public/cpp/environment/environment.h" |
| 10 #include "mojo/public/cpp/system/macros.h" | 10 #include "mojo/public/cpp/system/macros.h" |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 | 249 |
| 250 if (i % 2 == 1) | 250 if (i % 2 == 1) |
| 251 std::cout << " "; | 251 std::cout << " "; |
| 252 if (i % 8 == 7) | 252 if (i % 8 == 7) |
| 253 std::cout << " "; | 253 std::cout << " "; |
| 254 } | 254 } |
| 255 } | 255 } |
| 256 | 256 |
| 257 class ServiceImpl : public Service { | 257 class ServiceImpl : public Service { |
| 258 public: | 258 public: |
| 259 virtual void Frobinate(FooPtr foo, BazOptions baz, PortPtr port) override { | 259 void Frobinate(FooPtr foo, BazOptions baz, PortPtr port) override { |
| 260 // Users code goes here to handle the incoming Frobinate message. | 260 // Users code goes here to handle the incoming Frobinate message. |
| 261 | 261 |
| 262 // We mainly check that we're given the expected arguments. | 262 // We mainly check that we're given the expected arguments. |
| 263 EXPECT_FALSE(foo.is_null()); | 263 EXPECT_FALSE(foo.is_null()); |
| 264 if (!foo.is_null()) | 264 if (!foo.is_null()) |
| 265 CheckFoo(*foo); | 265 CheckFoo(*foo); |
| 266 EXPECT_EQ(BAZ_OPTIONS_EXTRA, baz); | 266 EXPECT_EQ(BAZ_OPTIONS_EXTRA, baz); |
| 267 | 267 |
| 268 if (g_dump_message_as_text) { | 268 if (g_dump_message_as_text) { |
| 269 // Also dump the Foo structure and all of its members. | 269 // Also dump the Foo structure and all of its members. |
| 270 std::cout << "Frobinate:" << std::endl; | 270 std::cout << "Frobinate:" << std::endl; |
| 271 int depth = 1; | 271 int depth = 1; |
| 272 Print(depth, "foo", foo); | 272 Print(depth, "foo", foo); |
| 273 Print(depth, "baz", baz); | 273 Print(depth, "baz", baz); |
| 274 Print(depth, "port", port.get()); | 274 Print(depth, "port", port.get()); |
| 275 } | 275 } |
| 276 } | 276 } |
| 277 | 277 |
| 278 virtual void GetPort(mojo::InterfaceRequest<Port> port_request) override {} | 278 void GetPort(mojo::InterfaceRequest<Port> port_request) override {} |
| 279 }; | 279 }; |
| 280 | 280 |
| 281 class ServiceProxyImpl : public ServiceProxy { | 281 class ServiceProxyImpl : public ServiceProxy { |
| 282 public: | 282 public: |
| 283 explicit ServiceProxyImpl(mojo::MessageReceiverWithResponder* receiver) | 283 explicit ServiceProxyImpl(mojo::MessageReceiverWithResponder* receiver) |
| 284 : ServiceProxy(receiver) {} | 284 : ServiceProxy(receiver) {} |
| 285 }; | 285 }; |
| 286 | 286 |
| 287 class SimpleMessageReceiver : public mojo::MessageReceiverWithResponder { | 287 class SimpleMessageReceiver : public mojo::MessageReceiverWithResponder { |
| 288 public: | 288 public: |
| 289 virtual bool Accept(mojo::Message* message) override { | 289 bool Accept(mojo::Message* message) override { |
| 290 // Imagine some IPC happened here. | 290 // Imagine some IPC happened here. |
| 291 | 291 |
| 292 if (g_dump_message_as_hex) { | 292 if (g_dump_message_as_hex) { |
| 293 DumpHex(reinterpret_cast<const uint8_t*>(message->data()), | 293 DumpHex(reinterpret_cast<const uint8_t*>(message->data()), |
| 294 message->data_num_bytes()); | 294 message->data_num_bytes()); |
| 295 } | 295 } |
| 296 | 296 |
| 297 // In the receiving process, an implementation of ServiceStub is known to | 297 // In the receiving process, an implementation of ServiceStub is known to |
| 298 // the system. It receives the incoming message. | 298 // the system. It receives the incoming message. |
| 299 ServiceImpl impl; | 299 ServiceImpl impl; |
| 300 | 300 |
| 301 ServiceStub stub; | 301 ServiceStub stub; |
| 302 stub.set_sink(&impl); | 302 stub.set_sink(&impl); |
| 303 return stub.Accept(message); | 303 return stub.Accept(message); |
| 304 } | 304 } |
| 305 | 305 |
| 306 virtual bool AcceptWithResponder(mojo::Message* message, | 306 bool AcceptWithResponder(mojo::Message* message, |
| 307 mojo::MessageReceiver* responder) override { | 307 mojo::MessageReceiver* responder) override { |
| 308 return false; | 308 return false; |
| 309 } | 309 } |
| 310 }; | 310 }; |
| 311 | 311 |
| 312 class BindingsSampleTest : public testing::Test { | 312 class BindingsSampleTest : public testing::Test { |
| 313 public: | 313 public: |
| 314 BindingsSampleTest() {} | 314 BindingsSampleTest() {} |
| 315 virtual ~BindingsSampleTest() {} | 315 virtual ~BindingsSampleTest() {} |
| 316 | 316 |
| 317 private: | 317 private: |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 ASSERT_FALSE(defaults->a22.is_null()); | 368 ASSERT_FALSE(defaults->a22.is_null()); |
| 369 EXPECT_EQ(imported::SHAPE_RECTANGLE, defaults->a22->shape); | 369 EXPECT_EQ(imported::SHAPE_RECTANGLE, defaults->a22->shape); |
| 370 EXPECT_EQ(imported::COLOR_BLACK, defaults->a22->color); | 370 EXPECT_EQ(imported::COLOR_BLACK, defaults->a22->color); |
| 371 EXPECT_EQ(0xFFFFFFFFFFFFFFFFULL, defaults->a23); | 371 EXPECT_EQ(0xFFFFFFFFFFFFFFFFULL, defaults->a23); |
| 372 EXPECT_EQ(0x123456789, defaults->a24); | 372 EXPECT_EQ(0x123456789, defaults->a24); |
| 373 EXPECT_EQ(-0x123456789, defaults->a25); | 373 EXPECT_EQ(-0x123456789, defaults->a25); |
| 374 } | 374 } |
| 375 | 375 |
| 376 } // namespace | 376 } // namespace |
| 377 } // namespace sample | 377 } // namespace sample |
| OLD | NEW |