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

Side by Side Diff: sandbox/win/src/threadpool_unittest.cc

Issue 1507413003: clang/win: Let some chromium_code targets build with -Wextra. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: content_browsertests Created 5 years 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 | « sandbox/win/src/sandbox_policy_base.cc ('k') | sandbox/win/src/win_utils_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "sandbox/win/src/win2k_threadpool.h" 5 #include "sandbox/win/src/win2k_threadpool.h"
6 #include "testing/gtest/include/gtest/gtest.h" 6 #include "testing/gtest/include/gtest/gtest.h"
7 7
8 void __stdcall EmptyCallBack(void*, unsigned char) { 8 void __stdcall EmptyCallBack(void*, unsigned char) {
9 } 9 }
10 10
11 void __stdcall TestCallBack(void* context, unsigned char) { 11 void __stdcall TestCallBack(void* context, unsigned char) {
12 HANDLE event = reinterpret_cast<HANDLE>(context); 12 HANDLE event = reinterpret_cast<HANDLE>(context);
13 ::SetEvent(event); 13 ::SetEvent(event);
14 } 14 }
15 15
16 namespace sandbox { 16 namespace sandbox {
17 17
18 // Test that register and unregister work, part 1. 18 // Test that register and unregister work, part 1.
19 TEST(IPCTest, ThreadPoolRegisterTest1) { 19 TEST(IPCTest, ThreadPoolRegisterTest1) {
20 Win2kThreadPool thread_pool; 20 Win2kThreadPool thread_pool;
21 21
22 EXPECT_EQ(0, thread_pool.OutstandingWaits()); 22 EXPECT_EQ(0u, thread_pool.OutstandingWaits());
23 23
24 HANDLE event1 = ::CreateEventW(NULL, FALSE, FALSE, NULL); 24 HANDLE event1 = ::CreateEventW(NULL, FALSE, FALSE, NULL);
25 HANDLE event2 = ::CreateEventW(NULL, FALSE, FALSE, NULL); 25 HANDLE event2 = ::CreateEventW(NULL, FALSE, FALSE, NULL);
26 26
27 uint32 context = 0; 27 uint32 context = 0;
28 EXPECT_FALSE(thread_pool.RegisterWait(0, event1, EmptyCallBack, &context)); 28 EXPECT_FALSE(thread_pool.RegisterWait(0, event1, EmptyCallBack, &context));
29 EXPECT_EQ(0, thread_pool.OutstandingWaits()); 29 EXPECT_EQ(0u, thread_pool.OutstandingWaits());
30 30
31 EXPECT_TRUE(thread_pool.RegisterWait(this, event1, EmptyCallBack, &context)); 31 EXPECT_TRUE(thread_pool.RegisterWait(this, event1, EmptyCallBack, &context));
32 EXPECT_EQ(1, thread_pool.OutstandingWaits()); 32 EXPECT_EQ(1u, thread_pool.OutstandingWaits());
33 EXPECT_TRUE(thread_pool.RegisterWait(this, event2, EmptyCallBack, &context)); 33 EXPECT_TRUE(thread_pool.RegisterWait(this, event2, EmptyCallBack, &context));
34 EXPECT_EQ(2, thread_pool.OutstandingWaits()); 34 EXPECT_EQ(2u, thread_pool.OutstandingWaits());
35 35
36 EXPECT_TRUE(thread_pool.UnRegisterWaits(this)); 36 EXPECT_TRUE(thread_pool.UnRegisterWaits(this));
37 EXPECT_EQ(0, thread_pool.OutstandingWaits()); 37 EXPECT_EQ(0u, thread_pool.OutstandingWaits());
38 38
39 EXPECT_EQ(TRUE, ::CloseHandle(event1)); 39 EXPECT_EQ(TRUE, ::CloseHandle(event1));
40 EXPECT_EQ(TRUE, ::CloseHandle(event2)); 40 EXPECT_EQ(TRUE, ::CloseHandle(event2));
41 } 41 }
42 42
43 // Test that register and unregister work, part 2. 43 // Test that register and unregister work, part 2.
44 TEST(IPCTest, ThreadPoolRegisterTest2) { 44 TEST(IPCTest, ThreadPoolRegisterTest2) {
45 Win2kThreadPool thread_pool; 45 Win2kThreadPool thread_pool;
46 46
47 HANDLE event1 = ::CreateEventW(NULL, FALSE, FALSE, NULL); 47 HANDLE event1 = ::CreateEventW(NULL, FALSE, FALSE, NULL);
48 HANDLE event2 = ::CreateEventW(NULL, FALSE, FALSE, NULL); 48 HANDLE event2 = ::CreateEventW(NULL, FALSE, FALSE, NULL);
49 49
50 uint32 context = 0; 50 uint32 context = 0;
51 uint32 c1 = 0; 51 uint32 c1 = 0;
52 uint32 c2 = 0; 52 uint32 c2 = 0;
53 53
54 EXPECT_TRUE(thread_pool.RegisterWait(&c1, event1, EmptyCallBack, &context)); 54 EXPECT_TRUE(thread_pool.RegisterWait(&c1, event1, EmptyCallBack, &context));
55 EXPECT_EQ(1, thread_pool.OutstandingWaits()); 55 EXPECT_EQ(1u, thread_pool.OutstandingWaits());
56 EXPECT_TRUE(thread_pool.RegisterWait(&c2, event2, EmptyCallBack, &context)); 56 EXPECT_TRUE(thread_pool.RegisterWait(&c2, event2, EmptyCallBack, &context));
57 EXPECT_EQ(2, thread_pool.OutstandingWaits()); 57 EXPECT_EQ(2u, thread_pool.OutstandingWaits());
58 58
59 EXPECT_TRUE(thread_pool.UnRegisterWaits(&c2)); 59 EXPECT_TRUE(thread_pool.UnRegisterWaits(&c2));
60 EXPECT_EQ(1, thread_pool.OutstandingWaits()); 60 EXPECT_EQ(1u, thread_pool.OutstandingWaits());
61 EXPECT_TRUE(thread_pool.UnRegisterWaits(&c2)); 61 EXPECT_TRUE(thread_pool.UnRegisterWaits(&c2));
62 EXPECT_EQ(1, thread_pool.OutstandingWaits()); 62 EXPECT_EQ(1u, thread_pool.OutstandingWaits());
63 63
64 EXPECT_TRUE(thread_pool.UnRegisterWaits(&c1)); 64 EXPECT_TRUE(thread_pool.UnRegisterWaits(&c1));
65 EXPECT_EQ(0, thread_pool.OutstandingWaits()); 65 EXPECT_EQ(0u, thread_pool.OutstandingWaits());
66 66
67 EXPECT_EQ(TRUE, ::CloseHandle(event1)); 67 EXPECT_EQ(TRUE, ::CloseHandle(event1));
68 EXPECT_EQ(TRUE, ::CloseHandle(event2)); 68 EXPECT_EQ(TRUE, ::CloseHandle(event2));
69 } 69 }
70 70
71 // Test that the thread pool has at least a thread that services an event. 71 // Test that the thread pool has at least a thread that services an event.
72 // Test that when the event is un-registered is no longer serviced. 72 // Test that when the event is un-registered is no longer serviced.
73 TEST(IPCTest, ThreadPoolSignalAndWaitTest) { 73 TEST(IPCTest, ThreadPoolSignalAndWaitTest) {
74 Win2kThreadPool thread_pool; 74 Win2kThreadPool thread_pool;
75 75
76 // The events are auto reset and start not signaled. 76 // The events are auto reset and start not signaled.
77 HANDLE event1 = ::CreateEventW(NULL, FALSE, FALSE, NULL); 77 HANDLE event1 = ::CreateEventW(NULL, FALSE, FALSE, NULL);
78 HANDLE event2 = ::CreateEventW(NULL, FALSE, FALSE, NULL); 78 HANDLE event2 = ::CreateEventW(NULL, FALSE, FALSE, NULL);
79 79
80 EXPECT_TRUE(thread_pool.RegisterWait(this, event1, TestCallBack, event2)); 80 EXPECT_TRUE(thread_pool.RegisterWait(this, event1, TestCallBack, event2));
81 81
82 EXPECT_EQ(WAIT_OBJECT_0, ::SignalObjectAndWait(event1, event2, 5000, FALSE)); 82 EXPECT_EQ(WAIT_OBJECT_0, ::SignalObjectAndWait(event1, event2, 5000, FALSE));
83 EXPECT_EQ(WAIT_OBJECT_0, ::SignalObjectAndWait(event1, event2, 5000, FALSE)); 83 EXPECT_EQ(WAIT_OBJECT_0, ::SignalObjectAndWait(event1, event2, 5000, FALSE));
84 84
85 EXPECT_TRUE(thread_pool.UnRegisterWaits(this)); 85 EXPECT_TRUE(thread_pool.UnRegisterWaits(this));
86 EXPECT_EQ(0, thread_pool.OutstandingWaits()); 86 EXPECT_EQ(0u, thread_pool.OutstandingWaits());
87 87
88 EXPECT_EQ(WAIT_TIMEOUT, ::SignalObjectAndWait(event1, event2, 1000, FALSE)); 88 EXPECT_EQ(static_cast<DWORD>(WAIT_TIMEOUT),
89 ::SignalObjectAndWait(event1, event2, 1000, FALSE));
89 90
90 EXPECT_EQ(TRUE, ::CloseHandle(event1)); 91 EXPECT_EQ(TRUE, ::CloseHandle(event1));
91 EXPECT_EQ(TRUE, ::CloseHandle(event2)); 92 EXPECT_EQ(TRUE, ::CloseHandle(event2));
92 } 93 }
93 94
94 } // namespace sandbox 95 } // namespace sandbox
OLDNEW
« no previous file with comments | « sandbox/win/src/sandbox_policy_base.cc ('k') | sandbox/win/src/win_utils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698