fake_sctp_transport.h 2.5 KB

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