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

Side by Side Diff: blimp/net/test_common.h

Issue 1452823011: Make PacketReader/PacketWriter interfaces async-only. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address wez feedback Created 5 years 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 BLIMP_NET_TEST_COMMON_H_ 5 #ifndef BLIMP_NET_TEST_COMMON_H_
6 #define BLIMP_NET_TEST_COMMON_H_ 6 #define BLIMP_NET_TEST_COMMON_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "blimp/common/proto/blimp_message.pb.h" 10 #include "blimp/common/proto/blimp_message.pb.h"
(...skipping 28 matching lines...) Expand all
39 message.SerializeToString(&expected_serialized); 39 message.SerializeToString(&expected_serialized);
40 arg.SerializeToString(&actual_serialized); 40 arg.SerializeToString(&actual_serialized);
41 return expected_serialized == actual_serialized; 41 return expected_serialized == actual_serialized;
42 } 42 }
43 43
44 // Checks if the contents of a buffer are an exact match with BlimpMessage. 44 // Checks if the contents of a buffer are an exact match with BlimpMessage.
45 // arg (type: net::DrainableIOBuffer*) The buffer to check. 45 // arg (type: net::DrainableIOBuffer*) The buffer to check.
46 // message (type: BlimpMessage) The message to compare with |arg|. 46 // message (type: BlimpMessage) The message to compare with |arg|.
47 MATCHER_P(BufferEqualsProto, message, "") { 47 MATCHER_P(BufferEqualsProto, message, "") {
48 BlimpMessage actual_message; 48 BlimpMessage actual_message;
49 actual_message.ParseFromArray(arg->data(), arg->BytesRemaining()); 49 actual_message.ParseFromArray(arg->data(), message.ByteSize());
50 std::string expected_serialized; 50 std::string expected_serialized;
51 std::string actual_serialized; 51 std::string actual_serialized;
52 message.SerializeToString(&expected_serialized); 52 message.SerializeToString(&expected_serialized);
53 actual_message.SerializeToString(&actual_serialized); 53 actual_message.SerializeToString(&actual_serialized);
54 return expected_serialized == actual_serialized; 54 return expected_serialized == actual_serialized;
55 } 55 }
56 56
57 // GMock action that writes data from a string to an IOBuffer. 57 // GMock action that writes data from a string to an IOBuffer.
58 // 58 //
59 // buf_idx (template parameter 0): 0-based index of the IOBuffer arg. 59 // buf_idx (template parameter 0): 0-based index of the IOBuffer arg.
60 // str: the string containing data to be written to the IOBuffer. 60 // str: the string containing data to be written to the IOBuffer.
61 ACTION_TEMPLATE(FillBufferFromString, 61 ACTION_TEMPLATE(FillBufferFromString,
62 HAS_1_TEMPLATE_PARAMS(int, buf_idx), 62 HAS_1_TEMPLATE_PARAMS(int, buf_idx),
63 AND_1_VALUE_PARAMS(str)) { 63 AND_1_VALUE_PARAMS(str)) {
64 memcpy(testing::get<buf_idx>(args)->data(), str.data(), str.size()); 64 memcpy(testing::get<buf_idx>(args)->data(), str.data(), str.size());
65 } 65 }
66 66
67 // GMock action that writes data from a blimp message to an IOBuffer . 67 // GMock action that writes data from a BlimpMessage to a GrowableIOBuffer.
68 // Advances the buffer's |offset| to the end of the message.
68 // 69 //
69 // buf_idx (template parameter 0): 0-based index of the IOBuffer arg. 70 // buf_idx (template parameter 0): 0-based index of the IOBuffer arg.
70 // message: the blimp message containing data to be written to the IOBuffer 71 // message: the blimp message containing data to be written to the IOBuffer
71 ACTION_TEMPLATE(FillBufferFromMessage, 72 ACTION_TEMPLATE(FillBufferFromMessage,
72 HAS_1_TEMPLATE_PARAMS(int, buf_idx), 73 HAS_1_TEMPLATE_PARAMS(int, buf_idx),
73 AND_1_VALUE_PARAMS(message)) { 74 AND_1_VALUE_PARAMS(message)) {
74 message->SerializeToArray(testing::get<buf_idx>(args)->data(), 75 message->SerializeToArray(testing::get<buf_idx>(args)->data(),
75 message->ByteSize()); 76 message->ByteSize());
76 } 77 }
77 78
79 // Calls |set_offset()| for a GrowableIOBuffer.
80 ACTION_TEMPLATE(SetBufferOffset,
81 HAS_1_TEMPLATE_PARAMS(int, buf_idx),
82 AND_1_VALUE_PARAMS(offset)) {
83 testing::get<buf_idx>(args)->set_offset(offset);
84 }
85
78 // Formats a string-based representation of a BlimpMessage header. 86 // Formats a string-based representation of a BlimpMessage header.
79 std::string EncodeHeader(size_t size); 87 std::string EncodeHeader(size_t size);
80 88
81 class MockStreamSocket : public net::StreamSocket { 89 class MockStreamSocket : public net::StreamSocket {
82 public: 90 public:
83 MockStreamSocket(); 91 MockStreamSocket();
84 virtual ~MockStreamSocket(); 92 virtual ~MockStreamSocket();
85 93
86 MOCK_METHOD3(Read, int(net::IOBuffer*, int, const net::CompletionCallback&)); 94 MOCK_METHOD3(Read, int(net::IOBuffer*, int, const net::CompletionCallback&));
87 MOCK_METHOD3(Write, int(net::IOBuffer*, int, const net::CompletionCallback&)); 95 MOCK_METHOD3(Write, int(net::IOBuffer*, int, const net::CompletionCallback&));
(...skipping 20 matching lines...) Expand all
108 MOCK_METHOD1(AddConnectionAttempts, void(const net::ConnectionAttempts&)); 116 MOCK_METHOD1(AddConnectionAttempts, void(const net::ConnectionAttempts&));
109 MOCK_CONST_METHOD0(GetTotalReceivedBytes, int64_t()); 117 MOCK_CONST_METHOD0(GetTotalReceivedBytes, int64_t());
110 }; 118 };
111 119
112 class MockPacketReader : public PacketReader { 120 class MockPacketReader : public PacketReader {
113 public: 121 public:
114 MockPacketReader(); 122 MockPacketReader();
115 ~MockPacketReader() override; 123 ~MockPacketReader() override;
116 124
117 MOCK_METHOD2(ReadPacket, 125 MOCK_METHOD2(ReadPacket,
118 int(const scoped_refptr<net::GrowableIOBuffer>&, 126 void(const scoped_refptr<net::GrowableIOBuffer>&,
119 const net::CompletionCallback&)); 127 const net::CompletionCallback&));
120 }; 128 };
121 129
122 class MockPacketWriter : public PacketWriter { 130 class MockPacketWriter : public PacketWriter {
123 public: 131 public:
124 MockPacketWriter(); 132 MockPacketWriter();
125 ~MockPacketWriter() override; 133 ~MockPacketWriter() override;
126 134
127 MOCK_METHOD2(WritePacket, 135 MOCK_METHOD2(WritePacket,
128 int(scoped_refptr<net::DrainableIOBuffer>, 136 void(scoped_refptr<net::DrainableIOBuffer>,
129 const net::CompletionCallback&)); 137 const net::CompletionCallback&));
130 }; 138 };
131 139
132 class MockConnectionErrorObserver : public ConnectionErrorObserver { 140 class MockConnectionErrorObserver : public ConnectionErrorObserver {
133 public: 141 public:
134 MockConnectionErrorObserver(); 142 MockConnectionErrorObserver();
135 ~MockConnectionErrorObserver() override; 143 ~MockConnectionErrorObserver() override;
136 144
137 MOCK_METHOD1(OnConnectionError, void(int error)); 145 MOCK_METHOD1(OnConnectionError, void(int error));
138 }; 146 };
139 147
(...skipping 13 matching lines...) Expand all
153 const net::CompletionCallback& callback)); 161 const net::CompletionCallback& callback));
154 }; 162 };
155 163
156 // Returns true if |buf| has a prefix of |str|. 164 // Returns true if |buf| has a prefix of |str|.
157 // Behavior is undefined if len(buf) < len(str). 165 // Behavior is undefined if len(buf) < len(str).
158 bool BufferStartsWith(net::GrowableIOBuffer* buf, const std::string& str); 166 bool BufferStartsWith(net::GrowableIOBuffer* buf, const std::string& str);
159 167
160 } // namespace blimp 168 } // namespace blimp
161 169
162 #endif // BLIMP_NET_TEST_COMMON_H_ 170 #endif // BLIMP_NET_TEST_COMMON_H_
OLDNEW
« blimp/net/stream_packet_writer.cc ('K') | « blimp/net/stream_packet_writer_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698