2 * Copyright 2015 Facebook, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <gmock/gmock.h>
19 #include <folly/io/async/AsyncSSLSocket.h>
21 namespace folly { namespace test {
23 class MockAsyncSSLSocket : public AsyncSSLSocket {
26 const std::shared_ptr<SSLContext>& ctx,
28 bool deferSecurityNegotiation = false) :
29 AsyncSSLSocket(ctx, base, deferSecurityNegotiation) {
32 GMOCK_METHOD5_(, noexcept, ,
34 void(AsyncSocket::ConnectCallback*,
35 const folly::SocketAddress&,
38 const folly::SocketAddress&));
39 MOCK_CONST_METHOD1(getLocalAddress, void(folly::SocketAddress*));
40 MOCK_CONST_METHOD1(getPeerAddress, void(folly::SocketAddress*));
41 MOCK_METHOD0(closeNow, void());
42 MOCK_CONST_METHOD0(good, bool());
43 MOCK_CONST_METHOD0(readable, bool());
44 MOCK_CONST_METHOD0(hangup, bool());
46 getSelectedNextProtocol,
47 void(const unsigned char**, unsigned*));
49 getSelectedNextProtocolNoThrow,
50 bool(const unsigned char**, unsigned*));
51 MOCK_METHOD1(setPeek, void(bool));
52 MOCK_METHOD1(setReadCB, void(ReadCallback*));
55 AsyncSSLSocket::HandshakeCB* cb,
57 const SSLContext::SSLVerifyPeerEnum& verify)
60 handshakeTimeout_.scheduleTimeout((uint32_t)timeout);
63 state_ = StateEnum::ESTABLISHED;
64 sslState_ = STATE_CONNECTING;
65 handshakeCallback_ = cb;
67 sslConnectMockable(cb, timeout, verify);
71 AsyncSSLSocket::HandshakeCB* cb,
73 const SSLContext::SSLVerifyPeerEnum& verify)
76 handshakeTimeout_.scheduleTimeout(timeout);
79 state_ = StateEnum::ESTABLISHED;
80 sslState_ = STATE_ACCEPTING;
81 handshakeCallback_ = cb;
83 sslAcceptMockable(cb, timeout, verify);
88 void(AsyncSSLSocket::HandshakeCB*, uint64_t,
89 const SSLContext::SSLVerifyPeerEnum&));
93 void(AsyncSSLSocket::HandshakeCB*, uint32_t,
94 const SSLContext::SSLVerifyPeerEnum&));