Victor Boivie | e1d60b0 | 2021-04-06 14:39:39 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2021 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 NET_DCSCTP_SOCKET_MOCK_CONTEXT_H_ |
| 11 | #define NET_DCSCTP_SOCKET_MOCK_CONTEXT_H_ |
| 12 | |
| 13 | #include <cstdint> |
| 14 | |
| 15 | #include "absl/strings/string_view.h" |
| 16 | #include "absl/types/optional.h" |
| 17 | #include "net/dcsctp/packet/sctp_packet.h" |
| 18 | #include "net/dcsctp/public/dcsctp_options.h" |
| 19 | #include "net/dcsctp/public/dcsctp_socket.h" |
| 20 | #include "net/dcsctp/socket/context.h" |
| 21 | #include "net/dcsctp/socket/mock_dcsctp_socket_callbacks.h" |
| 22 | #include "test/gmock.h" |
| 23 | |
| 24 | namespace dcsctp { |
| 25 | |
| 26 | class MockContext : public Context { |
| 27 | public: |
| 28 | static constexpr TSN MyInitialTsn() { return TSN(990); } |
| 29 | static constexpr TSN PeerInitialTsn() { return TSN(10); } |
| 30 | static constexpr VerificationTag PeerVerificationTag() { |
| 31 | return VerificationTag(0x01234567); |
| 32 | } |
| 33 | |
| 34 | explicit MockContext(MockDcSctpSocketCallbacks* callbacks) |
| 35 | : callbacks_(*callbacks) { |
| 36 | ON_CALL(*this, is_connection_established) |
| 37 | .WillByDefault(testing::Return(true)); |
| 38 | ON_CALL(*this, my_initial_tsn) |
| 39 | .WillByDefault(testing::Return(MyInitialTsn())); |
| 40 | ON_CALL(*this, peer_initial_tsn) |
| 41 | .WillByDefault(testing::Return(PeerInitialTsn())); |
| 42 | ON_CALL(*this, callbacks).WillByDefault(testing::ReturnRef(callbacks_)); |
Victor Boivie | be04c98 | 2023-10-26 12:22:39 | [diff] [blame] | 43 | ON_CALL(*this, current_rto) |
| 44 | .WillByDefault(testing::Return(webrtc::TimeDelta::Millis(123))); |
Victor Boivie | e1d60b0 | 2021-04-06 14:39:39 | [diff] [blame] | 45 | ON_CALL(*this, Send).WillByDefault([this](SctpPacket::Builder& builder) { |
Victor Boivie | 8df32eb | 2021-08-12 13:21:25 | [diff] [blame] | 46 | callbacks_.SendPacketWithStatus(builder.Build()); |
Victor Boivie | e1d60b0 | 2021-04-06 14:39:39 | [diff] [blame] | 47 | }); |
| 48 | } |
| 49 | |
| 50 | MOCK_METHOD(bool, is_connection_established, (), (const, override)); |
| 51 | MOCK_METHOD(TSN, my_initial_tsn, (), (const, override)); |
| 52 | MOCK_METHOD(TSN, peer_initial_tsn, (), (const, override)); |
| 53 | MOCK_METHOD(DcSctpSocketCallbacks&, callbacks, (), (const, override)); |
| 54 | |
Victor Boivie | b78e6a9 | 2023-10-20 11:16:35 | [diff] [blame] | 55 | MOCK_METHOD(void, ObserveRTT, (webrtc::TimeDelta rtt), (override)); |
Victor Boivie | be04c98 | 2023-10-26 12:22:39 | [diff] [blame] | 56 | MOCK_METHOD(webrtc::TimeDelta, current_rto, (), (const, override)); |
Victor Boivie | e1d60b0 | 2021-04-06 14:39:39 | [diff] [blame] | 57 | MOCK_METHOD(bool, |
| 58 | IncrementTxErrorCounter, |
| 59 | (absl::string_view reason), |
| 60 | (override)); |
| 61 | MOCK_METHOD(void, ClearTxErrorCounter, (), (override)); |
| 62 | MOCK_METHOD(bool, HasTooManyTxErrors, (), (const, override)); |
| 63 | SctpPacket::Builder PacketBuilder() const override { |
| 64 | return SctpPacket::Builder(PeerVerificationTag(), options_); |
| 65 | } |
| 66 | MOCK_METHOD(void, Send, (SctpPacket::Builder & builder), (override)); |
| 67 | |
| 68 | DcSctpOptions options_; |
| 69 | MockDcSctpSocketCallbacks& callbacks_; |
| 70 | }; |
| 71 | } // namespace dcsctp |
| 72 | |
| 73 | #endif // NET_DCSCTP_SOCKET_MOCK_CONTEXT_H_ |