Steve Anton | da6c095 | 2017-10-23 11:41:54 -0700 | [diff] [blame] | 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_FAKESCTPTRANSPORT_H_ |
| 12 | #define PC_TEST_FAKESCTPTRANSPORT_H_ |
| 13 | |
| 14 | #include <memory> |
| 15 | |
| 16 | #include "media/sctp/sctptransportinternal.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: |
| 23 | void SetTransportChannel(rtc::PacketTransportInternal* channel) override {} |
| 24 | bool Start(int local_port, int remote_port) override { |
| 25 | local_port_.emplace(local_port); |
| 26 | remote_port_.emplace(remote_port); |
| 27 | return true; |
| 28 | } |
| 29 | bool OpenStream(int sid) override { return true; } |
| 30 | bool ResetStream(int sid) override { return true; } |
| 31 | bool SendData(const cricket::SendDataParams& params, |
| 32 | const rtc::CopyOnWriteBuffer& payload, |
| 33 | cricket::SendDataResult* result = nullptr) override { |
| 34 | return true; |
| 35 | } |
| 36 | bool ReadyToSendData() override { return true; } |
| 37 | void set_debug_name_for_testing(const char* debug_name) override {} |
| 38 | |
| 39 | int local_port() const { return *local_port_; } |
| 40 | int remote_port() const { return *remote_port_; } |
| 41 | |
| 42 | private: |
| 43 | rtc::Optional<int> local_port_; |
| 44 | rtc::Optional<int> remote_port_; |
| 45 | }; |
| 46 | |
| 47 | class FakeSctpTransportFactory : public cricket::SctpTransportInternalFactory { |
| 48 | public: |
| 49 | std::unique_ptr<cricket::SctpTransportInternal> CreateSctpTransport( |
| 50 | rtc::PacketTransportInternal*) override { |
| 51 | last_fake_sctp_transport_ = new FakeSctpTransport(); |
| 52 | return std::unique_ptr<cricket::SctpTransportInternal>( |
| 53 | last_fake_sctp_transport_); |
| 54 | } |
| 55 | |
| 56 | FakeSctpTransport* last_fake_sctp_transport() { |
| 57 | return last_fake_sctp_transport_; |
| 58 | } |
| 59 | |
| 60 | private: |
| 61 | FakeSctpTransport* last_fake_sctp_transport_ = nullptr; |
| 62 | }; |
| 63 | |
| 64 | #endif // PC_TEST_FAKESCTPTRANSPORT_H_ |