OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/mac/mach_port_broker.h" | |
6 | |
7 #include "base/synchronization/lock.h" | |
8 #include "testing/gtest/include/gtest/gtest.h" | |
9 | |
10 namespace base { | |
11 | |
12 class MachPortBrokerTest : public testing::Test { | |
13 public: | |
14 MachPortBrokerTest() : broker_("foo") {} | |
15 | |
16 // Helper function to acquire/release locks and call |PlaceholderForPid()|. | |
17 void AddPlaceholderForPid(base::ProcessHandle pid) { | |
18 base::AutoLock lock(broker_.GetLock()); | |
19 broker_.AddPlaceholderForPid(pid); | |
20 } | |
21 | |
22 // Helper function to acquire/release locks and call |FinalizePid()|. | |
23 void FinalizePid(base::ProcessHandle pid, | |
24 mach_port_t task_port) { | |
25 base::AutoLock lock(broker_.GetLock()); | |
26 broker_.FinalizePid(pid, task_port); | |
27 } | |
28 | |
29 protected: | |
30 MachPortBroker broker_; | |
31 }; | |
32 | |
33 TEST_F(MachPortBrokerTest, Locks) { | |
34 // Acquire and release the locks. Nothing bad should happen. | |
35 base::AutoLock lock(broker_.GetLock()); | |
36 } | |
37 | |
38 TEST_F(MachPortBrokerTest, AddPlaceholderAndFinalize) { | |
39 // Add a placeholder for PID 1. | |
40 AddPlaceholderForPid(1); | |
41 EXPECT_EQ(0u, broker_.TaskForPid(1)); | |
42 | |
43 // Finalize PID 1. | |
44 FinalizePid(1, 100u); | |
45 EXPECT_EQ(100u, broker_.TaskForPid(1)); | |
46 | |
47 // Should be no entry for PID 2. | |
48 EXPECT_EQ(0u, broker_.TaskForPid(2)); | |
49 } | |
50 | |
51 TEST_F(MachPortBrokerTest, FinalizeUnknownPid) { | |
52 // Finalizing an entry for an unknown pid should not add it to the map. | |
53 FinalizePid(1u, 100u); | |
erikchen
2016/03/02 06:56:11
Sorry to impose, but could you add a multiprocess
Anand Mistry (off Chromium)
2016/03/03 01:57:39
Done.
| |
54 EXPECT_EQ(0u, broker_.TaskForPid(1u)); | |
55 } | |
56 | |
57 } // namespace base | |
OLD | NEW |