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" 12 #include "webrtc/base/scoped_ptr.h" 13 #include "webrtc/base/thread.h" 14 #include "webrtc/base/maccocoasocketserver.h" 15 16 namespace rtc { 17 18 class WakeThread : public Thread { 19 public: 20 WakeThread(SocketServer* ss) : ss_(ss) { 21 } 22 virtual ~WakeThread() { 23 Stop(); 24 } 25 void Run() { 26 ss_->WakeUp(); 27 } 28 private: 29 SocketServer* ss_; 30 }; 31 32 // Test that MacCocoaSocketServer::Wait works as expected. 33 TEST(MacCocoaSocketServer, TestWait) { 34 MacCocoaSocketServer server; 35 uint32 start = Time(); 36 server.Wait(1000, true); 37 EXPECT_GE(TimeSince(start), 1000); 38 } 39 40 // Test that MacCocoaSocketServer::Wakeup works as expected. 41 TEST(MacCocoaSocketServer, TestWakeup) { 42 MacCFSocketServer server; 43 WakeThread thread(&server); 44 uint32 start = Time(); 45 thread.Start(); 46 server.Wait(10000, true); 47 EXPECT_LT(TimeSince(start), 10000); 48 } 49 50 } // namespace rtc 51