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 "gmock/gmock.h"
9 #include "platform/api/tls_connection.h"
10 
11 namespace openscreen {
12 
13 class TaskRunner;
14 
15 class MockTlsConnection : public TlsConnection {
16  public:
MockTlsConnection(IPEndpoint local_address,IPEndpoint remote_address)17   MockTlsConnection(IPEndpoint local_address, IPEndpoint remote_address)
18       : local_address_(local_address), remote_address_(remote_address) {}
19 
20   ~MockTlsConnection() override = default;
21 
22   using TlsConnection::Client;
SetClient(Client * client)23   void SetClient(Client* client) override { client_ = client; }
24 
25   MOCK_METHOD(bool, Send, (const void* data, size_t len), (override));
26 
GetLocalEndpoint()27   IPEndpoint GetLocalEndpoint() const override { return local_address_; }
GetRemoteEndpoint()28   IPEndpoint GetRemoteEndpoint() const override { return remote_address_; }
29 
OnError(Error error)30   void OnError(Error error) {
31     if (client_) {
32       client_->OnError(this, std::move(error));
33     }
34   }
OnRead(std::vector<uint8_t> block)35   void OnRead(std::vector<uint8_t> block) {
36     if (client_) {
37       client_->OnRead(this, std::move(block));
38     }
39   }
40 
41  private:
42   Client* client_;
43   const IPEndpoint local_address_;
44   const IPEndpoint remote_address_;
45 };
46 
47 }  // namespace openscreen
48 
49 #endif  // PLATFORM_TEST_MOCK_TLS_CONNECTION_H_
50