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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « mojo/edk/system/handle_table.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/edk/system/handle_table.h" 5 #include "mojo/edk/system/handle_table.h"
6 6
7 #include <vector>
8
7 #include "mojo/edk/system/dispatcher.h" 9 #include "mojo/edk/system/dispatcher.h"
8 #include "mojo/edk/system/handle.h" 10 #include "mojo/edk/system/handle.h"
9 #include "mojo/edk/system/mock_simple_dispatcher.h" 11 #include "mojo/edk/system/mock_simple_dispatcher.h"
10 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
11 13
12 using mojo::util::MakeRefCounted; 14 using mojo::util::MakeRefCounted;
13 using mojo::util::RefPtr; 15 using mojo::util::RefPtr;
14 16
15 namespace mojo { 17 namespace mojo {
16 namespace system { 18 namespace system {
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 d = nullptr; 170 d = nullptr;
169 ASSERT_EQ(MOJO_RESULT_OK, ht.GetAndRemoveDispatcher(h4, &d)); 171 ASSERT_EQ(MOJO_RESULT_OK, ht.GetAndRemoveDispatcher(h4, &d));
170 ASSERT_EQ(d4, d); 172 ASSERT_EQ(d4, d);
171 173
172 EXPECT_EQ(MOJO_RESULT_OK, d1->Close()); 174 EXPECT_EQ(MOJO_RESULT_OK, d1->Close());
173 EXPECT_EQ(MOJO_RESULT_OK, d2->Close()); 175 EXPECT_EQ(MOJO_RESULT_OK, d2->Close());
174 EXPECT_EQ(MOJO_RESULT_OK, d3->Close()); 176 EXPECT_EQ(MOJO_RESULT_OK, d3->Close());
175 EXPECT_EQ(MOJO_RESULT_OK, d4->Close()); 177 EXPECT_EQ(MOJO_RESULT_OK, d4->Close());
176 } 178 }
177 179
180 TEST(HandleTableTest, AddHandleVector) {
181 static constexpr size_t kNumHandles = 10u;
182
183 HandleTable ht(1000u);
184
185 HandleVector handles;
186 std::vector<RefPtr<Dispatcher>> dispatchers;
187 for (size_t i = 0u; i < kNumHandles; i++) {
188 dispatchers.push_back(MakeRefCounted<test::MockSimpleDispatcher>());
189 handles.push_back(
190 Handle(dispatchers.back().Clone(), MOJO_HANDLE_RIGHT_NONE));
191 ASSERT_TRUE(handles[i]) << i;
192 }
193
194 std::vector<MojoHandle> handle_values(kNumHandles, MOJO_HANDLE_INVALID);
195
196 ASSERT_TRUE(ht.AddHandleVector(&handles, handle_values.data()));
197
198 for (size_t i = 0u; i < kNumHandles; i++) {
199 ASSERT_NE(handle_values[i], MOJO_HANDLE_INVALID) << i;
200
201 RefPtr<Dispatcher> d;
202 ASSERT_EQ(MOJO_RESULT_OK, ht.GetAndRemoveDispatcher(handle_values[i], &d))
203 << i;
204 ASSERT_EQ(dispatchers[i], d) << i;
205
206 EXPECT_EQ(MOJO_RESULT_OK, dispatchers[i]->Close()) << i;
207 }
208 }
209
210 TEST(HandleTableTest, AddHandleVectorTooMany) {
211 static constexpr size_t kHandleTableSize = 10u;
212 static constexpr size_t kNumHandles = kHandleTableSize + 1u;
213
214 HandleTable ht(kHandleTableSize);
215
216 HandleVector handles;
217 std::vector<RefPtr<Dispatcher>> dispatchers;
218 for (size_t i = 0u; i < kNumHandles; i++) {
219 dispatchers.push_back(MakeRefCounted<test::MockSimpleDispatcher>());
220 handles.push_back(
221 Handle(dispatchers.back().Clone(), MOJO_HANDLE_RIGHT_NONE));
222 ASSERT_TRUE(handles[i]) << i;
223 }
224
225 std::vector<MojoHandle> handle_values(kNumHandles, MOJO_HANDLE_INVALID);
226
227 EXPECT_FALSE(ht.AddHandleVector(&handles, handle_values.data()));
228
229 handles.pop_back();
230 handle_values.pop_back();
231
232 ASSERT_TRUE(ht.AddHandleVector(&handles, handle_values.data()));
233
234 for (size_t i = 0u; i < kNumHandles - 1u; i++) {
235 ASSERT_NE(handle_values[i], MOJO_HANDLE_INVALID) << i;
236
237 RefPtr<Dispatcher> d;
238 ASSERT_EQ(MOJO_RESULT_OK, ht.GetAndRemoveDispatcher(handle_values[i], &d))
239 << i;
240 ASSERT_EQ(dispatchers[i], d) << i;
241 }
242
243 for (size_t i = 0u; i < kNumHandles; i++)
244 EXPECT_EQ(MOJO_RESULT_OK, dispatchers[i]->Close()) << i;
245 }
246
178 } // namespace 247 } // namespace
179 } // namespace system 248 } // namespace system
180 } // namespace mojo 249 } // namespace mojo
OLDNEW
« 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