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 <utility> | 5 #include <utility> |
6 | 6 |
7 #include "mojo/public/cpp/bindings/binding.h" | 7 #include "mojo/public/cpp/bindings/binding.h" |
8 #include "mojo/public/cpp/bindings/strong_binding.h" | 8 #include "mojo/public/cpp/bindings/strong_binding.h" |
9 #include "mojo/public/cpp/environment/environment.h" | |
10 #include "mojo/public/cpp/utility/run_loop.h" | 9 #include "mojo/public/cpp/utility/run_loop.h" |
11 #include "mojo/public/interfaces/bindings/tests/math_calculator.mojom.h" | 10 #include "mojo/public/interfaces/bindings/tests/math_calculator.mojom.h" |
12 #include "mojo/public/interfaces/bindings/tests/sample_interfaces.mojom.h" | 11 #include "mojo/public/interfaces/bindings/tests/sample_interfaces.mojom.h" |
13 #include "mojo/public/interfaces/bindings/tests/sample_service.mojom.h" | 12 #include "mojo/public/interfaces/bindings/tests/sample_service.mojom.h" |
14 #include "mojo/public/interfaces/bindings/tests/scoping.mojom.h" | 13 #include "mojo/public/interfaces/bindings/tests/scoping.mojom.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
16 | 15 |
17 namespace mojo { | 16 namespace mojo { |
18 namespace test { | 17 namespace test { |
19 namespace { | 18 namespace { |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 int64_t integer_; | 187 int64_t integer_; |
189 }; | 188 }; |
190 | 189 |
191 class InterfacePtrTest : public testing::Test { | 190 class InterfacePtrTest : public testing::Test { |
192 public: | 191 public: |
193 ~InterfacePtrTest() override { loop_.RunUntilIdle(); } | 192 ~InterfacePtrTest() override { loop_.RunUntilIdle(); } |
194 | 193 |
195 void PumpMessages() { loop_.RunUntilIdle(); } | 194 void PumpMessages() { loop_.RunUntilIdle(); } |
196 | 195 |
197 private: | 196 private: |
198 Environment env_; | |
199 RunLoop loop_; | 197 RunLoop loop_; |
200 }; | 198 }; |
201 | 199 |
202 TEST_F(InterfacePtrTest, IsBound) { | 200 TEST_F(InterfacePtrTest, IsBound) { |
203 math::CalculatorPtr calc; | 201 math::CalculatorPtr calc; |
204 EXPECT_FALSE(calc.is_bound()); | 202 EXPECT_FALSE(calc.is_bound()); |
205 EXPECT_FALSE(calc); | 203 EXPECT_FALSE(calc); |
206 MathCalculatorImpl calc_impl(GetProxy(&calc)); | 204 MathCalculatorImpl calc_impl(GetProxy(&calc)); |
207 EXPECT_TRUE(calc.is_bound()); | 205 EXPECT_TRUE(calc.is_bound()); |
208 EXPECT_TRUE(calc); | 206 EXPECT_TRUE(calc); |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 | 477 |
480 private: | 478 private: |
481 double total_ = 0.0; | 479 double total_ = 0.0; |
482 bool* error_received_; | 480 bool* error_received_; |
483 bool* destroyed_; | 481 bool* destroyed_; |
484 | 482 |
485 StrongBinding<math::Calculator> binding_; | 483 StrongBinding<math::Calculator> binding_; |
486 }; | 484 }; |
487 | 485 |
488 TEST(StrongConnectorTest, Math) { | 486 TEST(StrongConnectorTest, Math) { |
489 Environment env; | |
490 RunLoop loop; | 487 RunLoop loop; |
491 | 488 |
492 bool error_received = false; | 489 bool error_received = false; |
493 bool destroyed = false; | 490 bool destroyed = false; |
494 MessagePipe pipe; | 491 MessagePipe pipe; |
495 new StrongMathCalculatorImpl(pipe.handle0.Pass(), &error_received, | 492 new StrongMathCalculatorImpl(pipe.handle0.Pass(), &error_received, |
496 &destroyed); | 493 &destroyed); |
497 | 494 |
498 math::CalculatorPtr calc; | 495 math::CalculatorPtr calc; |
499 calc.Bind(InterfaceHandle<math::Calculator>(pipe.handle1.Pass(), 0u)); | 496 calc.Bind(InterfaceHandle<math::Calculator>(pipe.handle1.Pass(), 0u)); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 | 545 |
549 private: | 546 private: |
550 double total_ = 0.0; | 547 double total_ = 0.0; |
551 bool* error_received_; | 548 bool* error_received_; |
552 bool* destroyed_; | 549 bool* destroyed_; |
553 | 550 |
554 Binding<math::Calculator> binding_; | 551 Binding<math::Calculator> binding_; |
555 }; | 552 }; |
556 | 553 |
557 TEST(WeakConnectorTest, Math) { | 554 TEST(WeakConnectorTest, Math) { |
558 Environment env; | |
559 RunLoop loop; | 555 RunLoop loop; |
560 | 556 |
561 bool error_received = false; | 557 bool error_received = false; |
562 bool destroyed = false; | 558 bool destroyed = false; |
563 MessagePipe pipe; | 559 MessagePipe pipe; |
564 WeakMathCalculatorImpl impl(pipe.handle0.Pass(), &error_received, &destroyed); | 560 WeakMathCalculatorImpl impl(pipe.handle0.Pass(), &error_received, &destroyed); |
565 | 561 |
566 math::CalculatorPtr calc; | 562 math::CalculatorPtr calc; |
567 calc.Bind(InterfaceHandle<math::Calculator>(pipe.handle1.Pass(), 0u)); | 563 calc.Bind(InterfaceHandle<math::Calculator>(pipe.handle1.Pass(), 0u)); |
568 | 564 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
656 // While B & C have fallen out of scope, the pipes will remain until they are | 652 // While B & C have fallen out of scope, the pipes will remain until they are |
657 // flushed. | 653 // flushed. |
658 EXPECT_FALSE(a_impl.d_called()); | 654 EXPECT_FALSE(a_impl.d_called()); |
659 PumpMessages(); | 655 PumpMessages(); |
660 EXPECT_TRUE(a_impl.d_called()); | 656 EXPECT_TRUE(a_impl.d_called()); |
661 } | 657 } |
662 | 658 |
663 } // namespace | 659 } // namespace |
664 } // namespace test | 660 } // namespace test |
665 } // namespace mojo | 661 } // namespace mojo |
OLD | NEW |