| // Copyright 2018 The Fuchsia Authors. All rights reserved. | |
| // Use of this source code is governed by a BSD-style license that can be | |
| // found in the LICENSE file. | |
| #include "lib/fidl/cpp/thread_safe_binding_set.h" | |
| #include <gtest/gtest.h> | |
| #include "lib/fidl/cpp/test/async_loop_for_test.h" | |
| #include "lib/fidl/cpp/test/frobinator_impl.h" | |
| namespace fidl { | |
| namespace { | |
| TEST(DeprecatedBrokenBindingSet, Trivial) { | |
| DeprecatedBrokenBindingSet<fidl::test::frobinator::Frobinator> binding_set; | |
| } | |
| TEST(DeprecatedBrokenBindingSet, Control) { | |
| constexpr size_t kCount = 10; | |
| fidl::test::frobinator::FrobinatorPtr ptrs[kCount]; | |
| test::FrobinatorImpl impls[kCount]; | |
| DeprecatedBrokenBindingSet<fidl::test::frobinator::Frobinator> binding_set; | |
| fidl::test::AsyncLoopForTest loop; | |
| for (size_t i = 0; i < kCount; ++i) { | |
| if (i % 2 == 0) { | |
| binding_set.AddBinding(&impls[i], ptrs[i].NewRequest(), loop.dispatcher()); | |
| } else { | |
| ptrs[i] = binding_set.AddBinding(&impls[i], loop.dispatcher()).Bind(); | |
| } | |
| } | |
| for (const auto& impl : impls) | |
| EXPECT_TRUE(impl.frobs.empty()); | |
| for (auto& ptr : ptrs) | |
| ptr->Frob("one"); | |
| loop.RunUntilIdle(); | |
| for (const auto& impl : impls) | |
| EXPECT_EQ(1u, impl.frobs.size()); | |
| for (size_t i = 0; i < kCount / 2; ++i) | |
| ptrs[i].Unbind(); | |
| loop.RunUntilIdle(); | |
| for (size_t i = kCount / 2; i < kCount; ++i) | |
| ptrs[i]->Frob("two"); | |
| loop.RunUntilIdle(); | |
| for (size_t i = 0; i < kCount; ++i) { | |
| size_t expected = (i < kCount / 2 ? 1 : 2); | |
| EXPECT_EQ(expected, impls[i].frobs.size()); | |
| } | |
| binding_set.CloseAll(); | |
| for (size_t i = kCount / 2; i < kCount; ++i) | |
| ptrs[i]->Frob("three"); | |
| loop.RunUntilIdle(); | |
| for (size_t i = 0; i < kCount; ++i) { | |
| size_t expected = (i < kCount / 2 ? 1 : 2); | |
| EXPECT_EQ(expected, impls[i].frobs.size()); | |
| } | |
| } | |
| } // namespace | |
| } // namespace fidl |