blob: e3d9952f77d14ab8d02c51cd62427dca6f2f2281 [file] [log] [blame]
henrike@webrtc.orgf0488722014-05-13 18:00:26 +00001/*
2 * Copyright 2012 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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "rtc_base/nullsocketserver.h"
12#include "rtc_base/gunit.h"
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000013
14namespace rtc {
15
Peter Boström0c4e06b2015-10-07 12:23:21 +020016static const uint32_t kTimeout = 5000U;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000017
18class NullSocketServerTest
19 : public testing::Test,
20 public MessageHandler {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000021 protected:
Steve Anton9de3aac2017-10-24 10:08:26 -070022 void OnMessage(Message* message) override { ss_.WakeUp(); }
23
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000024 NullSocketServer ss_;
25};
26
henrike@webrtc.orgc732a3e2014-10-09 22:08:15 +000027TEST_F(NullSocketServerTest, WaitAndSet) {
tommie7251592017-07-14 14:44:46 -070028 auto thread = Thread::Create();
29 EXPECT_TRUE(thread->Start());
30 thread->Post(RTC_FROM_HERE, this, 0);
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000031 // The process_io will be ignored.
32 const bool process_io = true;
andresp@webrtc.org53d90122015-02-09 14:19:09 +000033 EXPECT_TRUE_WAIT(ss_.Wait(SocketServer::kForever, process_io), kTimeout);
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000034}
35
36TEST_F(NullSocketServerTest, TestWait) {
Honghai Zhang82d78622016-05-06 11:29:15 -070037 int64_t start = TimeMillis();
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000038 ss_.Wait(200, true);
39 // The actual wait time is dependent on the resolution of the timer used by
40 // the Event class. Allow for the event to signal ~20ms early.
41 EXPECT_GE(TimeSince(start), 180);
42}
43
44} // namespace rtc