| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/common/weak_binding_set.h" | 5 #include "mojo/common/binding_set.h" |
| 6 | 6 |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "mojo/common/message_pump_mojo.h" | 8 #include "mojo/common/message_pump_mojo.h" |
| 9 #include "mojo/common/test_interfaces.mojom.h" | 9 #include "mojo/common/test_interfaces.mojom.h" |
| 10 #include "mojo/public/cpp/bindings/binding.h" | 10 #include "mojo/public/cpp/bindings/binding.h" |
| 11 #include "mojo/public/cpp/bindings/interface_request.h" | 11 #include "mojo/public/cpp/bindings/interface_request.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 13 |
| 14 namespace mojo { | 14 namespace mojo { |
| 15 namespace common { | 15 namespace common { |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 class DummyImpl : public tests::Dummy { | 18 class DummyImpl : public tests::Dummy { |
| 19 public: | 19 public: |
| 20 DummyImpl() {} | 20 DummyImpl() {} |
| 21 | 21 |
| 22 void Foo() override { call_count_++; } | 22 void Foo() override { call_count_++; } |
| 23 | 23 |
| 24 int call_count() const { return call_count_; } | 24 int call_count() const { return call_count_; } |
| 25 | 25 |
| 26 private: | 26 private: |
| 27 int call_count_ = 0; | 27 int call_count_ = 0; |
| 28 | 28 |
| 29 DISALLOW_COPY_AND_ASSIGN(DummyImpl); | 29 DISALLOW_COPY_AND_ASSIGN(DummyImpl); |
| 30 }; | 30 }; |
| 31 | 31 |
| 32 // Tests all of the functionality of WeakBindingSet. | 32 // Tests all of the functionality of BindingSet. |
| 33 TEST(WeakBindingSet, FullLifeCycleTest) { | 33 TEST(BindingSetTest, FullLifeCycle) { |
| 34 base::MessageLoop loop(MessagePumpMojo::Create()); | 34 base::MessageLoop loop(MessagePumpMojo::Create()); |
| 35 | 35 |
| 36 // Create 10 InterfacePtrs and DummyImpls. | 36 // Create 10 InterfacePtrs and DummyImpls. |
| 37 const size_t kNumObjects = 10; | 37 const size_t kNumObjects = 10; |
| 38 InterfacePtr<tests::Dummy> intrfc_ptrs[kNumObjects]; | 38 InterfacePtr<tests::Dummy> intrfc_ptrs[kNumObjects]; |
| 39 DummyImpl impls[kNumObjects]; | 39 DummyImpl impls[kNumObjects]; |
| 40 | 40 |
| 41 // Create 10 message pipes, bind everything together, and add the | 41 // Create 10 message pipes, bind everything together, and add the |
| 42 // bindings to binding_set. | 42 // bindings to binding_set. |
| 43 WeakBindingSet<tests::Dummy> binding_set; | 43 BindingSet<tests::Dummy> binding_set; |
| 44 EXPECT_EQ(0u, binding_set.size()); | 44 EXPECT_EQ(0u, binding_set.size()); |
| 45 for (size_t i = 0; i < kNumObjects; i++) { | 45 for (size_t i = 0; i < kNumObjects; i++) { |
| 46 binding_set.AddBinding(&impls[i], GetProxy(&intrfc_ptrs[i])); | 46 binding_set.AddBinding(&impls[i], GetProxy(&intrfc_ptrs[i])); |
| 47 } | 47 } |
| 48 EXPECT_EQ(kNumObjects, binding_set.size()); | 48 EXPECT_EQ(kNumObjects, binding_set.size()); |
| 49 | 49 |
| 50 // Check that initially all call counts are zero. | 50 // Check that initially all call counts are zero. |
| 51 for (const auto& impl : impls) { | 51 for (const auto& impl : impls) { |
| 52 EXPECT_EQ(0, impl.call_count()); | 52 EXPECT_EQ(0, impl.call_count()); |
| 53 } | 53 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 // Check that the call counts are the same as before. | 99 // Check that the call counts are the same as before. |
| 100 for (size_t i = 0; i < kNumObjects; i++) { | 100 for (size_t i = 0; i < kNumObjects; i++) { |
| 101 int expected = (i < kNumObjects / 2 ? 1 : 2); | 101 int expected = (i < kNumObjects / 2 ? 1 : 2); |
| 102 EXPECT_EQ(expected, impls[i].call_count()); | 102 EXPECT_EQ(expected, impls[i].call_count()); |
| 103 } | 103 } |
| 104 } | 104 } |
| 105 | 105 |
| 106 } // namespace | 106 } // namespace |
| 107 } // namespace common | 107 } // namespace common |
| 108 } // namespace mojo | 108 } // namespace mojo |
| OLD | NEW |