blob: 29f4980c266bd9fa2c425643c9084d5bf1ca4bf0 [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 {
21 public:
22 NullSocketServerTest() {}
23 protected:
24 virtual void OnMessage(Message* message) {
25 ss_.WakeUp();
26 }
27 NullSocketServer ss_;
28};
29
henrike@webrtc.orgc732a3e2014-10-09 22:08:15 +000030TEST_F(NullSocketServerTest, WaitAndSet) {
tommie7251592017-07-14 14:44:46 -070031 auto thread = Thread::Create();
32 EXPECT_TRUE(thread->Start());
33 thread->Post(RTC_FROM_HERE, this, 0);
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000034 // The process_io will be ignored.
35 const bool process_io = true;
andresp@webrtc.org53d90122015-02-09 14:19:09 +000036 EXPECT_TRUE_WAIT(ss_.Wait(SocketServer::kForever, process_io), kTimeout);
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000037}
38
39TEST_F(NullSocketServerTest, TestWait) {
Honghai Zhang82d78622016-05-06 11:29:15 -070040 int64_t start = TimeMillis();
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000041 ss_.Wait(200, true);
42 // The actual wait time is dependent on the resolution of the timer used by
43 // the Event class. Allow for the event to signal ~20ms early.
44 EXPECT_GE(TimeSince(start), 180);
45}
46
47} // namespace rtc