| OLD | NEW |
| 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 ~MessagePumpLibeventTest() override {} |
| 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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 pump->WatchFileDescriptor(pipefds_[1], | 190 pump->WatchFileDescriptor(pipefds_[1], |
| 191 false, MessagePumpLibevent::WATCH_READ, &watcher, &delegate); | 191 false, MessagePumpLibevent::WATCH_READ, &watcher, &delegate); |
| 192 | 192 |
| 193 // Spoof a libevent notification. | 193 // Spoof a libevent notification. |
| 194 OnLibeventNotification(pump.get(), &watcher); | 194 OnLibeventNotification(pump.get(), &watcher); |
| 195 } | 195 } |
| 196 | 196 |
| 197 } // namespace | 197 } // namespace |
| 198 | 198 |
| 199 } // namespace base | 199 } // namespace base |
| OLD | NEW |