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

Unified Diff: mojo/edk/system/handle_table_unittest.cc

Issue 1949153002: EDK: Add HandleTable::AddHandleVector(). (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 7 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
« no previous file with comments | « mojo/edk/system/handle_table.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/edk/system/handle_table_unittest.cc
diff --git a/mojo/edk/system/handle_table_unittest.cc b/mojo/edk/system/handle_table_unittest.cc
index a239962514d698a9cbfd914ab849f351ae7cf0d4..33c983d07b21662dbe52cd068faa960d4125d88a 100644
--- a/mojo/edk/system/handle_table_unittest.cc
+++ b/mojo/edk/system/handle_table_unittest.cc
@@ -4,6 +4,8 @@
#include "mojo/edk/system/handle_table.h"
+#include <vector>
+
#include "mojo/edk/system/dispatcher.h"
#include "mojo/edk/system/handle.h"
#include "mojo/edk/system/mock_simple_dispatcher.h"
@@ -175,6 +177,73 @@ TEST(HandleTableTest, AddHandlePairTooMany) {
EXPECT_EQ(MOJO_RESULT_OK, d4->Close());
}
+TEST(HandleTableTest, AddHandleVector) {
+ static constexpr size_t kNumHandles = 10u;
+
+ HandleTable ht(1000u);
+
+ HandleVector handles;
+ std::vector<RefPtr<Dispatcher>> dispatchers;
+ for (size_t i = 0u; i < kNumHandles; i++) {
+ dispatchers.push_back(MakeRefCounted<test::MockSimpleDispatcher>());
+ handles.push_back(
+ Handle(dispatchers.back().Clone(), MOJO_HANDLE_RIGHT_NONE));
+ ASSERT_TRUE(handles[i]) << i;
+ }
+
+ std::vector<MojoHandle> handle_values(kNumHandles, MOJO_HANDLE_INVALID);
+
+ ASSERT_TRUE(ht.AddHandleVector(&handles, handle_values.data()));
+
+ for (size_t i = 0u; i < kNumHandles; i++) {
+ ASSERT_NE(handle_values[i], MOJO_HANDLE_INVALID) << i;
+
+ RefPtr<Dispatcher> d;
+ ASSERT_EQ(MOJO_RESULT_OK, ht.GetAndRemoveDispatcher(handle_values[i], &d))
+ << i;
+ ASSERT_EQ(dispatchers[i], d) << i;
+
+ EXPECT_EQ(MOJO_RESULT_OK, dispatchers[i]->Close()) << i;
+ }
+}
+
+TEST(HandleTableTest, AddHandleVectorTooMany) {
+ static constexpr size_t kHandleTableSize = 10u;
+ static constexpr size_t kNumHandles = kHandleTableSize + 1u;
+
+ HandleTable ht(kHandleTableSize);
+
+ HandleVector handles;
+ std::vector<RefPtr<Dispatcher>> dispatchers;
+ for (size_t i = 0u; i < kNumHandles; i++) {
+ dispatchers.push_back(MakeRefCounted<test::MockSimpleDispatcher>());
+ handles.push_back(
+ Handle(dispatchers.back().Clone(), MOJO_HANDLE_RIGHT_NONE));
+ ASSERT_TRUE(handles[i]) << i;
+ }
+
+ std::vector<MojoHandle> handle_values(kNumHandles, MOJO_HANDLE_INVALID);
+
+ EXPECT_FALSE(ht.AddHandleVector(&handles, handle_values.data()));
+
+ handles.pop_back();
+ handle_values.pop_back();
+
+ ASSERT_TRUE(ht.AddHandleVector(&handles, handle_values.data()));
+
+ for (size_t i = 0u; i < kNumHandles - 1u; i++) {
+ ASSERT_NE(handle_values[i], MOJO_HANDLE_INVALID) << i;
+
+ RefPtr<Dispatcher> d;
+ ASSERT_EQ(MOJO_RESULT_OK, ht.GetAndRemoveDispatcher(handle_values[i], &d))
+ << i;
+ ASSERT_EQ(dispatchers[i], d) << i;
+ }
+
+ for (size_t i = 0u; i < kNumHandles; i++)
+ EXPECT_EQ(MOJO_RESULT_OK, dispatchers[i]->Close()) << i;
+}
+
} // namespace
} // namespace system
} // namespace mojo
« no previous file with comments | « mojo/edk/system/handle_table.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698