blob: 3d9e4da6997964e0764c0d090f89792ead1328cd [file] [log] [blame]
henrike@webrtc.orgf0488722014-05-13 18:00:26 +00001/*
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.orgf0488722014-05-13 18:00:26 +000012#include "webrtc/base/thread.h"
13#include "webrtc/base/maccocoasocketserver.h"
14
15namespace rtc {
16
17class 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.
32TEST(MacCocoaSocketServer, TestWait) {
33 MacCocoaSocketServer server;
Peter Boström0c4e06b2015-10-07 12:23:21 +020034 uint32_t start = Time();
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000035 server.Wait(1000, true);
36 EXPECT_GE(TimeSince(start), 1000);
37}
38
39// Test that MacCocoaSocketServer::Wakeup works as expected.
40TEST(MacCocoaSocketServer, TestWakeup) {
41 MacCFSocketServer server;
42 WakeThread thread(&server);
Peter Boström0c4e06b2015-10-07 12:23:21 +020043 uint32_t start = Time();
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000044 thread.Start();
45 server.Wait(10000, true);
46 EXPECT_LT(TimeSince(start), 10000);
47}
48
49} // namespace rtc