henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [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 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 11 | #include "rtc_base/null_socket_server.h" |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 12 | |
| 13 | #include <stdint.h> |
Jonas Olsson | a4d8737 | 2019-07-05 17:08:33 | [diff] [blame] | 14 | |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 15 | #include <memory> |
| 16 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 17 | #include "rtc_base/gunit.h" |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 18 | #include "rtc_base/location.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 19 | #include "rtc_base/message_handler.h" |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 20 | #include "rtc_base/thread.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 21 | #include "rtc_base/time_utils.h" |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 22 | #include "test/gtest.h" |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 23 | |
| 24 | namespace rtc { |
| 25 | |
Peter Boström | 0c4e06b | 2015-10-07 10:23:21 | [diff] [blame] | 26 | static const uint32_t kTimeout = 5000U; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 27 | |
Mirko Bonadei | 6a489f2 | 2019-04-09 13:11:12 | [diff] [blame] | 28 | class NullSocketServerTest : public ::testing::Test, public MessageHandler { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 29 | protected: |
Steve Anton | 9de3aac | 2017-10-24 17:08:26 | [diff] [blame] | 30 | void OnMessage(Message* message) override { ss_.WakeUp(); } |
| 31 | |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 32 | NullSocketServer ss_; |
| 33 | }; |
| 34 | |
henrike@webrtc.org | c732a3e | 2014-10-09 22:08:15 | [diff] [blame] | 35 | TEST_F(NullSocketServerTest, WaitAndSet) { |
tommi | e725159 | 2017-07-14 21:44:46 | [diff] [blame] | 36 | auto thread = Thread::Create(); |
| 37 | EXPECT_TRUE(thread->Start()); |
| 38 | thread->Post(RTC_FROM_HERE, this, 0); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 39 | // The process_io will be ignored. |
| 40 | const bool process_io = true; |
andresp@webrtc.org | 53d9012 | 2015-02-09 14:19:09 | [diff] [blame] | 41 | EXPECT_TRUE_WAIT(ss_.Wait(SocketServer::kForever, process_io), kTimeout); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | TEST_F(NullSocketServerTest, TestWait) { |
Honghai Zhang | 82d7862 | 2016-05-06 18:29:15 | [diff] [blame] | 45 | int64_t start = TimeMillis(); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 | [diff] [blame] | 46 | ss_.Wait(200, true); |
| 47 | // The actual wait time is dependent on the resolution of the timer used by |
| 48 | // the Event class. Allow for the event to signal ~20ms early. |
| 49 | EXPECT_GE(TimeSince(start), 180); |
| 50 | } |
| 51 | |
| 52 | } // namespace rtc |