| 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 "mojo/public/cpp/bindings/binding.h" | 5 #include "mojo/public/cpp/bindings/binding.h" |
| 6 #include "mojo/public/cpp/bindings/error_handler.h" | 6 #include "mojo/public/cpp/bindings/error_handler.h" |
| 7 #include "mojo/public/cpp/bindings/strong_binding.h" | 7 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 8 #include "mojo/public/cpp/environment/environment.h" | 8 #include "mojo/public/cpp/environment/environment.h" |
| 9 #include "mojo/public/cpp/utility/run_loop.h" | 9 #include "mojo/public/cpp/utility/run_loop.h" |
| 10 #include "mojo/public/interfaces/bindings/tests/math_calculator.mojom.h" | 10 #include "mojo/public/interfaces/bindings/tests/math_calculator.mojom.h" |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 TEST_F(InterfacePtrTest, Resettable) { | 259 TEST_F(InterfacePtrTest, Resettable) { |
| 260 math::CalculatorPtr a; | 260 math::CalculatorPtr a; |
| 261 | 261 |
| 262 EXPECT_TRUE(!a); | 262 EXPECT_TRUE(!a); |
| 263 | 263 |
| 264 MessagePipe pipe; | 264 MessagePipe pipe; |
| 265 | 265 |
| 266 // Save this so we can test it later. | 266 // Save this so we can test it later. |
| 267 Handle handle = pipe.handle0.get(); | 267 Handle handle = pipe.handle0.get(); |
| 268 | 268 |
| 269 a = MakeProxy<math::Calculator>(pipe.handle0.Pass()); | 269 a = MakeProxy(InterfacePtrInfo<math::Calculator>(pipe.handle0.Pass(), 0u)); |
| 270 | 270 |
| 271 EXPECT_FALSE(!a); | 271 EXPECT_FALSE(!a); |
| 272 | 272 |
| 273 a.reset(); | 273 a.reset(); |
| 274 | 274 |
| 275 EXPECT_TRUE(!a); | 275 EXPECT_TRUE(!a); |
| 276 EXPECT_FALSE(a.internal_state()->router_for_testing()); | 276 EXPECT_FALSE(a.internal_state()->router_for_testing()); |
| 277 | 277 |
| 278 // Test that handle was closed. | 278 // Test that handle was closed. |
| 279 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, CloseRaw(handle)); | 279 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, CloseRaw(handle)); |
| 280 } | 280 } |
| 281 | 281 |
| 282 TEST_F(InterfacePtrTest, BindInvalidHandle) { | 282 TEST_F(InterfacePtrTest, BindInvalidHandle) { |
| 283 math::CalculatorPtr ptr; | 283 math::CalculatorPtr ptr; |
| 284 EXPECT_FALSE(ptr.get()); | 284 EXPECT_FALSE(ptr.get()); |
| 285 EXPECT_FALSE(ptr); | 285 EXPECT_FALSE(ptr); |
| 286 | 286 |
| 287 ptr.Bind(ScopedMessagePipeHandle()); | 287 ptr.Bind(InterfacePtrInfo<math::Calculator>()); |
| 288 EXPECT_FALSE(ptr.get()); | 288 EXPECT_FALSE(ptr.get()); |
| 289 EXPECT_FALSE(ptr); | 289 EXPECT_FALSE(ptr); |
| 290 } | 290 } |
| 291 | 291 |
| 292 TEST_F(InterfacePtrTest, EncounteredError) { | 292 TEST_F(InterfacePtrTest, EncounteredError) { |
| 293 math::CalculatorPtr proxy; | 293 math::CalculatorPtr proxy; |
| 294 MathCalculatorImpl calc_impl(GetProxy(&proxy)); | 294 MathCalculatorImpl calc_impl(GetProxy(&proxy)); |
| 295 | 295 |
| 296 MathCalculatorUI calculator_ui(proxy.Pass()); | 296 MathCalculatorUI calculator_ui(proxy.Pass()); |
| 297 | 297 |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 Environment env; | 479 Environment env; |
| 480 RunLoop loop; | 480 RunLoop loop; |
| 481 | 481 |
| 482 bool error_received = false; | 482 bool error_received = false; |
| 483 bool destroyed = false; | 483 bool destroyed = false; |
| 484 MessagePipe pipe; | 484 MessagePipe pipe; |
| 485 new StrongMathCalculatorImpl(pipe.handle0.Pass(), &error_received, | 485 new StrongMathCalculatorImpl(pipe.handle0.Pass(), &error_received, |
| 486 &destroyed); | 486 &destroyed); |
| 487 | 487 |
| 488 math::CalculatorPtr calc; | 488 math::CalculatorPtr calc; |
| 489 calc.Bind(pipe.handle1.Pass()); | 489 calc.Bind(InterfacePtrInfo<math::Calculator>(pipe.handle1.Pass(), 0u)); |
| 490 | 490 |
| 491 { | 491 { |
| 492 // Suppose this is instantiated in a process that has the other end of the | 492 // Suppose this is instantiated in a process that has the other end of the |
| 493 // message pipe. | 493 // message pipe. |
| 494 MathCalculatorUI calculator_ui(calc.Pass()); | 494 MathCalculatorUI calculator_ui(calc.Pass()); |
| 495 | 495 |
| 496 calculator_ui.Add(2.0); | 496 calculator_ui.Add(2.0); |
| 497 calculator_ui.Multiply(5.0); | 497 calculator_ui.Multiply(5.0); |
| 498 | 498 |
| 499 loop.RunUntilIdle(); | 499 loop.RunUntilIdle(); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 TEST(WeakConnectorTest, Math) { | 549 TEST(WeakConnectorTest, Math) { |
| 550 Environment env; | 550 Environment env; |
| 551 RunLoop loop; | 551 RunLoop loop; |
| 552 | 552 |
| 553 bool error_received = false; | 553 bool error_received = false; |
| 554 bool destroyed = false; | 554 bool destroyed = false; |
| 555 MessagePipe pipe; | 555 MessagePipe pipe; |
| 556 WeakMathCalculatorImpl impl(pipe.handle0.Pass(), &error_received, &destroyed); | 556 WeakMathCalculatorImpl impl(pipe.handle0.Pass(), &error_received, &destroyed); |
| 557 | 557 |
| 558 math::CalculatorPtr calc; | 558 math::CalculatorPtr calc; |
| 559 calc.Bind(pipe.handle1.Pass()); | 559 calc.Bind(InterfacePtrInfo<math::Calculator>(pipe.handle1.Pass(), 0u)); |
| 560 | 560 |
| 561 { | 561 { |
| 562 // Suppose this is instantiated in a process that has the other end of the | 562 // Suppose this is instantiated in a process that has the other end of the |
| 563 // message pipe. | 563 // message pipe. |
| 564 MathCalculatorUI calculator_ui(calc.Pass()); | 564 MathCalculatorUI calculator_ui(calc.Pass()); |
| 565 | 565 |
| 566 calculator_ui.Add(2.0); | 566 calculator_ui.Add(2.0); |
| 567 calculator_ui.Multiply(5.0); | 567 calculator_ui.Multiply(5.0); |
| 568 | 568 |
| 569 loop.RunUntilIdle(); | 569 loop.RunUntilIdle(); |
| 570 | 570 |
| 571 EXPECT_EQ(10.0, calculator_ui.GetOutput()); | 571 EXPECT_EQ(10.0, calculator_ui.GetOutput()); |
| 572 EXPECT_FALSE(error_received); | 572 EXPECT_FALSE(error_received); |
| 573 EXPECT_FALSE(destroyed); | 573 EXPECT_FALSE(destroyed); |
| 574 // Destroying calculator_ui should close the pipe and generate an error on | 574 // Destroying calculator_ui should close the pipe and generate an error on |
| 575 // the other | 575 // the other |
| 576 // end which will destroy the instance since it is strongly bound. | 576 // end which will destroy the instance since it is strongly bound. |
| 577 } | 577 } |
| 578 | 578 |
| 579 loop.RunUntilIdle(); | 579 loop.RunUntilIdle(); |
| 580 EXPECT_TRUE(error_received); | 580 EXPECT_TRUE(error_received); |
| 581 EXPECT_FALSE(destroyed); | 581 EXPECT_FALSE(destroyed); |
| 582 } | 582 } |
| 583 | 583 |
| 584 } // namespace | 584 } // namespace |
| 585 } // namespace test | 585 } // namespace test |
| 586 } // namespace mojo | 586 } // namespace mojo |
| OLD | NEW |