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

Side by Side Diff: mojo/edk/system/handle_table_unittest.cc

Issue 1947083003: EDK: Replace HandleTable::GetDispatcher() with GetHandle(). (Closed) Base URL: https://github.com/domokit/mojo.git@work788_edk_handle_13.2
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> 7 #include <vector>
8 8
9 #include "mojo/edk/system/dispatcher.h" 9 #include "mojo/edk/system/dispatcher.h"
10 #include "mojo/edk/system/handle.h" 10 #include "mojo/edk/system/handle.h"
11 #include "mojo/edk/system/mock_simple_dispatcher.h" 11 #include "mojo/edk/system/mock_simple_dispatcher.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 using mojo::util::MakeRefCounted; 14 using mojo::util::MakeRefCounted;
15 using mojo::util::RefPtr; 15 using mojo::util::RefPtr;
16 16
17 namespace mojo { 17 namespace mojo {
18 namespace system { 18 namespace system {
19 namespace { 19 namespace {
20 20
21 TEST(HandleTableTest, Basic) { 21 TEST(HandleTableTest, Basic) {
22 HandleTable ht(1000u); 22 HandleTable ht(1000u);
23 23
24 RefPtr<Dispatcher> d = MakeRefCounted<test::MockSimpleDispatcher>(); 24 RefPtr<Dispatcher> d = MakeRefCounted<test::MockSimpleDispatcher>();
25 25
26 MojoHandle h = ht.AddHandle(Handle(d.Clone(), MOJO_HANDLE_RIGHT_NONE)); 26 MojoHandle hv = ht.AddHandle(Handle(d.Clone(), MOJO_HANDLE_RIGHT_NONE));
27 ASSERT_NE(h, MOJO_HANDLE_INVALID); 27 ASSERT_NE(hv, MOJO_HANDLE_INVALID);
28 28
29 // Save the pointer value (without taking a ref), so we can check that we get 29 // Save the pointer value (without taking a ref), so we can check that we get
30 // the same object back. 30 // the same object back.
31 Dispatcher* dv = d.get(); 31 Dispatcher* dv = d.get();
32 // Reset this, to make sure that the handle table takes a ref. 32 // Reset this, to make sure that the handle table takes a ref.
33 d = nullptr; 33 d = nullptr;
34 34
35 EXPECT_EQ(MOJO_RESULT_OK, ht.GetDispatcher(h, &d)); 35 Handle h;
36 EXPECT_EQ(d.get(), dv); 36 EXPECT_EQ(MOJO_RESULT_OK, ht.GetHandle(hv, &h));
37 EXPECT_EQ(dv, h.dispatcher.get());
37 38
38 d = nullptr; 39 d = nullptr;
39 ASSERT_EQ(MOJO_RESULT_OK, ht.GetAndRemoveDispatcher(h, &d)); 40 ASSERT_EQ(MOJO_RESULT_OK, ht.GetAndRemoveDispatcher(hv, &d));
40 ASSERT_EQ(d.get(), dv); 41 ASSERT_EQ(dv, d.get());
41 42
42 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); 43 EXPECT_EQ(MOJO_RESULT_OK, d->Close());
43 44
44 // We removed |h|, so it should no longer be valid. 45 // We removed |hv|, so it should no longer be valid.
45 d = nullptr; 46 h.reset();
46 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, ht.GetDispatcher(h, &d)); 47 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, ht.GetHandle(hv, &h));
47 } 48 }
48 49
49 TEST(HandleTableTest, AddHandlePair) { 50 TEST(HandleTableTest, AddHandlePair) {
50 HandleTable ht(1000u); 51 HandleTable ht(1000u);
51 52
52 auto d1 = MakeRefCounted<test::MockSimpleDispatcher>(); 53 auto d1 = MakeRefCounted<test::MockSimpleDispatcher>();
53 auto d2 = MakeRefCounted<test::MockSimpleDispatcher>(); 54 auto d2 = MakeRefCounted<test::MockSimpleDispatcher>();
54 55
55 auto hp = ht.AddHandlePair(Handle(d1.Clone(), MOJO_HANDLE_RIGHT_NONE), 56 auto hp = ht.AddHandlePair(Handle(d1.Clone(), MOJO_HANDLE_RIGHT_NONE),
56 Handle(d2.Clone(), MOJO_HANDLE_RIGHT_NONE)); 57 Handle(d2.Clone(), MOJO_HANDLE_RIGHT_NONE));
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 ASSERT_EQ(dispatchers[i], d) << i; 241 ASSERT_EQ(dispatchers[i], d) << i;
241 } 242 }
242 243
243 for (size_t i = 0u; i < kNumHandles; i++) 244 for (size_t i = 0u; i < kNumHandles; i++)
244 EXPECT_EQ(MOJO_RESULT_OK, dispatchers[i]->Close()) << i; 245 EXPECT_EQ(MOJO_RESULT_OK, dispatchers[i]->Close()) << i;
245 } 246 }
246 247
247 } // namespace 248 } // namespace
248 } // namespace system 249 } // namespace system
249 } // namespace mojo 250 } // 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