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

Side by Side Diff: base/message_loop/message_pump_io_ios_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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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_io_ios.h" 5 #include "base/message_loop/message_pump_io_ios.h"
6 6
7 #include <unistd.h> 7 #include <unistd.h>
8 8
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/posix/eintr_wrapper.h" 10 #include "base/posix/eintr_wrapper.h"
11 #include "base/threading/thread.h" 11 #include "base/threading/thread.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 namespace base { 14 namespace base {
15 15
16 class MessagePumpIOSForIOTest : public testing::Test { 16 class MessagePumpIOSForIOTest : public testing::Test {
17 protected: 17 protected:
18 MessagePumpIOSForIOTest() 18 MessagePumpIOSForIOTest()
19 : ui_loop_(MessageLoop::TYPE_UI), 19 : ui_loop_(MessageLoop::TYPE_UI),
20 io_thread_("MessagePumpIOSForIOTestIOThread") {} 20 io_thread_("MessagePumpIOSForIOTestIOThread") {}
21 virtual ~MessagePumpIOSForIOTest() {} 21 virtual ~MessagePumpIOSForIOTest() {}
22 22
23 virtual void SetUp() OVERRIDE { 23 void SetUp() override {
24 Thread::Options options(MessageLoop::TYPE_IO, 0); 24 Thread::Options options(MessageLoop::TYPE_IO, 0);
25 ASSERT_TRUE(io_thread_.StartWithOptions(options)); 25 ASSERT_TRUE(io_thread_.StartWithOptions(options));
26 ASSERT_EQ(MessageLoop::TYPE_IO, io_thread_.message_loop()->type()); 26 ASSERT_EQ(MessageLoop::TYPE_IO, io_thread_.message_loop()->type());
27 int ret = pipe(pipefds_); 27 int ret = pipe(pipefds_);
28 ASSERT_EQ(0, ret); 28 ASSERT_EQ(0, ret);
29 ret = pipe(alternate_pipefds_); 29 ret = pipe(alternate_pipefds_);
30 ASSERT_EQ(0, ret); 30 ASSERT_EQ(0, ret);
31 } 31 }
32 32
33 virtual void TearDown() OVERRIDE { 33 void TearDown() override {
34 if (IGNORE_EINTR(close(pipefds_[0])) < 0) 34 if (IGNORE_EINTR(close(pipefds_[0])) < 0)
35 PLOG(ERROR) << "close"; 35 PLOG(ERROR) << "close";
36 if (IGNORE_EINTR(close(pipefds_[1])) < 0) 36 if (IGNORE_EINTR(close(pipefds_[1])) < 0)
37 PLOG(ERROR) << "close"; 37 PLOG(ERROR) << "close";
38 } 38 }
39 39
40 MessageLoop* ui_loop() { return &ui_loop_; } 40 MessageLoop* ui_loop() { return &ui_loop_; }
41 MessageLoopForIO* io_loop() const { 41 MessageLoopForIO* io_loop() const {
42 return static_cast<MessageLoopForIO*>(io_thread_.message_loop()); 42 return static_cast<MessageLoopForIO*>(io_thread_.message_loop());
43 } 43 }
(...skipping 16 matching lines...) Expand all
60 60
61 namespace { 61 namespace {
62 62
63 // Concrete implementation of MessagePumpIOSForIO::Watcher that does 63 // Concrete implementation of MessagePumpIOSForIO::Watcher that does
64 // nothing useful. 64 // nothing useful.
65 class StupidWatcher : public MessagePumpIOSForIO::Watcher { 65 class StupidWatcher : public MessagePumpIOSForIO::Watcher {
66 public: 66 public:
67 virtual ~StupidWatcher() {} 67 virtual ~StupidWatcher() {}
68 68
69 // base:MessagePumpIOSForIO::Watcher interface 69 // base:MessagePumpIOSForIO::Watcher interface
70 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE {} 70 void OnFileCanReadWithoutBlocking(int fd) override {}
71 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE {} 71 void OnFileCanWriteWithoutBlocking(int fd) override {}
72 }; 72 };
73 73
74 #if GTEST_HAS_DEATH_TEST && !defined(NDEBUG) 74 #if GTEST_HAS_DEATH_TEST && !defined(NDEBUG)
75 75
76 // Test to make sure that we catch calling WatchFileDescriptor off of the 76 // Test to make sure that we catch calling WatchFileDescriptor off of the
77 // wrong thread. 77 // wrong thread.
78 TEST_F(MessagePumpIOSForIOTest, TestWatchingFromBadThread) { 78 TEST_F(MessagePumpIOSForIOTest, TestWatchingFromBadThread) {
79 MessagePumpIOSForIO::FileDescriptorWatcher watcher; 79 MessagePumpIOSForIO::FileDescriptorWatcher watcher;
80 StupidWatcher delegate; 80 StupidWatcher delegate;
81 81
82 ASSERT_DEBUG_DEATH(io_loop()->WatchFileDescriptor( 82 ASSERT_DEBUG_DEATH(io_loop()->WatchFileDescriptor(
83 STDOUT_FILENO, false, MessageLoopForIO::WATCH_READ, &watcher, &delegate), 83 STDOUT_FILENO, false, MessageLoopForIO::WATCH_READ, &watcher, &delegate),
84 "Check failed: " 84 "Check failed: "
85 "watch_file_descriptor_caller_checker_.CalledOnValidThread\\(\\)"); 85 "watch_file_descriptor_caller_checker_.CalledOnValidThread\\(\\)");
86 } 86 }
87 87
88 #endif // GTEST_HAS_DEATH_TEST && !defined(NDEBUG) 88 #endif // GTEST_HAS_DEATH_TEST && !defined(NDEBUG)
89 89
90 class BaseWatcher : public MessagePumpIOSForIO::Watcher { 90 class BaseWatcher : public MessagePumpIOSForIO::Watcher {
91 public: 91 public:
92 BaseWatcher(MessagePumpIOSForIO::FileDescriptorWatcher* controller) 92 BaseWatcher(MessagePumpIOSForIO::FileDescriptorWatcher* controller)
93 : controller_(controller) { 93 : controller_(controller) {
94 DCHECK(controller_); 94 DCHECK(controller_);
95 } 95 }
96 virtual ~BaseWatcher() {} 96 virtual ~BaseWatcher() {}
97 97
98 // MessagePumpIOSForIO::Watcher interface 98 // MessagePumpIOSForIO::Watcher interface
99 virtual void OnFileCanReadWithoutBlocking(int /* fd */) OVERRIDE { 99 void OnFileCanReadWithoutBlocking(int /* fd */) override { NOTREACHED(); }
100 NOTREACHED();
101 }
102 100
103 virtual void OnFileCanWriteWithoutBlocking(int /* fd */) OVERRIDE { 101 void OnFileCanWriteWithoutBlocking(int /* fd */) override { NOTREACHED(); }
104 NOTREACHED();
105 }
106 102
107 protected: 103 protected:
108 MessagePumpIOSForIO::FileDescriptorWatcher* controller_; 104 MessagePumpIOSForIO::FileDescriptorWatcher* controller_;
109 }; 105 };
110 106
111 class DeleteWatcher : public BaseWatcher { 107 class DeleteWatcher : public BaseWatcher {
112 public: 108 public:
113 explicit DeleteWatcher( 109 explicit DeleteWatcher(
114 MessagePumpIOSForIO::FileDescriptorWatcher* controller) 110 MessagePumpIOSForIO::FileDescriptorWatcher* controller)
115 : BaseWatcher(controller) {} 111 : BaseWatcher(controller) {}
116 112
117 virtual ~DeleteWatcher() { 113 virtual ~DeleteWatcher() {
118 DCHECK(!controller_); 114 DCHECK(!controller_);
119 } 115 }
120 116
121 virtual void OnFileCanWriteWithoutBlocking(int /* fd */) OVERRIDE { 117 void OnFileCanWriteWithoutBlocking(int /* fd */) override {
122 DCHECK(controller_); 118 DCHECK(controller_);
123 delete controller_; 119 delete controller_;
124 controller_ = NULL; 120 controller_ = NULL;
125 } 121 }
126 }; 122 };
127 123
128 TEST_F(MessagePumpIOSForIOTest, DeleteWatcher) { 124 TEST_F(MessagePumpIOSForIOTest, DeleteWatcher) {
129 scoped_ptr<MessagePumpIOSForIO> pump(new MessagePumpIOSForIO); 125 scoped_ptr<MessagePumpIOSForIO> pump(new MessagePumpIOSForIO);
130 MessagePumpIOSForIO::FileDescriptorWatcher* watcher = 126 MessagePumpIOSForIO::FileDescriptorWatcher* watcher =
131 new MessagePumpIOSForIO::FileDescriptorWatcher; 127 new MessagePumpIOSForIO::FileDescriptorWatcher;
132 DeleteWatcher delegate(watcher); 128 DeleteWatcher delegate(watcher);
133 pump->WatchFileDescriptor(pipefds_[1], 129 pump->WatchFileDescriptor(pipefds_[1],
134 false, MessagePumpIOSForIO::WATCH_READ_WRITE, watcher, &delegate); 130 false, MessagePumpIOSForIO::WATCH_READ_WRITE, watcher, &delegate);
135 131
136 // Spoof a callback. 132 // Spoof a callback.
137 HandleFdIOEvent(watcher); 133 HandleFdIOEvent(watcher);
138 } 134 }
139 135
140 class StopWatcher : public BaseWatcher { 136 class StopWatcher : public BaseWatcher {
141 public: 137 public:
142 StopWatcher(MessagePumpIOSForIO::FileDescriptorWatcher* controller, 138 StopWatcher(MessagePumpIOSForIO::FileDescriptorWatcher* controller,
143 MessagePumpIOSForIO* pump, 139 MessagePumpIOSForIO* pump,
144 int fd_to_start_watching = -1) 140 int fd_to_start_watching = -1)
145 : BaseWatcher(controller), 141 : BaseWatcher(controller),
146 pump_(pump), 142 pump_(pump),
147 fd_to_start_watching_(fd_to_start_watching) {} 143 fd_to_start_watching_(fd_to_start_watching) {}
148 144
149 virtual ~StopWatcher() {} 145 virtual ~StopWatcher() {}
150 146
151 virtual void OnFileCanWriteWithoutBlocking(int /* fd */) OVERRIDE { 147 void OnFileCanWriteWithoutBlocking(int /* fd */) override {
152 controller_->StopWatchingFileDescriptor(); 148 controller_->StopWatchingFileDescriptor();
153 if (fd_to_start_watching_ >= 0) { 149 if (fd_to_start_watching_ >= 0) {
154 pump_->WatchFileDescriptor(fd_to_start_watching_, 150 pump_->WatchFileDescriptor(fd_to_start_watching_,
155 false, MessagePumpIOSForIO::WATCH_READ_WRITE, controller_, this); 151 false, MessagePumpIOSForIO::WATCH_READ_WRITE, controller_, this);
156 } 152 }
157 } 153 }
158 154
159 private: 155 private:
160 MessagePumpIOSForIO* pump_; 156 MessagePumpIOSForIO* pump_;
161 int fd_to_start_watching_; 157 int fd_to_start_watching_;
(...skipping 17 matching lines...) Expand all
179 pump->WatchFileDescriptor(pipefds_[1], 175 pump->WatchFileDescriptor(pipefds_[1],
180 false, MessagePumpIOSForIO::WATCH_READ_WRITE, &watcher, &delegate); 176 false, MessagePumpIOSForIO::WATCH_READ_WRITE, &watcher, &delegate);
181 177
182 // Spoof a callback. 178 // Spoof a callback.
183 HandleFdIOEvent(&watcher); 179 HandleFdIOEvent(&watcher);
184 } 180 }
185 181
186 } // namespace 182 } // namespace
187 183
188 } // namespace base 184 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698