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

Side by Side Diff: base/message_loop/message_pump_libevent_unittest.cc

Issue 614103004: replace 'virtual ... OVERRIDE' with '... override' (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: process base/ Created 6 years, 2 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/message_loop/message_pump_libevent.h" 5 #include "base/message_loop/message_pump_libevent.h"
6 6
7 #include <unistd.h> 7 #include <unistd.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "base/posix/eintr_wrapper.h" 11 #include "base/posix/eintr_wrapper.h"
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "base/threading/thread.h" 13 #include "base/threading/thread.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "third_party/libevent/event.h" 15 #include "third_party/libevent/event.h"
16 16
17 namespace base { 17 namespace base {
18 18
19 class MessagePumpLibeventTest : public testing::Test { 19 class MessagePumpLibeventTest : public testing::Test {
20 protected: 20 protected:
21 MessagePumpLibeventTest() 21 MessagePumpLibeventTest()
22 : ui_loop_(MessageLoop::TYPE_UI), 22 : ui_loop_(MessageLoop::TYPE_UI),
23 io_thread_("MessagePumpLibeventTestIOThread") {} 23 io_thread_("MessagePumpLibeventTestIOThread") {}
24 virtual ~MessagePumpLibeventTest() {} 24 virtual ~MessagePumpLibeventTest() {}
25 25
26 virtual void SetUp() OVERRIDE { 26 void SetUp() override {
27 Thread::Options options(MessageLoop::TYPE_IO, 0); 27 Thread::Options options(MessageLoop::TYPE_IO, 0);
28 ASSERT_TRUE(io_thread_.StartWithOptions(options)); 28 ASSERT_TRUE(io_thread_.StartWithOptions(options));
29 ASSERT_EQ(MessageLoop::TYPE_IO, io_thread_.message_loop()->type()); 29 ASSERT_EQ(MessageLoop::TYPE_IO, io_thread_.message_loop()->type());
30 int ret = pipe(pipefds_); 30 int ret = pipe(pipefds_);
31 ASSERT_EQ(0, ret); 31 ASSERT_EQ(0, ret);
32 } 32 }
33 33
34 virtual void TearDown() OVERRIDE { 34 void TearDown() override {
35 if (IGNORE_EINTR(close(pipefds_[0])) < 0) 35 if (IGNORE_EINTR(close(pipefds_[0])) < 0)
36 PLOG(ERROR) << "close"; 36 PLOG(ERROR) << "close";
37 if (IGNORE_EINTR(close(pipefds_[1])) < 0) 37 if (IGNORE_EINTR(close(pipefds_[1])) < 0)
38 PLOG(ERROR) << "close"; 38 PLOG(ERROR) << "close";
39 } 39 }
40 40
41 MessageLoop* ui_loop() { return &ui_loop_; } 41 MessageLoop* ui_loop() { return &ui_loop_; }
42 MessageLoopForIO* io_loop() const { 42 MessageLoopForIO* io_loop() const {
43 return static_cast<MessageLoopForIO*>(io_thread_.message_loop()); 43 return static_cast<MessageLoopForIO*>(io_thread_.message_loop());
44 } 44 }
(...skipping 13 matching lines...) Expand all
58 58
59 namespace { 59 namespace {
60 60
61 // Concrete implementation of MessagePumpLibevent::Watcher that does 61 // Concrete implementation of MessagePumpLibevent::Watcher that does
62 // nothing useful. 62 // nothing useful.
63 class StupidWatcher : public MessagePumpLibevent::Watcher { 63 class StupidWatcher : public MessagePumpLibevent::Watcher {
64 public: 64 public:
65 virtual ~StupidWatcher() {} 65 virtual ~StupidWatcher() {}
66 66
67 // base:MessagePumpLibevent::Watcher interface 67 // base:MessagePumpLibevent::Watcher interface
68 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE {} 68 void OnFileCanReadWithoutBlocking(int fd) override {}
69 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE {} 69 void OnFileCanWriteWithoutBlocking(int fd) override {}
70 }; 70 };
71 71
72 #if GTEST_HAS_DEATH_TEST && !defined(NDEBUG) 72 #if GTEST_HAS_DEATH_TEST && !defined(NDEBUG)
73 73
74 // Test to make sure that we catch calling WatchFileDescriptor off of the 74 // Test to make sure that we catch calling WatchFileDescriptor off of the
75 // wrong thread. 75 // wrong thread.
76 TEST_F(MessagePumpLibeventTest, TestWatchingFromBadThread) { 76 TEST_F(MessagePumpLibeventTest, TestWatchingFromBadThread) {
77 MessagePumpLibevent::FileDescriptorWatcher watcher; 77 MessagePumpLibevent::FileDescriptorWatcher watcher;
78 StupidWatcher delegate; 78 StupidWatcher delegate;
79 79
(...skipping 13 matching lines...) Expand all
93 93
94 class BaseWatcher : public MessagePumpLibevent::Watcher { 94 class BaseWatcher : public MessagePumpLibevent::Watcher {
95 public: 95 public:
96 explicit BaseWatcher(MessagePumpLibevent::FileDescriptorWatcher* controller) 96 explicit BaseWatcher(MessagePumpLibevent::FileDescriptorWatcher* controller)
97 : controller_(controller) { 97 : controller_(controller) {
98 DCHECK(controller_); 98 DCHECK(controller_);
99 } 99 }
100 virtual ~BaseWatcher() {} 100 virtual ~BaseWatcher() {}
101 101
102 // base:MessagePumpLibevent::Watcher interface 102 // base:MessagePumpLibevent::Watcher interface
103 virtual void OnFileCanReadWithoutBlocking(int /* fd */) OVERRIDE { 103 void OnFileCanReadWithoutBlocking(int /* fd */) override { NOTREACHED(); }
104 NOTREACHED();
105 }
106 104
107 virtual void OnFileCanWriteWithoutBlocking(int /* fd */) OVERRIDE { 105 void OnFileCanWriteWithoutBlocking(int /* fd */) override { NOTREACHED(); }
108 NOTREACHED();
109 }
110 106
111 protected: 107 protected:
112 MessagePumpLibevent::FileDescriptorWatcher* controller_; 108 MessagePumpLibevent::FileDescriptorWatcher* controller_;
113 }; 109 };
114 110
115 class DeleteWatcher : public BaseWatcher { 111 class DeleteWatcher : public BaseWatcher {
116 public: 112 public:
117 explicit DeleteWatcher( 113 explicit DeleteWatcher(
118 MessagePumpLibevent::FileDescriptorWatcher* controller) 114 MessagePumpLibevent::FileDescriptorWatcher* controller)
119 : BaseWatcher(controller) {} 115 : BaseWatcher(controller) {}
120 116
121 virtual ~DeleteWatcher() { 117 virtual ~DeleteWatcher() {
122 DCHECK(!controller_); 118 DCHECK(!controller_);
123 } 119 }
124 120
125 virtual void OnFileCanWriteWithoutBlocking(int /* fd */) OVERRIDE { 121 void OnFileCanWriteWithoutBlocking(int /* fd */) override {
126 DCHECK(controller_); 122 DCHECK(controller_);
127 delete controller_; 123 delete controller_;
128 controller_ = NULL; 124 controller_ = NULL;
129 } 125 }
130 }; 126 };
131 127
132 TEST_F(MessagePumpLibeventTest, DeleteWatcher) { 128 TEST_F(MessagePumpLibeventTest, DeleteWatcher) {
133 scoped_ptr<MessagePumpLibevent> pump(new MessagePumpLibevent); 129 scoped_ptr<MessagePumpLibevent> pump(new MessagePumpLibevent);
134 MessagePumpLibevent::FileDescriptorWatcher* watcher = 130 MessagePumpLibevent::FileDescriptorWatcher* watcher =
135 new MessagePumpLibevent::FileDescriptorWatcher; 131 new MessagePumpLibevent::FileDescriptorWatcher;
136 DeleteWatcher delegate(watcher); 132 DeleteWatcher delegate(watcher);
137 pump->WatchFileDescriptor(pipefds_[1], 133 pump->WatchFileDescriptor(pipefds_[1],
138 false, MessagePumpLibevent::WATCH_READ_WRITE, watcher, &delegate); 134 false, MessagePumpLibevent::WATCH_READ_WRITE, watcher, &delegate);
139 135
140 // Spoof a libevent notification. 136 // Spoof a libevent notification.
141 OnLibeventNotification(pump.get(), watcher); 137 OnLibeventNotification(pump.get(), watcher);
142 } 138 }
143 139
144 class StopWatcher : public BaseWatcher { 140 class StopWatcher : public BaseWatcher {
145 public: 141 public:
146 explicit StopWatcher( 142 explicit StopWatcher(
147 MessagePumpLibevent::FileDescriptorWatcher* controller) 143 MessagePumpLibevent::FileDescriptorWatcher* controller)
148 : BaseWatcher(controller) {} 144 : BaseWatcher(controller) {}
149 145
150 virtual ~StopWatcher() {} 146 virtual ~StopWatcher() {}
151 147
152 virtual void OnFileCanWriteWithoutBlocking(int /* fd */) OVERRIDE { 148 void OnFileCanWriteWithoutBlocking(int /* fd */) override {
153 controller_->StopWatchingFileDescriptor(); 149 controller_->StopWatchingFileDescriptor();
154 } 150 }
155 }; 151 };
156 152
157 TEST_F(MessagePumpLibeventTest, StopWatcher) { 153 TEST_F(MessagePumpLibeventTest, StopWatcher) {
158 scoped_ptr<MessagePumpLibevent> pump(new MessagePumpLibevent); 154 scoped_ptr<MessagePumpLibevent> pump(new MessagePumpLibevent);
159 MessagePumpLibevent::FileDescriptorWatcher watcher; 155 MessagePumpLibevent::FileDescriptorWatcher watcher;
160 StopWatcher delegate(&watcher); 156 StopWatcher delegate(&watcher);
161 pump->WatchFileDescriptor(pipefds_[1], 157 pump->WatchFileDescriptor(pipefds_[1],
162 false, MessagePumpLibevent::WATCH_READ_WRITE, &watcher, &delegate); 158 false, MessagePumpLibevent::WATCH_READ_WRITE, &watcher, &delegate);
163 159
164 // Spoof a libevent notification. 160 // Spoof a libevent notification.
165 OnLibeventNotification(pump.get(), &watcher); 161 OnLibeventNotification(pump.get(), &watcher);
166 } 162 }
167 163
168 void QuitMessageLoopAndStart(const Closure& quit_closure) { 164 void QuitMessageLoopAndStart(const Closure& quit_closure) {
169 quit_closure.Run(); 165 quit_closure.Run();
170 166
171 MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current()); 167 MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current());
172 RunLoop runloop; 168 RunLoop runloop;
173 MessageLoop::current()->PostTask(FROM_HERE, runloop.QuitClosure()); 169 MessageLoop::current()->PostTask(FROM_HERE, runloop.QuitClosure());
174 runloop.Run(); 170 runloop.Run();
175 } 171 }
176 172
177 class NestedPumpWatcher : public MessagePumpLibevent::Watcher { 173 class NestedPumpWatcher : public MessagePumpLibevent::Watcher {
178 public: 174 public:
179 NestedPumpWatcher() {} 175 NestedPumpWatcher() {}
180 virtual ~NestedPumpWatcher() {} 176 virtual ~NestedPumpWatcher() {}
181 177
182 virtual void OnFileCanReadWithoutBlocking(int /* fd */) OVERRIDE { 178 void OnFileCanReadWithoutBlocking(int /* fd */) override {
183 RunLoop runloop; 179 RunLoop runloop;
184 MessageLoop::current()->PostTask(FROM_HERE, Bind(&QuitMessageLoopAndStart, 180 MessageLoop::current()->PostTask(FROM_HERE, Bind(&QuitMessageLoopAndStart,
185 runloop.QuitClosure())); 181 runloop.QuitClosure()));
186 runloop.Run(); 182 runloop.Run();
187 } 183 }
188 184
189 virtual void OnFileCanWriteWithoutBlocking(int /* fd */) OVERRIDE {} 185 void OnFileCanWriteWithoutBlocking(int /* fd */) override {}
190 }; 186 };
191 187
192 TEST_F(MessagePumpLibeventTest, NestedPumpWatcher) { 188 TEST_F(MessagePumpLibeventTest, NestedPumpWatcher) {
193 scoped_ptr<MessagePumpLibevent> pump(new MessagePumpLibevent); 189 scoped_ptr<MessagePumpLibevent> pump(new MessagePumpLibevent);
194 MessagePumpLibevent::FileDescriptorWatcher watcher; 190 MessagePumpLibevent::FileDescriptorWatcher watcher;
195 NestedPumpWatcher delegate; 191 NestedPumpWatcher delegate;
196 pump->WatchFileDescriptor(pipefds_[1], 192 pump->WatchFileDescriptor(pipefds_[1],
197 false, MessagePumpLibevent::WATCH_READ, &watcher, &delegate); 193 false, MessagePumpLibevent::WATCH_READ, &watcher, &delegate);
198 194
199 // Spoof a libevent notification. 195 // Spoof a libevent notification.
200 OnLibeventNotification(pump.get(), &watcher); 196 OnLibeventNotification(pump.get(), &watcher);
201 } 197 }
202 198
203 } // namespace 199 } // namespace
204 200
205 } // namespace base 201 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698