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