1 // Copyright 2019 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef PLATFORM_TEST_MOCK_TLS_CONNECTION_H_ 6 #define PLATFORM_TEST_MOCK_TLS_CONNECTION_H_ 7 8 #include <utility> 9 #include <vector> 10 11 #include "gmock/gmock.h" 12 #include "platform/api/tls_connection.h" 13 14 namespace openscreen { 15 16 class TaskRunner; 17 18 class MockTlsConnection : public TlsConnection { 19 public: MockTlsConnection(IPEndpoint local_address,IPEndpoint remote_address)20 MockTlsConnection(IPEndpoint local_address, IPEndpoint remote_address) 21 : local_address_(local_address), remote_address_(remote_address) {} 22 23 ~MockTlsConnection() override = default; 24 25 using TlsConnection::Client; SetClient(Client * client)26 void SetClient(Client* client) override { client_ = client; } 27 28 MOCK_METHOD(bool, Send, (const void* data, size_t len), (override)); 29 GetRemoteEndpoint()30 IPEndpoint GetRemoteEndpoint() const override { return remote_address_; } 31 OnError(Error error)32 void OnError(Error error) { 33 if (client_) { 34 client_->OnError(this, std::move(error)); 35 } 36 } OnRead(std::vector<uint8_t> block)37 void OnRead(std::vector<uint8_t> block) { 38 if (client_) { 39 client_->OnRead(this, std::move(block)); 40 } 41 } 42 43 private: 44 Client* client_; 45 const IPEndpoint local_address_; 46 const IPEndpoint remote_address_; 47 }; 48 49 } // namespace openscreen 50 51 #endif // PLATFORM_TEST_MOCK_TLS_CONNECTION_H_ 52