2014-05-13 18:00:26 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright 2012 The WebRTC Project Authors. All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "rtc_base/null_socket_server.h"
|
2018-11-28 16:47:49 +01:00
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2019-07-05 19:08:33 +02:00
|
|
|
|
2018-11-28 16:47:49 +01:00
|
|
|
#include <memory>
|
|
|
|
|
|
2022-08-25 11:40:13 +00:00
|
|
|
#include "api/units/time_delta.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/gunit.h"
|
2018-11-28 16:47:49 +01:00
|
|
|
#include "rtc_base/location.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "rtc_base/message_handler.h"
|
2018-11-28 16:47:49 +01:00
|
|
|
#include "rtc_base/thread.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "rtc_base/time_utils.h"
|
2018-11-28 16:47:49 +01:00
|
|
|
#include "test/gtest.h"
|
2014-05-13 18:00:26 +00:00
|
|
|
|
|
|
|
|
namespace rtc {
|
|
|
|
|
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
static const uint32_t kTimeout = 5000U;
|
2014-05-13 18:00:26 +00:00
|
|
|
|
2020-09-05 18:43:36 +02:00
|
|
|
class NullSocketServerTest : public ::testing::Test,
|
|
|
|
|
public MessageHandlerAutoCleanup {
|
2014-05-13 18:00:26 +00:00
|
|
|
protected:
|
2017-10-24 10:08:26 -07:00
|
|
|
void OnMessage(Message* message) override { ss_.WakeUp(); }
|
|
|
|
|
|
2014-05-13 18:00:26 +00:00
|
|
|
NullSocketServer ss_;
|
|
|
|
|
};
|
|
|
|
|
|
2014-10-09 22:08:15 +00:00
|
|
|
TEST_F(NullSocketServerTest, WaitAndSet) {
|
2017-07-14 14:44:46 -07:00
|
|
|
auto thread = Thread::Create();
|
|
|
|
|
EXPECT_TRUE(thread->Start());
|
|
|
|
|
thread->Post(RTC_FROM_HERE, this, 0);
|
2014-05-13 18:00:26 +00:00
|
|
|
// The process_io will be ignored.
|
|
|
|
|
const bool process_io = true;
|
2015-02-09 14:19:09 +00:00
|
|
|
EXPECT_TRUE_WAIT(ss_.Wait(SocketServer::kForever, process_io), kTimeout);
|
2014-05-13 18:00:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(NullSocketServerTest, TestWait) {
|
2016-05-06 11:29:15 -07:00
|
|
|
int64_t start = TimeMillis();
|
2022-08-25 11:40:13 +00:00
|
|
|
ss_.Wait(webrtc::TimeDelta::Millis(200), true);
|
2014-05-13 18:00:26 +00:00
|
|
|
// The actual wait time is dependent on the resolution of the timer used by
|
|
|
|
|
// the Event class. Allow for the event to signal ~20ms early.
|
|
|
|
|
EXPECT_GE(TimeSince(start), 180);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace rtc
|