2014-05-13 18:00:26 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright 2004 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2016-04-26 03:13:22 -07:00
|
|
|
#include <memory>
|
2014-05-13 18:00:26 +00:00
|
|
|
#include <string>
|
|
|
|
|
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "rtc_base/async_tcp_socket.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/gunit.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "rtc_base/virtual_socket_server.h"
|
2014-05-13 18:00:26 +00:00
|
|
|
|
|
|
|
|
namespace rtc {
|
|
|
|
|
|
2019-04-09 15:11:12 +02:00
|
|
|
class AsyncTCPSocketTest : public ::testing::Test, public sigslot::has_slots<> {
|
2014-05-13 18:00:26 +00:00
|
|
|
public:
|
|
|
|
|
AsyncTCPSocketTest()
|
2017-05-16 18:00:06 -07:00
|
|
|
: vss_(new rtc::VirtualSocketServer()),
|
2014-05-13 18:00:26 +00:00
|
|
|
socket_(vss_->CreateAsyncSocket(SOCK_STREAM)),
|
|
|
|
|
tcp_socket_(new AsyncTCPSocket(socket_, true)),
|
|
|
|
|
ready_to_send_(false) {
|
|
|
|
|
tcp_socket_->SignalReadyToSend.connect(this,
|
|
|
|
|
&AsyncTCPSocketTest::OnReadyToSend);
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-19 15:03:05 +02:00
|
|
|
void OnReadyToSend(rtc::AsyncPacketSocket* socket) { ready_to_send_ = true; }
|
2014-05-13 18:00:26 +00:00
|
|
|
|
|
|
|
|
protected:
|
2016-04-26 03:13:22 -07:00
|
|
|
std::unique_ptr<VirtualSocketServer> vss_;
|
2014-05-13 18:00:26 +00:00
|
|
|
AsyncSocket* socket_;
|
2016-04-26 03:13:22 -07:00
|
|
|
std::unique_ptr<AsyncTCPSocket> tcp_socket_;
|
2014-05-13 18:00:26 +00:00
|
|
|
bool ready_to_send_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TEST_F(AsyncTCPSocketTest, OnWriteEvent) {
|
|
|
|
|
EXPECT_FALSE(ready_to_send_);
|
|
|
|
|
socket_->SignalWriteEvent(socket_);
|
|
|
|
|
EXPECT_TRUE(ready_to_send_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace rtc
|