Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1205)

Unified Diff: mojo/public/cpp/bindings/tests/interface_ptr_set_unittest.cc

Issue 2250183003: Make the fuchsia mojo/public repo the source of truth. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mojo/public/cpp/bindings/tests/interface_ptr_set_unittest.cc
diff --git a/mojo/public/cpp/bindings/tests/interface_ptr_set_unittest.cc b/mojo/public/cpp/bindings/tests/interface_ptr_set_unittest.cc
deleted file mode 100644
index adcc30627e1d31b1472b21aa66653afc0ffa9d26..0000000000000000000000000000000000000000
--- a/mojo/public/cpp/bindings/tests/interface_ptr_set_unittest.cc
+++ /dev/null
@@ -1,118 +0,0 @@
-// Copyright 2015 The Chromium 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 "mojo/public/cpp/bindings/interface_ptr_set.h"
-
-#include "gtest/gtest.h"
-#include "mojo/public/cpp/bindings/binding.h"
-#include "mojo/public/cpp/system/macros.h"
-#include "mojo/public/cpp/utility/run_loop.h"
-#include "mojo/public/interfaces/bindings/tests/minimal_interface.mojom.h"
-
-namespace mojo {
-namespace common {
-namespace {
-
-class MinimalInterfaceImpl : public test::MinimalInterface {
- public:
- explicit MinimalInterfaceImpl(
- InterfaceRequest<test::MinimalInterface> request)
- : binding_(this, request.Pass()) {}
-
- void Message() override { call_count_++; }
-
- void CloseMessagePipe() { binding_.Close(); }
-
- int call_count() { return call_count_; }
-
- private:
- Binding<test::MinimalInterface> binding_;
- int call_count_ = 0;
-
- MOJO_DISALLOW_COPY_AND_ASSIGN(MinimalInterfaceImpl);
-};
-
-// Tests all of the functionality of InterfacePtrSet.
-TEST(InterfacePtrSetTest, FullLifeCycle) {
- RunLoop loop;
-
- // Create 10 InterfacePtrs.
- const size_t kNumObjects = 10;
- InterfacePtr<test::MinimalInterface> intrfc_ptrs[kNumObjects];
-
- // Create 10 MinimalInterfaceImpls and 10 message pipes and bind them all
- // together.
- std::unique_ptr<MinimalInterfaceImpl> impls[kNumObjects];
- for (size_t i = 0; i < kNumObjects; i++) {
- impls[i].reset(new MinimalInterfaceImpl(GetProxy(&intrfc_ptrs[i])));
- }
-
- // Move all 10 InterfacePtrs into the set.
- InterfacePtrSet<test::MinimalInterface> intrfc_ptr_set;
- EXPECT_EQ(0u, intrfc_ptr_set.size());
- for (InterfacePtr<test::MinimalInterface>& ptr : intrfc_ptrs) {
- intrfc_ptr_set.AddInterfacePtr(ptr.Pass());
- }
- EXPECT_EQ(kNumObjects, intrfc_ptr_set.size());
-
- // Check that initially all call counts are zero.
- for (const std::unique_ptr<MinimalInterfaceImpl>& impl : impls) {
- EXPECT_EQ(0, impl->call_count());
- }
-
- // Invoke ForAllPtrs().
- size_t num_invocations = 0;
- intrfc_ptr_set.ForAllPtrs([&num_invocations](test::MinimalInterface* dummy) {
- dummy->Message();
- num_invocations++;
- });
- EXPECT_EQ(kNumObjects, num_invocations);
-
- // Check that now all call counts are one.
- loop.RunUntilIdle();
- for (const std::unique_ptr<MinimalInterfaceImpl>& impl : impls) {
- EXPECT_EQ(1, impl->call_count());
- }
-
- // Close the first 5 message pipes. This will (after RunUntilIdle) cause
- // connection errors on the closed pipes which will cause the first five
- // objects to be removed.
- for (size_t i = 0; i < kNumObjects / 2; i++) {
- impls[i]->CloseMessagePipe();
- }
- EXPECT_EQ(kNumObjects, intrfc_ptr_set.size());
- loop.RunUntilIdle();
- EXPECT_EQ(kNumObjects / 2, intrfc_ptr_set.size());
-
- // Invoke ForAllPtrs again on the remaining five pointers
- intrfc_ptr_set.ForAllPtrs(
- [](test::MinimalInterface* dummy) { dummy->Message(); });
- loop.RunUntilIdle();
-
- // Check that now the first five counts are still 1 but the second five
- // counts are two.
- for (size_t i = 0; i < kNumObjects; i++) {
- int expected = (i < kNumObjects / 2 ? 1 : 2);
- EXPECT_EQ(expected, impls[i]->call_count());
- }
-
- // Close all of the MessagePipes and clear the set.
- intrfc_ptr_set.CloseAll();
-
- // Invoke ForAllPtrs() again.
- intrfc_ptr_set.ForAllPtrs(
- [](test::MinimalInterface* dummy) { dummy->Message(); });
- loop.RunUntilIdle();
-
- // Check that the counts are the same as last time.
- for (size_t i = 0; i < kNumObjects; i++) {
- int expected = (i < kNumObjects / 2 ? 1 : 2);
- EXPECT_EQ(expected, impls[i]->call_count());
- }
- EXPECT_EQ(0u, intrfc_ptr_set.size());
-}
-
-} // namespace
-} // namespace common
-} // namespace mojo
« no previous file with comments | « mojo/public/cpp/bindings/tests/handle_passing_unittest.cc ('k') | mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698