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

Side by Side Diff: base/synchronization/waitable_event_unittest.cc

Issue 5977010: Move CancellationFlag and WaitableEvent to the synchronization subdirectory.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 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/time.h" 5 #include "base/time.h"
6 #include "base/waitable_event.h" 6 #include "base/synchronization/waitable_event.h"
7 #include "base/threading/platform_thread.h" 7 #include "base/threading/platform_thread.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 using base::TimeDelta; 10 namespace base {
11 using base::WaitableEvent;
12
13 namespace {
14 typedef testing::Test WaitableEventTest;
15 }
16 11
17 TEST(WaitableEventTest, ManualBasics) { 12 TEST(WaitableEventTest, ManualBasics) {
18 WaitableEvent event(true, false); 13 WaitableEvent event(true, false);
19 14
20 EXPECT_FALSE(event.IsSignaled()); 15 EXPECT_FALSE(event.IsSignaled());
21 16
22 event.Signal(); 17 event.Signal();
23 EXPECT_TRUE(event.IsSignaled()); 18 EXPECT_TRUE(event.IsSignaled());
24 EXPECT_TRUE(event.IsSignaled()); 19 EXPECT_TRUE(event.IsSignaled());
25 20
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 ev[4]->Signal(); 62 ev[4]->Signal();
68 EXPECT_EQ(WaitableEvent::WaitMany(ev, 5), 4u); 63 EXPECT_EQ(WaitableEvent::WaitMany(ev, 5), 4u);
69 64
70 ev[0]->Signal(); 65 ev[0]->Signal();
71 EXPECT_EQ(WaitableEvent::WaitMany(ev, 5), 0u); 66 EXPECT_EQ(WaitableEvent::WaitMany(ev, 5), 0u);
72 67
73 for (unsigned i = 0; i < 5; ++i) 68 for (unsigned i = 0; i < 5; ++i)
74 delete ev[i]; 69 delete ev[i];
75 } 70 }
76 71
77 class WaitableEventSignaler : public base::PlatformThread::Delegate { 72 class WaitableEventSignaler : public PlatformThread::Delegate {
78 public: 73 public:
79 WaitableEventSignaler(double seconds, WaitableEvent* ev) 74 WaitableEventSignaler(double seconds, WaitableEvent* ev)
80 : seconds_(seconds), 75 : seconds_(seconds),
81 ev_(ev) { 76 ev_(ev) {
82 } 77 }
83 78
84 void ThreadMain() { 79 void ThreadMain() {
85 base::PlatformThread::Sleep(static_cast<int>(seconds_ * 1000)); 80 PlatformThread::Sleep(static_cast<int>(seconds_ * 1000));
86 ev_->Signal(); 81 ev_->Signal();
87 } 82 }
88 83
89 private: 84 private:
90 const double seconds_; 85 const double seconds_;
91 WaitableEvent *const ev_; 86 WaitableEvent *const ev_;
92 }; 87 };
93 88
94 TEST(WaitableEventTest, WaitMany) { 89 TEST(WaitableEventTest, WaitMany) {
95 WaitableEvent* ev[5]; 90 WaitableEvent* ev[5];
96 for (unsigned i = 0; i < 5; ++i) 91 for (unsigned i = 0; i < 5; ++i)
97 ev[i] = new WaitableEvent(false, false); 92 ev[i] = new WaitableEvent(false, false);
98 93
99 WaitableEventSignaler signaler(0.1, ev[2]); 94 WaitableEventSignaler signaler(0.1, ev[2]);
100 base::PlatformThreadHandle thread; 95 PlatformThreadHandle thread;
101 base::PlatformThread::Create(0, &signaler, &thread); 96 PlatformThread::Create(0, &signaler, &thread);
102 97
103 EXPECT_EQ(WaitableEvent::WaitMany(ev, 5), 2u); 98 EXPECT_EQ(WaitableEvent::WaitMany(ev, 5), 2u);
104 99
105 base::PlatformThread::Join(thread); 100 PlatformThread::Join(thread);
106 101
107 for (unsigned i = 0; i < 5; ++i) 102 for (unsigned i = 0; i < 5; ++i)
108 delete ev[i]; 103 delete ev[i];
109 } 104 }
105
106 } // namespace base
OLDNEW
« no previous file with comments | « base/synchronization/waitable_event_posix.cc ('k') | base/synchronization/waitable_event_watcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698