Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(402)

Side by Side Diff: net/socket/socket_test_util.h

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef NET_SOCKET_SOCKET_TEST_UTIL_H_ 5 #ifndef NET_SOCKET_SOCKET_TEST_UTIL_H_
6 #define NET_SOCKET_SOCKET_TEST_UTIL_H_ 6 #define NET_SOCKET_SOCKET_TEST_UTIL_H_
7 7
8 #include <cstring> 8 #include <cstring>
9 #include <deque> 9 #include <deque>
10 #include <string> 10 #include <string>
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 // MockRead. The other members of that MockRead are ignored. 45 // MockRead. The other members of that MockRead are ignored.
46 ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ = -10000, 46 ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ = -10000,
47 }; 47 };
48 48
49 class AsyncSocket; 49 class AsyncSocket;
50 class MockClientSocket; 50 class MockClientSocket;
51 class ServerBoundCertService; 51 class ServerBoundCertService;
52 class SSLClientSocket; 52 class SSLClientSocket;
53 class StreamSocket; 53 class StreamSocket;
54 54
55 enum IoMode { 55 enum IoMode { ASYNC, SYNCHRONOUS };
56 ASYNC,
57 SYNCHRONOUS
58 };
59 56
60 struct MockConnect { 57 struct MockConnect {
61 // Asynchronous connection success. 58 // Asynchronous connection success.
62 // Creates a MockConnect with |mode| ASYC, |result| OK, and 59 // Creates a MockConnect with |mode| ASYC, |result| OK, and
63 // |peer_addr| 192.0.2.33. 60 // |peer_addr| 192.0.2.33.
64 MockConnect(); 61 MockConnect();
65 // Creates a MockConnect with the specified mode and result, with 62 // Creates a MockConnect with the specified mode and result, with
66 // |peer_addr| 192.0.2.33. 63 // |peer_addr| 192.0.2.33.
67 MockConnect(IoMode io_mode, int r); 64 MockConnect(IoMode io_mode, int r);
68 MockConnect(IoMode io_mode, int r, IPEndPoint addr); 65 MockConnect(IoMode io_mode, int r, IPEndPoint addr);
69 ~MockConnect(); 66 ~MockConnect();
70 67
71 IoMode mode; 68 IoMode mode;
72 int result; 69 int result;
73 IPEndPoint peer_addr; 70 IPEndPoint peer_addr;
74 }; 71 };
75 72
76 // MockRead and MockWrite shares the same interface and members, but we'd like 73 // MockRead and MockWrite shares the same interface and members, but we'd like
77 // to have distinct types because we don't want to have them used 74 // to have distinct types because we don't want to have them used
78 // interchangably. To do this, a struct template is defined, and MockRead and 75 // interchangably. To do this, a struct template is defined, and MockRead and
79 // MockWrite are instantiated by using this template. Template parameter |type| 76 // MockWrite are instantiated by using this template. Template parameter |type|
80 // is not used in the struct definition (it purely exists for creating a new 77 // is not used in the struct definition (it purely exists for creating a new
81 // type). 78 // type).
82 // 79 //
83 // |data| in MockRead and MockWrite has different meanings: |data| in MockRead 80 // |data| in MockRead and MockWrite has different meanings: |data| in MockRead
84 // is the data returned from the socket when MockTCPClientSocket::Read() is 81 // is the data returned from the socket when MockTCPClientSocket::Read() is
85 // attempted, while |data| in MockWrite is the expected data that should be 82 // attempted, while |data| in MockWrite is the expected data that should be
86 // given in MockTCPClientSocket::Write(). 83 // given in MockTCPClientSocket::Write().
87 enum MockReadWriteType { 84 enum MockReadWriteType { MOCK_READ, MOCK_WRITE };
88 MOCK_READ,
89 MOCK_WRITE
90 };
91 85
92 template <MockReadWriteType type> 86 template <MockReadWriteType type>
93 struct MockReadWrite { 87 struct MockReadWrite {
94 // Flag to indicate that the message loop should be terminated. 88 // Flag to indicate that the message loop should be terminated.
95 enum { 89 enum { STOPLOOP = 1 << 31 };
96 STOPLOOP = 1 << 31
97 };
98 90
99 // Default 91 // Default
100 MockReadWrite() 92 MockReadWrite()
101 : mode(SYNCHRONOUS), 93 : mode(SYNCHRONOUS),
102 result(0), 94 result(0),
103 data(NULL), 95 data(NULL),
104 data_len(0), 96 data_len(0),
105 sequence_number(0), 97 sequence_number(0),
106 time_stamp(base::Time::Now()) {} 98 time_stamp(base::Time::Now()) {}
107 99
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 virtual void Disconnect() OVERRIDE; 675 virtual void Disconnect() OVERRIDE;
684 virtual bool IsConnected() const OVERRIDE; 676 virtual bool IsConnected() const OVERRIDE;
685 virtual bool IsConnectedAndIdle() const OVERRIDE; 677 virtual bool IsConnectedAndIdle() const OVERRIDE;
686 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE; 678 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE;
687 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE; 679 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE;
688 virtual const BoundNetLog& NetLog() const OVERRIDE; 680 virtual const BoundNetLog& NetLog() const OVERRIDE;
689 virtual void SetSubresourceSpeculation() OVERRIDE {} 681 virtual void SetSubresourceSpeculation() OVERRIDE {}
690 virtual void SetOmniboxSpeculation() OVERRIDE {} 682 virtual void SetOmniboxSpeculation() OVERRIDE {}
691 683
692 // SSLClientSocket implementation. 684 // SSLClientSocket implementation.
693 virtual void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) 685 virtual void GetSSLCertRequestInfo(
694 OVERRIDE; 686 SSLCertRequestInfo* cert_request_info) OVERRIDE;
695 virtual int ExportKeyingMaterial(const base::StringPiece& label, 687 virtual int ExportKeyingMaterial(const base::StringPiece& label,
696 bool has_context, 688 bool has_context,
697 const base::StringPiece& context, 689 const base::StringPiece& context,
698 unsigned char* out, 690 unsigned char* out,
699 unsigned int outlen) OVERRIDE; 691 unsigned int outlen) OVERRIDE;
700 virtual int GetTLSUniqueChannelBinding(std::string* out) OVERRIDE; 692 virtual int GetTLSUniqueChannelBinding(std::string* out) OVERRIDE;
701 virtual NextProtoStatus GetNextProto(std::string* proto, 693 virtual NextProtoStatus GetNextProto(std::string* proto,
702 std::string* server_protos) OVERRIDE; 694 std::string* server_protos) OVERRIDE;
703 virtual ServerBoundCertService* GetServerBoundCertService() const OVERRIDE; 695 virtual ServerBoundCertService* GetServerBoundCertService() const OVERRIDE;
704 696
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
942 virtual int Connect(const CompletionCallback& callback) OVERRIDE; 934 virtual int Connect(const CompletionCallback& callback) OVERRIDE;
943 virtual void Disconnect() OVERRIDE; 935 virtual void Disconnect() OVERRIDE;
944 virtual bool IsConnected() const OVERRIDE; 936 virtual bool IsConnected() const OVERRIDE;
945 virtual bool WasEverUsed() const OVERRIDE; 937 virtual bool WasEverUsed() const OVERRIDE;
946 virtual bool UsingTCPFastOpen() const OVERRIDE; 938 virtual bool UsingTCPFastOpen() const OVERRIDE;
947 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE; 939 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE;
948 virtual bool WasNpnNegotiated() const OVERRIDE; 940 virtual bool WasNpnNegotiated() const OVERRIDE;
949 virtual bool GetSSLInfo(SSLInfo* ssl_info) OVERRIDE; 941 virtual bool GetSSLInfo(SSLInfo* ssl_info) OVERRIDE;
950 942
951 // SSLClientSocket implementation. 943 // SSLClientSocket implementation.
952 virtual void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) 944 virtual void GetSSLCertRequestInfo(
953 OVERRIDE; 945 SSLCertRequestInfo* cert_request_info) OVERRIDE;
954 virtual NextProtoStatus GetNextProto(std::string* proto, 946 virtual NextProtoStatus GetNextProto(std::string* proto,
955 std::string* server_protos) OVERRIDE; 947 std::string* server_protos) OVERRIDE;
956 virtual bool set_was_npn_negotiated(bool negotiated) OVERRIDE; 948 virtual bool set_was_npn_negotiated(bool negotiated) OVERRIDE;
957 virtual void set_protocol_negotiated(NextProto protocol_negotiated) OVERRIDE; 949 virtual void set_protocol_negotiated(NextProto protocol_negotiated) OVERRIDE;
958 virtual NextProto GetNegotiatedProtocol() const OVERRIDE; 950 virtual NextProto GetNegotiatedProtocol() const OVERRIDE;
959 951
960 // This MockSocket does not implement the manual async IO feature. 952 // This MockSocket does not implement the manual async IO feature.
961 virtual void OnReadComplete(const MockRead& data) OVERRIDE; 953 virtual void OnReadComplete(const MockRead& data) OVERRIDE;
962 virtual void OnConnectComplete(const MockConnect& data) OVERRIDE; 954 virtual void OnConnectComplete(const MockConnect& data) OVERRIDE;
963 955
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1001 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE; 993 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE;
1002 virtual const BoundNetLog& NetLog() const OVERRIDE; 994 virtual const BoundNetLog& NetLog() const OVERRIDE;
1003 995
1004 // DatagramClientSocket implementation. 996 // DatagramClientSocket implementation.
1005 virtual int Connect(const IPEndPoint& address) OVERRIDE; 997 virtual int Connect(const IPEndPoint& address) OVERRIDE;
1006 998
1007 // AsyncSocket implementation. 999 // AsyncSocket implementation.
1008 virtual void OnReadComplete(const MockRead& data) OVERRIDE; 1000 virtual void OnReadComplete(const MockRead& data) OVERRIDE;
1009 virtual void OnConnectComplete(const MockConnect& data) OVERRIDE; 1001 virtual void OnConnectComplete(const MockConnect& data) OVERRIDE;
1010 1002
1011 void set_source_port(int port) { source_port_ = port;} 1003 void set_source_port(int port) { source_port_ = port; }
1012 1004
1013 private: 1005 private:
1014 int CompleteRead(); 1006 int CompleteRead();
1015 1007
1016 void RunCallbackAsync(const CompletionCallback& callback, int result); 1008 void RunCallbackAsync(const CompletionCallback& callback, int result);
1017 void RunCallback(const CompletionCallback& callback, int result); 1009 void RunCallback(const CompletionCallback& callback, int result);
1018 1010
1019 bool connected_; 1011 bool connected_;
1020 SocketDataProvider* data_; 1012 SocketDataProvider* data_;
1021 int read_offset_; 1013 int read_offset_;
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
1284 1276
1285 extern const char kSOCKS5OkRequest[]; 1277 extern const char kSOCKS5OkRequest[];
1286 extern const int kSOCKS5OkRequestLength; 1278 extern const int kSOCKS5OkRequestLength;
1287 1279
1288 extern const char kSOCKS5OkResponse[]; 1280 extern const char kSOCKS5OkResponse[];
1289 extern const int kSOCKS5OkResponseLength; 1281 extern const int kSOCKS5OkResponseLength;
1290 1282
1291 } // namespace net 1283 } // namespace net
1292 1284
1293 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ 1285 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698