1 /* 2 * Copyright 2017 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 11 #ifndef TEST_PC_SCTP_FAKE_SCTP_TRANSPORT_H_ 12 #define TEST_PC_SCTP_FAKE_SCTP_TRANSPORT_H_ 13 14 #include <memory> 15 16 #include "api/transport/sctp_transport_factory_interface.h" 17 #include "media/sctp/sctp_transport_internal.h" 18 19 // Used for tests in this file to verify that PeerConnection responds to signals 20 // from the SctpTransport correctly, and calls Start with the correct 21 // local/remote ports. 22 class FakeSctpTransport : public cricket::SctpTransportInternal { 23 public: SetOnConnectedCallback(std::function<void ()> callback)24 void SetOnConnectedCallback(std::function<void()> callback) override {} SetDataChannelSink(webrtc::DataChannelSink * sink)25 void SetDataChannelSink(webrtc::DataChannelSink* sink) override {} SetDtlsTransport(rtc::PacketTransportInternal * transport)26 void SetDtlsTransport(rtc::PacketTransportInternal* transport) override {} Start(int local_port,int remote_port,int max_message_size)27 bool Start(int local_port, int remote_port, int max_message_size) override { 28 local_port_.emplace(local_port); 29 remote_port_.emplace(remote_port); 30 max_message_size_ = max_message_size; 31 return true; 32 } OpenStream(int sid)33 bool OpenStream(int sid) override { return true; } ResetStream(int sid)34 bool ResetStream(int sid) override { return true; } 35 bool SendData(int sid, 36 const webrtc::SendDataParams& params, 37 const rtc::CopyOnWriteBuffer& payload, 38 cricket::SendDataResult* result = nullptr) override { 39 return true; 40 } ReadyToSendData()41 bool ReadyToSendData() override { return true; } set_debug_name_for_testing(const char * debug_name)42 void set_debug_name_for_testing(const char* debug_name) override {} 43 max_message_size()44 int max_message_size() const { return max_message_size_; } max_outbound_streams()45 absl::optional<int> max_outbound_streams() const { return absl::nullopt; } max_inbound_streams()46 absl::optional<int> max_inbound_streams() const { return absl::nullopt; } local_port()47 int local_port() const { 48 RTC_DCHECK(local_port_); 49 return *local_port_; 50 } remote_port()51 int remote_port() const { 52 RTC_DCHECK(remote_port_); 53 return *remote_port_; 54 } 55 56 private: 57 absl::optional<int> local_port_; 58 absl::optional<int> remote_port_; 59 int max_message_size_; 60 }; 61 62 class FakeSctpTransportFactory : public webrtc::SctpTransportFactoryInterface { 63 public: CreateSctpTransport(rtc::PacketTransportInternal *)64 std::unique_ptr<cricket::SctpTransportInternal> CreateSctpTransport( 65 rtc::PacketTransportInternal*) override { 66 last_fake_sctp_transport_ = new FakeSctpTransport(); 67 return std::unique_ptr<cricket::SctpTransportInternal>( 68 last_fake_sctp_transport_); 69 } 70 last_fake_sctp_transport()71 FakeSctpTransport* last_fake_sctp_transport() { 72 return last_fake_sctp_transport_; 73 } 74 75 private: 76 FakeSctpTransport* last_fake_sctp_transport_ = nullptr; 77 }; 78 79 #endif // TEST_PC_SCTP_FAKE_SCTP_TRANSPORT_H_ 80