OLD | NEW |
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/message_pump_libevent.h" | 5 #include "base/message_pump_mac.h" |
6 | 6 |
7 #include <unistd.h> | 7 #include <unistd.h> |
8 | 8 |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/threading/thread.h" | 10 #include "base/threading/thread.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 | 12 |
13 namespace { | 13 namespace { |
14 | 14 |
15 class MessagePumpLibeventTest : public testing::Test { | 15 class MessagePumpCFRunLoopBaseTest : public testing::Test { |
16 public: | 16 public: |
17 MessagePumpLibeventTest() | 17 MessagePumpCFRunLoopBaseTest() |
18 : ui_loop_(MessageLoop::TYPE_UI), | 18 : ui_loop_(MessageLoop::TYPE_UI), |
19 io_thread_("MessagePumpLibeventTestIOThread") {} | 19 io_thread_("MessagePumpCFRunLoopBaseTestIOThread") {} |
20 virtual ~MessagePumpLibeventTest() {} | 20 virtual ~MessagePumpCFRunLoopBaseTest() {} |
21 | 21 |
22 virtual void SetUp() { | 22 virtual void SetUp() { |
23 base::Thread::Options options(MessageLoop::TYPE_IO, 0); | 23 base::Thread::Options options(MessageLoop::TYPE_IO, 0); |
24 ASSERT_TRUE(io_thread_.StartWithOptions(options)); | 24 ASSERT_TRUE(io_thread_.StartWithOptions(options)); |
25 ASSERT_EQ(MessageLoop::TYPE_IO, io_thread_.message_loop()->type()); | 25 ASSERT_EQ(MessageLoop::TYPE_IO, io_thread_.message_loop()->type()); |
26 } | 26 } |
27 | 27 |
28 MessageLoop* ui_loop() { return &ui_loop_; } | 28 MessageLoop* ui_loop() { return &ui_loop_; } |
29 MessageLoopForIO* io_loop() const { | 29 MessageLoopForIO* io_loop() const { |
30 return static_cast<MessageLoopForIO*>(io_thread_.message_loop()); | 30 return static_cast<MessageLoopForIO*>(io_thread_.message_loop()); |
31 } | 31 } |
32 | 32 |
33 private: | 33 private: |
34 MessageLoop ui_loop_; | 34 MessageLoop ui_loop_; |
35 base::Thread io_thread_; | 35 base::Thread io_thread_; |
36 DISALLOW_COPY_AND_ASSIGN(MessagePumpLibeventTest); | 36 DISALLOW_COPY_AND_ASSIGN(MessagePumpCFRunLoopBaseTest); |
37 }; | 37 }; |
38 | 38 |
39 // Concrete implementation of base::MessagePumpLibevent::Watcher that does | 39 // Concrete implementation of base::MessagePumpCFRunLoopBase::Watcher that does |
40 // nothing useful. | 40 // nothing useful. |
41 class StupidWatcher : public base::MessagePumpLibevent::Watcher { | 41 class StupidWatcher : public base::MessagePumpCFRunLoopBase::Watcher { |
42 public: | 42 public: |
43 virtual ~StupidWatcher() {} | 43 virtual ~StupidWatcher() {} |
44 | 44 |
45 // base:MessagePumpLibEvent::Watcher interface | 45 // base:MessagePumpCFRunLoopBase::Watcher interface |
46 virtual void OnFileCanReadWithoutBlocking(int fd) {} | 46 virtual void OnFileCanReadWithoutBlocking(int fd) {} |
47 virtual void OnFileCanWriteWithoutBlocking(int fd) {} | 47 virtual void OnFileCanWriteWithoutBlocking(int fd) {} |
48 }; | 48 }; |
49 | 49 |
50 } // namespace | 50 } // namespace |
51 | 51 |
52 #if GTEST_HAS_DEATH_TEST | 52 #if GTEST_HAS_DEATH_TEST |
53 | 53 |
54 // Test to make sure that we catch calling WatchFileDescriptor off of the | 54 // Test to make sure that we catch calling WatchFileDescriptor off of the |
55 // wrong thread. | 55 // wrong thread. |
56 TEST_F(MessagePumpLibeventTest, TestWatchingFromBadThread) { | 56 TEST_F(MessagePumpCFRunLoopBaseTest, TestWatchingFromBadThread) { |
57 base::MessagePumpLibevent::FileDescriptorWatcher watcher; | 57 base::MessagePumpCFRunLoopBase::FileDescriptorWatcher watcher; |
58 StupidWatcher delegate; | 58 StupidWatcher delegate; |
59 | 59 |
60 ASSERT_DEBUG_DEATH(io_loop()->WatchFileDescriptor( | 60 ASSERT_DEBUG_DEATH(io_loop()->WatchFileDescriptor( |
61 STDOUT_FILENO, false, MessageLoopForIO::WATCH_READ, &watcher, &delegate), | 61 STDOUT_FILENO, false, MessageLoopForIO::WATCH_READ, &watcher, &delegate), |
62 "Check failed: " | 62 "Check failed: " |
63 "watch_file_descriptor_caller_checker_.CalledOnValidThread()"); | 63 "watch_file_descriptor_caller_checker_.CalledOnValidThread()"); |
64 } | 64 } |
65 | 65 |
66 #endif // GTEST_HAS_DEATH_TEST | 66 #endif // GTEST_HAS_DEATH_TEST |
OLD | NEW |