OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <stdint.h> |
| 6 |
5 #include "sandbox/win/src/win2k_threadpool.h" | 7 #include "sandbox/win/src/win2k_threadpool.h" |
6 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
7 | 9 |
8 void __stdcall EmptyCallBack(void*, unsigned char) { | 10 void __stdcall EmptyCallBack(void*, unsigned char) { |
9 } | 11 } |
10 | 12 |
11 void __stdcall TestCallBack(void* context, unsigned char) { | 13 void __stdcall TestCallBack(void* context, unsigned char) { |
12 HANDLE event = reinterpret_cast<HANDLE>(context); | 14 HANDLE event = reinterpret_cast<HANDLE>(context); |
13 ::SetEvent(event); | 15 ::SetEvent(event); |
14 } | 16 } |
15 | 17 |
16 namespace sandbox { | 18 namespace sandbox { |
17 | 19 |
18 // Test that register and unregister work, part 1. | 20 // Test that register and unregister work, part 1. |
19 TEST(IPCTest, ThreadPoolRegisterTest1) { | 21 TEST(IPCTest, ThreadPoolRegisterTest1) { |
20 Win2kThreadPool thread_pool; | 22 Win2kThreadPool thread_pool; |
21 | 23 |
22 EXPECT_EQ(0u, thread_pool.OutstandingWaits()); | 24 EXPECT_EQ(0u, thread_pool.OutstandingWaits()); |
23 | 25 |
24 HANDLE event1 = ::CreateEventW(NULL, FALSE, FALSE, NULL); | 26 HANDLE event1 = ::CreateEventW(NULL, FALSE, FALSE, NULL); |
25 HANDLE event2 = ::CreateEventW(NULL, FALSE, FALSE, NULL); | 27 HANDLE event2 = ::CreateEventW(NULL, FALSE, FALSE, NULL); |
26 | 28 |
27 uint32 context = 0; | 29 uint32_t context = 0; |
28 EXPECT_FALSE(thread_pool.RegisterWait(0, event1, EmptyCallBack, &context)); | 30 EXPECT_FALSE(thread_pool.RegisterWait(0, event1, EmptyCallBack, &context)); |
29 EXPECT_EQ(0u, thread_pool.OutstandingWaits()); | 31 EXPECT_EQ(0u, thread_pool.OutstandingWaits()); |
30 | 32 |
31 EXPECT_TRUE(thread_pool.RegisterWait(this, event1, EmptyCallBack, &context)); | 33 EXPECT_TRUE(thread_pool.RegisterWait(this, event1, EmptyCallBack, &context)); |
32 EXPECT_EQ(1u, thread_pool.OutstandingWaits()); | 34 EXPECT_EQ(1u, thread_pool.OutstandingWaits()); |
33 EXPECT_TRUE(thread_pool.RegisterWait(this, event2, EmptyCallBack, &context)); | 35 EXPECT_TRUE(thread_pool.RegisterWait(this, event2, EmptyCallBack, &context)); |
34 EXPECT_EQ(2u, thread_pool.OutstandingWaits()); | 36 EXPECT_EQ(2u, thread_pool.OutstandingWaits()); |
35 | 37 |
36 EXPECT_TRUE(thread_pool.UnRegisterWaits(this)); | 38 EXPECT_TRUE(thread_pool.UnRegisterWaits(this)); |
37 EXPECT_EQ(0u, thread_pool.OutstandingWaits()); | 39 EXPECT_EQ(0u, thread_pool.OutstandingWaits()); |
38 | 40 |
39 EXPECT_EQ(TRUE, ::CloseHandle(event1)); | 41 EXPECT_EQ(TRUE, ::CloseHandle(event1)); |
40 EXPECT_EQ(TRUE, ::CloseHandle(event2)); | 42 EXPECT_EQ(TRUE, ::CloseHandle(event2)); |
41 } | 43 } |
42 | 44 |
43 // Test that register and unregister work, part 2. | 45 // Test that register and unregister work, part 2. |
44 TEST(IPCTest, ThreadPoolRegisterTest2) { | 46 TEST(IPCTest, ThreadPoolRegisterTest2) { |
45 Win2kThreadPool thread_pool; | 47 Win2kThreadPool thread_pool; |
46 | 48 |
47 HANDLE event1 = ::CreateEventW(NULL, FALSE, FALSE, NULL); | 49 HANDLE event1 = ::CreateEventW(NULL, FALSE, FALSE, NULL); |
48 HANDLE event2 = ::CreateEventW(NULL, FALSE, FALSE, NULL); | 50 HANDLE event2 = ::CreateEventW(NULL, FALSE, FALSE, NULL); |
49 | 51 |
50 uint32 context = 0; | 52 uint32_t context = 0; |
51 uint32 c1 = 0; | 53 uint32_t c1 = 0; |
52 uint32 c2 = 0; | 54 uint32_t c2 = 0; |
53 | 55 |
54 EXPECT_TRUE(thread_pool.RegisterWait(&c1, event1, EmptyCallBack, &context)); | 56 EXPECT_TRUE(thread_pool.RegisterWait(&c1, event1, EmptyCallBack, &context)); |
55 EXPECT_EQ(1u, thread_pool.OutstandingWaits()); | 57 EXPECT_EQ(1u, thread_pool.OutstandingWaits()); |
56 EXPECT_TRUE(thread_pool.RegisterWait(&c2, event2, EmptyCallBack, &context)); | 58 EXPECT_TRUE(thread_pool.RegisterWait(&c2, event2, EmptyCallBack, &context)); |
57 EXPECT_EQ(2u, thread_pool.OutstandingWaits()); | 59 EXPECT_EQ(2u, thread_pool.OutstandingWaits()); |
58 | 60 |
59 EXPECT_TRUE(thread_pool.UnRegisterWaits(&c2)); | 61 EXPECT_TRUE(thread_pool.UnRegisterWaits(&c2)); |
60 EXPECT_EQ(1u, thread_pool.OutstandingWaits()); | 62 EXPECT_EQ(1u, thread_pool.OutstandingWaits()); |
61 EXPECT_TRUE(thread_pool.UnRegisterWaits(&c2)); | 63 EXPECT_TRUE(thread_pool.UnRegisterWaits(&c2)); |
62 EXPECT_EQ(1u, thread_pool.OutstandingWaits()); | 64 EXPECT_EQ(1u, thread_pool.OutstandingWaits()); |
(...skipping 23 matching lines...) Expand all Loading... |
86 EXPECT_EQ(0u, thread_pool.OutstandingWaits()); | 88 EXPECT_EQ(0u, thread_pool.OutstandingWaits()); |
87 | 89 |
88 EXPECT_EQ(static_cast<DWORD>(WAIT_TIMEOUT), | 90 EXPECT_EQ(static_cast<DWORD>(WAIT_TIMEOUT), |
89 ::SignalObjectAndWait(event1, event2, 1000, FALSE)); | 91 ::SignalObjectAndWait(event1, event2, 1000, FALSE)); |
90 | 92 |
91 EXPECT_EQ(TRUE, ::CloseHandle(event1)); | 93 EXPECT_EQ(TRUE, ::CloseHandle(event1)); |
92 EXPECT_EQ(TRUE, ::CloseHandle(event2)); | 94 EXPECT_EQ(TRUE, ::CloseHandle(event2)); |
93 } | 95 } |
94 | 96 |
95 } // namespace sandbox | 97 } // namespace sandbox |
OLD | NEW |