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

Side by Side Diff: base/win/object_watcher_unittest.cc

Issue 868143004: Add an explicit ObjectWatcher::IsWatching() method (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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 | « base/win/object_watcher.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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/win/object_watcher.h" 5 #include "base/win/object_watcher.h"
6 6
7 #include <process.h> 7 #include <process.h>
8 8
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 19 matching lines...) Expand all
30 --(*counter_); 30 --(*counter_);
31 } 31 }
32 private: 32 private:
33 int* counter_; 33 int* counter_;
34 }; 34 };
35 35
36 void RunTest_BasicSignal(MessageLoop::Type message_loop_type) { 36 void RunTest_BasicSignal(MessageLoop::Type message_loop_type) {
37 MessageLoop message_loop(message_loop_type); 37 MessageLoop message_loop(message_loop_type);
38 38
39 ObjectWatcher watcher; 39 ObjectWatcher watcher;
40 EXPECT_EQ(NULL, watcher.GetWatchedObject()); 40 EXPECT_FALSE(watcher.IsWatching());
41 41
42 // A manual-reset event that is not yet signaled. 42 // A manual-reset event that is not yet signaled.
43 HANDLE event = CreateEvent(NULL, TRUE, FALSE, NULL); 43 HANDLE event = CreateEvent(NULL, TRUE, FALSE, NULL);
44 44
45 QuitDelegate delegate; 45 QuitDelegate delegate;
46 bool ok = watcher.StartWatching(event, &delegate); 46 bool ok = watcher.StartWatching(event, &delegate);
47 EXPECT_TRUE(ok); 47 EXPECT_TRUE(ok);
48 EXPECT_TRUE(watcher.IsWatching());
48 EXPECT_EQ(event, watcher.GetWatchedObject()); 49 EXPECT_EQ(event, watcher.GetWatchedObject());
49 50
50 SetEvent(event); 51 SetEvent(event);
51 52
52 MessageLoop::current()->Run(); 53 MessageLoop::current()->Run();
53 54
54 EXPECT_EQ(NULL, watcher.GetWatchedObject()); 55 EXPECT_FALSE(watcher.IsWatching());
55 CloseHandle(event); 56 CloseHandle(event);
56 } 57 }
57 58
58 void RunTest_BasicCancel(MessageLoop::Type message_loop_type) { 59 void RunTest_BasicCancel(MessageLoop::Type message_loop_type) {
59 MessageLoop message_loop(message_loop_type); 60 MessageLoop message_loop(message_loop_type);
60 61
61 ObjectWatcher watcher; 62 ObjectWatcher watcher;
62 63
63 // A manual-reset event that is not yet signaled. 64 // A manual-reset event that is not yet signaled.
64 HANDLE event = CreateEvent(NULL, TRUE, FALSE, NULL); 65 HANDLE event = CreateEvent(NULL, TRUE, FALSE, NULL);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 109
109 // A manual-reset event that is signaled before we begin watching. 110 // A manual-reset event that is signaled before we begin watching.
110 HANDLE event = CreateEvent(NULL, TRUE, TRUE, NULL); 111 HANDLE event = CreateEvent(NULL, TRUE, TRUE, NULL);
111 112
112 QuitDelegate delegate; 113 QuitDelegate delegate;
113 bool ok = watcher.StartWatching(event, &delegate); 114 bool ok = watcher.StartWatching(event, &delegate);
114 EXPECT_TRUE(ok); 115 EXPECT_TRUE(ok);
115 116
116 MessageLoop::current()->Run(); 117 MessageLoop::current()->Run();
117 118
118 EXPECT_EQ(NULL, watcher.GetWatchedObject()); 119 EXPECT_FALSE(watcher.IsWatching());
119 CloseHandle(event); 120 CloseHandle(event);
120 } 121 }
121 122
122 void RunTest_OutlivesMessageLoop(MessageLoop::Type message_loop_type) { 123 void RunTest_OutlivesMessageLoop(MessageLoop::Type message_loop_type) {
123 // Simulate a MessageLoop that dies before an ObjectWatcher. This ordinarily 124 // Simulate a MessageLoop that dies before an ObjectWatcher. This ordinarily
124 // doesn't happen when people use the Thread class, but it can happen when 125 // doesn't happen when people use the Thread class, but it can happen when
125 // people use the Singleton pattern or atexit. 126 // people use the Singleton pattern or atexit.
126 HANDLE event = CreateEvent(NULL, TRUE, FALSE, NULL); // not signaled 127 HANDLE event = CreateEvent(NULL, TRUE, FALSE, NULL); // not signaled
127 { 128 {
128 ObjectWatcher watcher; 129 ObjectWatcher watcher;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 } 166 }
166 167
167 TEST(ObjectWatcherTest, OutlivesMessageLoop) { 168 TEST(ObjectWatcherTest, OutlivesMessageLoop) {
168 RunTest_OutlivesMessageLoop(MessageLoop::TYPE_DEFAULT); 169 RunTest_OutlivesMessageLoop(MessageLoop::TYPE_DEFAULT);
169 RunTest_OutlivesMessageLoop(MessageLoop::TYPE_IO); 170 RunTest_OutlivesMessageLoop(MessageLoop::TYPE_IO);
170 RunTest_OutlivesMessageLoop(MessageLoop::TYPE_UI); 171 RunTest_OutlivesMessageLoop(MessageLoop::TYPE_UI);
171 } 172 }
172 173
173 } // namespace win 174 } // namespace win
174 } // namespace base 175 } // namespace base
OLDNEW
« no previous file with comments | « base/win/object_watcher.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698