henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1 | /* |
| 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 Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "rtc_base/nullsocketserver.h" |
| 12 | #include "rtc_base/gunit.h" |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 13 | |
| 14 | namespace rtc { |
| 15 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 16 | static const uint32_t kTimeout = 5000U; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 17 | |
| 18 | class NullSocketServerTest |
| 19 | : public testing::Test, |
| 20 | public MessageHandler { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 21 | protected: |
Steve Anton | 9de3aac | 2017-10-24 10:08:26 -0700 | [diff] [blame] | 22 | void OnMessage(Message* message) override { ss_.WakeUp(); } |
| 23 | |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 24 | NullSocketServer ss_; |
| 25 | }; |
| 26 | |
henrike@webrtc.org | c732a3e | 2014-10-09 22:08:15 +0000 | [diff] [blame] | 27 | TEST_F(NullSocketServerTest, WaitAndSet) { |
tommi | e725159 | 2017-07-14 14:44:46 -0700 | [diff] [blame] | 28 | auto thread = Thread::Create(); |
| 29 | EXPECT_TRUE(thread->Start()); |
| 30 | thread->Post(RTC_FROM_HERE, this, 0); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 31 | // The process_io will be ignored. |
| 32 | const bool process_io = true; |
andresp@webrtc.org | 53d9012 | 2015-02-09 14:19:09 +0000 | [diff] [blame] | 33 | EXPECT_TRUE_WAIT(ss_.Wait(SocketServer::kForever, process_io), kTimeout); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | TEST_F(NullSocketServerTest, TestWait) { |
Honghai Zhang | 82d7862 | 2016-05-06 11:29:15 -0700 | [diff] [blame] | 37 | int64_t start = TimeMillis(); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 38 | 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 |