henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2009 The WebRTC Project Authors. All rights reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #include "webrtc/base/gunit.h" |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 12 | #include "webrtc/base/thread.h" |
| 13 | #include "webrtc/base/maccocoasocketserver.h" |
| 14 | |
| 15 | namespace rtc { |
| 16 | |
| 17 | class WakeThread : public Thread { |
| 18 | public: |
| 19 | WakeThread(SocketServer* ss) : ss_(ss) { |
| 20 | } |
| 21 | virtual ~WakeThread() { |
| 22 | Stop(); |
| 23 | } |
| 24 | void Run() { |
| 25 | ss_->WakeUp(); |
| 26 | } |
| 27 | private: |
| 28 | SocketServer* ss_; |
| 29 | }; |
| 30 | |
| 31 | // Test that MacCocoaSocketServer::Wait works as expected. |
| 32 | TEST(MacCocoaSocketServer, TestWait) { |
| 33 | MacCocoaSocketServer server; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 34 | uint32_t start = Time(); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 35 | server.Wait(1000, true); |
| 36 | EXPECT_GE(TimeSince(start), 1000); |
| 37 | } |
| 38 | |
| 39 | // Test that MacCocoaSocketServer::Wakeup works as expected. |
| 40 | TEST(MacCocoaSocketServer, TestWakeup) { |
| 41 | MacCFSocketServer server; |
| 42 | WakeThread thread(&server); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 43 | uint32_t start = Time(); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 44 | thread.Start(); |
| 45 | server.Wait(10000, true); |
| 46 | EXPECT_LT(TimeSince(start), 10000); |
| 47 | } |
| 48 | |
| 49 | } // namespace rtc |