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

Side by Side Diff: net/tools/balsa/balsa_frame_test.cc

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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #include "net/tools/balsa/balsa_frame.h" 5 #include "net/tools/balsa/balsa_frame.h"
6 6
7 #include <iterator> 7 #include <iterator>
8 8
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/string_piece.h" 10 #include "base/strings/string_piece.h"
(...skipping 12 matching lines...) Expand all
23 using ::testing::SaveArg; 23 using ::testing::SaveArg;
24 24
25 class Visitor : public BalsaVisitorInterface { 25 class Visitor : public BalsaVisitorInterface {
26 public: 26 public:
27 virtual ~Visitor() {} 27 virtual ~Visitor() {}
28 MOCK_METHOD2(ProcessBodyInput, void(const char*, size_t)); 28 MOCK_METHOD2(ProcessBodyInput, void(const char*, size_t));
29 MOCK_METHOD2(ProcessBodyData, void(const char*, size_t)); 29 MOCK_METHOD2(ProcessBodyData, void(const char*, size_t));
30 MOCK_METHOD2(ProcessHeaderInput, void(const char*, size_t)); 30 MOCK_METHOD2(ProcessHeaderInput, void(const char*, size_t));
31 MOCK_METHOD2(ProcessTrailerInput, void(const char*, size_t)); 31 MOCK_METHOD2(ProcessTrailerInput, void(const char*, size_t));
32 MOCK_METHOD1(ProcessHeaders, void(const BalsaHeaders&)); 32 MOCK_METHOD1(ProcessHeaders, void(const BalsaHeaders&));
33 MOCK_METHOD8(ProcessRequestFirstLine, void(const char*, 33 MOCK_METHOD8(ProcessRequestFirstLine,
34 size_t, 34 void(const char*,
35 const char*, 35 size_t,
36 size_t, 36 const char*,
37 const char*, 37 size_t,
38 size_t, 38 const char*,
39 const char*, 39 size_t,
40 size_t)); 40 const char*,
41 MOCK_METHOD8(ProcessResponseFirstLine, void(const char*, 41 size_t));
42 size_t, 42 MOCK_METHOD8(ProcessResponseFirstLine,
43 const char*, 43 void(const char*,
44 size_t, 44 size_t,
45 const char*, 45 const char*,
46 size_t, 46 size_t,
47 const char*, 47 const char*,
48 size_t)); 48 size_t,
49 const char*,
50 size_t));
49 MOCK_METHOD2(ProcessChunkExtensions, void(const char*, size_t)); 51 MOCK_METHOD2(ProcessChunkExtensions, void(const char*, size_t));
50 MOCK_METHOD1(ProcessChunkLength, void(size_t)); 52 MOCK_METHOD1(ProcessChunkLength, void(size_t));
51 MOCK_METHOD0(HeaderDone, void()); 53 MOCK_METHOD0(HeaderDone, void());
52 MOCK_METHOD0(MessageDone, void()); 54 MOCK_METHOD0(MessageDone, void());
53 MOCK_METHOD1(HandleHeaderError, void(BalsaFrame*)); 55 MOCK_METHOD1(HandleHeaderError, void(BalsaFrame*));
54 MOCK_METHOD1(HandleHeaderWarning, void(BalsaFrame*)); 56 MOCK_METHOD1(HandleHeaderWarning, void(BalsaFrame*));
55 MOCK_METHOD1(HandleChunkingError, void(BalsaFrame*)); 57 MOCK_METHOD1(HandleChunkingError, void(BalsaFrame*));
56 MOCK_METHOD1(HandleBodyError, void(BalsaFrame*)); 58 MOCK_METHOD1(HandleBodyError, void(BalsaFrame*));
57 }; 59 };
58 60
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 ASSERT_FALSE(frame_->Error()); 148 ASSERT_FALSE(frame_->Error());
147 ASSERT_EQ(0u, frame_->BytesSafeToSplice()); 149 ASSERT_EQ(0u, frame_->BytesSafeToSplice());
148 ASSERT_EQ("GET / HTTP/1.0", StringPiece(line, line_length)); 150 ASSERT_EQ("GET / HTTP/1.0", StringPiece(line, line_length));
149 ASSERT_EQ("GET", StringPiece(method, method_length)); 151 ASSERT_EQ("GET", StringPiece(method, method_length));
150 ASSERT_EQ("/", StringPiece(request_uri, request_uri_length)); 152 ASSERT_EQ("/", StringPiece(request_uri, request_uri_length));
151 ASSERT_EQ("HTTP/1.0", StringPiece(version, version_length)); 153 ASSERT_EQ("HTTP/1.0", StringPiece(version, version_length));
152 ASSERT_EQ(input, StringPiece(header, header_length)); 154 ASSERT_EQ(input, StringPiece(header, header_length));
153 } 155 }
154 156
155 TEST_F(BalsaFrameTest, HeadResponse) { 157 TEST_F(BalsaFrameTest, HeadResponse) {
156 const char input[] = "HTTP/1.1 200 OK\r\n" 158 const char input[] =
159 "HTTP/1.1 200 OK\r\n"
157 "Content-type: text/plain\r\n" 160 "Content-type: text/plain\r\n"
158 "Content-Length: 14\r\n\r\n"; 161 "Content-Length: 14\r\n\r\n";
159 const char* line = NULL; 162 const char* line = NULL;
160 size_t line_length = 0; 163 size_t line_length = 0;
161 const char* version = NULL; 164 const char* version = NULL;
162 size_t version_length = 0; 165 size_t version_length = 0;
163 const char* status = NULL; 166 const char* status = NULL;
164 size_t status_length = 0; 167 size_t status_length = 0;
165 const char* reason = NULL; 168 const char* reason = NULL;
166 size_t reason_length = 0; 169 size_t reason_length = 0;
(...skipping 26 matching lines...) Expand all
193 ASSERT_EQ(strlen(input), read); 196 ASSERT_EQ(strlen(input), read);
194 ASSERT_EQ(BalsaFrameEnums::MESSAGE_FULLY_READ, frame_->ParseState()); 197 ASSERT_EQ(BalsaFrameEnums::MESSAGE_FULLY_READ, frame_->ParseState());
195 ASSERT_TRUE(frame_->MessageFullyRead()); 198 ASSERT_TRUE(frame_->MessageFullyRead());
196 ASSERT_FALSE(frame_->Error()); 199 ASSERT_FALSE(frame_->Error());
197 ASSERT_EQ(0u, frame_->BytesSafeToSplice()); 200 ASSERT_EQ(0u, frame_->BytesSafeToSplice());
198 201
199 ASSERT_EQ("HTTP/1.1 200 OK", StringPiece(line, line_length)); 202 ASSERT_EQ("HTTP/1.1 200 OK", StringPiece(line, line_length));
200 ASSERT_EQ("HTTP/1.1", StringPiece(version, version_length)); 203 ASSERT_EQ("HTTP/1.1", StringPiece(version, version_length));
201 ASSERT_EQ("200", StringPiece(status, status_length)); 204 ASSERT_EQ("200", StringPiece(status, status_length));
202 ASSERT_EQ("OK", StringPiece(reason, reason_length)); 205 ASSERT_EQ("OK", StringPiece(reason, reason_length));
203 ASSERT_EQ("HTTP/1.1 200 OK\r\n" 206 ASSERT_EQ(
204 "Content-type: text/plain\r\n" 207 "HTTP/1.1 200 OK\r\n"
205 "Content-Length: 14\r\n\r\n", 208 "Content-type: text/plain\r\n"
206 StringPiece(header, header_length)); 209 "Content-Length: 14\r\n\r\n",
210 StringPiece(header, header_length));
207 } 211 }
208 212
209 TEST_F(BalsaFrameTest, GetResponse) { 213 TEST_F(BalsaFrameTest, GetResponse) {
210 const char input[] = "HTTP/1.1 200 OK\r\n" 214 const char input[] =
215 "HTTP/1.1 200 OK\r\n"
211 "Content-type: text/plain\r\n" 216 "Content-type: text/plain\r\n"
212 "Content-Length: 14\r\n\r\n" 217 "Content-Length: 14\r\n\r\n"
213 "hello, world\r\n"; 218 "hello, world\r\n";
214 const char* line = NULL; 219 const char* line = NULL;
215 size_t line_length = 0; 220 size_t line_length = 0;
216 const char* version = NULL; 221 const char* version = NULL;
217 size_t version_length = 0; 222 size_t version_length = 0;
218 const char* status = NULL; 223 const char* status = NULL;
219 size_t status_length = 0; 224 size_t status_length = 0;
220 const char* reason = NULL; 225 const char* reason = NULL;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 ASSERT_EQ(strlen(input), read); 266 ASSERT_EQ(strlen(input), read);
262 ASSERT_EQ(BalsaFrameEnums::MESSAGE_FULLY_READ, frame_->ParseState()); 267 ASSERT_EQ(BalsaFrameEnums::MESSAGE_FULLY_READ, frame_->ParseState());
263 ASSERT_TRUE(frame_->MessageFullyRead()); 268 ASSERT_TRUE(frame_->MessageFullyRead());
264 ASSERT_FALSE(frame_->Error()); 269 ASSERT_FALSE(frame_->Error());
265 ASSERT_EQ(0u, frame_->BytesSafeToSplice()); 270 ASSERT_EQ(0u, frame_->BytesSafeToSplice());
266 271
267 ASSERT_EQ("HTTP/1.1 200 OK", StringPiece(line, line_length)); 272 ASSERT_EQ("HTTP/1.1 200 OK", StringPiece(line, line_length));
268 ASSERT_EQ("HTTP/1.1", StringPiece(version, version_length)); 273 ASSERT_EQ("HTTP/1.1", StringPiece(version, version_length));
269 ASSERT_EQ("200", StringPiece(status, status_length)); 274 ASSERT_EQ("200", StringPiece(status, status_length));
270 ASSERT_EQ("OK", StringPiece(reason, reason_length)); 275 ASSERT_EQ("OK", StringPiece(reason, reason_length));
271 ASSERT_EQ("HTTP/1.1 200 OK\r\n" 276 ASSERT_EQ(
272 "Content-type: text/plain\r\n" 277 "HTTP/1.1 200 OK\r\n"
273 "Content-Length: 14\r\n\r\n", 278 "Content-type: text/plain\r\n"
274 StringPiece(header, header_length)); 279 "Content-Length: 14\r\n\r\n",
280 StringPiece(header, header_length));
275 ASSERT_EQ("hello, world\r\n", StringPiece(body, body_length)); 281 ASSERT_EQ("hello, world\r\n", StringPiece(body, body_length));
276 ASSERT_EQ("hello, world\r\n", StringPiece(body_data, body_data_length)); 282 ASSERT_EQ("hello, world\r\n", StringPiece(body_data, body_data_length));
277 } 283 }
278 284
279 TEST_F(BalsaFrameTest, Reset) { 285 TEST_F(BalsaFrameTest, Reset) {
280 const char input[] = "GET / HTTP/1.0\r\nkey1: value1\r\n\r\n"; 286 const char input[] = "GET / HTTP/1.0\r\nkey1: value1\r\n\r\n";
281 287
282 { 288 {
283 InSequence s; 289 InSequence s;
284 EXPECT_CALL(*visitor_, ProcessRequestFirstLine(_, _, _, _, _, _, _, _)); 290 EXPECT_CALL(*visitor_, ProcessRequestFirstLine(_, _, _, _, _, _, _, _));
(...skipping 12 matching lines...) Expand all
297 ASSERT_FALSE(frame_->Error()); 303 ASSERT_FALSE(frame_->Error());
298 304
299 frame_->Reset(); 305 frame_->Reset();
300 ASSERT_EQ(BalsaFrameEnums::READING_HEADER_AND_FIRSTLINE, 306 ASSERT_EQ(BalsaFrameEnums::READING_HEADER_AND_FIRSTLINE,
301 frame_->ParseState()); 307 frame_->ParseState());
302 ASSERT_FALSE(frame_->MessageFullyRead()); 308 ASSERT_FALSE(frame_->MessageFullyRead());
303 ASSERT_FALSE(frame_->Error()); 309 ASSERT_FALSE(frame_->Error());
304 } 310 }
305 311
306 TEST_F(BalsaFrameTest, InvalidStatusCode) { 312 TEST_F(BalsaFrameTest, InvalidStatusCode) {
307 const char input[] = "HTTP/1.1 InvalidStatusCode OK\r\n" 313 const char input[] =
314 "HTTP/1.1 InvalidStatusCode OK\r\n"
308 "Content-type: text/plain\r\n" 315 "Content-type: text/plain\r\n"
309 "Content-Length: 14\r\n\r\n" 316 "Content-Length: 14\r\n\r\n"
310 "hello, world\r\n"; 317 "hello, world\r\n";
311 318
312 frame_->set_balsa_headers(frame_headers_.get()); 319 frame_->set_balsa_headers(frame_headers_.get());
313 frame_->set_is_request(false); 320 frame_->set_is_request(false);
314 321
315 { 322 {
316 InSequence s; 323 InSequence s;
317 EXPECT_CALL(*visitor_, HandleHeaderError(frame_.get())); 324 EXPECT_CALL(*visitor_, HandleHeaderError(frame_.get()));
318 } 325 }
319 326
320 size_t read = frame_->ProcessInput(input, strlen(input)); 327 size_t read = frame_->ProcessInput(input, strlen(input));
321 ASSERT_EQ(30u, read); 328 ASSERT_EQ(30u, read);
322 ASSERT_EQ(BalsaFrameEnums::PARSE_ERROR, frame_->ParseState()); 329 ASSERT_EQ(BalsaFrameEnums::PARSE_ERROR, frame_->ParseState());
323 ASSERT_EQ(BalsaFrameEnums::FAILED_CONVERTING_STATUS_CODE_TO_INT, 330 ASSERT_EQ(BalsaFrameEnums::FAILED_CONVERTING_STATUS_CODE_TO_INT,
324 frame_->ErrorCode()); 331 frame_->ErrorCode());
325 ASSERT_FALSE(frame_->MessageFullyRead()); 332 ASSERT_FALSE(frame_->MessageFullyRead());
326 ASSERT_TRUE(frame_->Error()); 333 ASSERT_TRUE(frame_->Error());
327 ASSERT_EQ(0u, frame_->BytesSafeToSplice()); 334 ASSERT_EQ(0u, frame_->BytesSafeToSplice());
328 } 335 }
329 336
330 TEST_F(BalsaFrameTest, ResetError) { 337 TEST_F(BalsaFrameTest, ResetError) {
331 const char input[] = "HTTP/1.1 InvalidStatusCode OK\r\n" 338 const char input[] =
339 "HTTP/1.1 InvalidStatusCode OK\r\n"
332 "Content-type: text/plain\r\n" 340 "Content-type: text/plain\r\n"
333 "Content-Length: 14\r\n\r\n" 341 "Content-Length: 14\r\n\r\n"
334 "hello, world\r\n"; 342 "hello, world\r\n";
335 343
336 frame_->set_balsa_headers(frame_headers_.get()); 344 frame_->set_balsa_headers(frame_headers_.get());
337 frame_->set_is_request(false); 345 frame_->set_is_request(false);
338 346
339 { 347 {
340 InSequence s; 348 InSequence s;
341 EXPECT_CALL(*visitor_, HandleHeaderError(frame_.get())); 349 EXPECT_CALL(*visitor_, HandleHeaderError(frame_.get()));
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 size_t read = frame_->ProcessInput(input, strlen(input)); 399 size_t read = frame_->ProcessInput(input, strlen(input));
392 ASSERT_EQ(0u, read); 400 ASSERT_EQ(0u, read);
393 ASSERT_EQ(BalsaFrameEnums::PARSE_ERROR, frame_->ParseState()); 401 ASSERT_EQ(BalsaFrameEnums::PARSE_ERROR, frame_->ParseState());
394 ASSERT_EQ(BalsaFrameEnums::HEADERS_TOO_LONG, frame_->ErrorCode()); 402 ASSERT_EQ(BalsaFrameEnums::HEADERS_TOO_LONG, frame_->ErrorCode());
395 ASSERT_FALSE(frame_->MessageFullyRead()); 403 ASSERT_FALSE(frame_->MessageFullyRead());
396 ASSERT_TRUE(frame_->Error()); 404 ASSERT_TRUE(frame_->Error());
397 ASSERT_EQ(0u, frame_->BytesSafeToSplice()); 405 ASSERT_EQ(0u, frame_->BytesSafeToSplice());
398 } 406 }
399 407
400 TEST_F(BalsaFrameTest, InvalidHeader) { 408 TEST_F(BalsaFrameTest, InvalidHeader) {
401 const char input[] = "GET / HTTP/1.0\r\n" 409 const char input[] =
410 "GET / HTTP/1.0\r\n"
402 "foo bar baz\r\n" 411 "foo bar baz\r\n"
403 "Content-Type: text/plain\r\n\r\n"; 412 "Content-Type: text/plain\r\n\r\n";
404 const char* line = NULL; 413 const char* line = NULL;
405 size_t line_length = 0; 414 size_t line_length = 0;
406 const char* method = NULL; 415 const char* method = NULL;
407 size_t method_length = 0; 416 size_t method_length = 0;
408 const char* request_uri = NULL; 417 const char* request_uri = NULL;
409 size_t request_uri_length = 0; 418 size_t request_uri_length = 0;
410 const char* version = NULL; 419 const char* version = NULL;
411 size_t version_length = 0; 420 size_t version_length = 0;
(...skipping 22 matching lines...) Expand all
434 ASSERT_EQ(strlen(input), read); 443 ASSERT_EQ(strlen(input), read);
435 ASSERT_EQ(BalsaFrameEnums::MESSAGE_FULLY_READ, frame_->ParseState()); 444 ASSERT_EQ(BalsaFrameEnums::MESSAGE_FULLY_READ, frame_->ParseState());
436 ASSERT_EQ(BalsaFrameEnums::HEADER_MISSING_COLON, frame_->ErrorCode()); 445 ASSERT_EQ(BalsaFrameEnums::HEADER_MISSING_COLON, frame_->ErrorCode());
437 ASSERT_TRUE(frame_->MessageFullyRead()); 446 ASSERT_TRUE(frame_->MessageFullyRead());
438 ASSERT_FALSE(frame_->Error()); 447 ASSERT_FALSE(frame_->Error());
439 ASSERT_EQ(0u, frame_->BytesSafeToSplice()); 448 ASSERT_EQ(0u, frame_->BytesSafeToSplice());
440 ASSERT_EQ("GET / HTTP/1.0", StringPiece(line, line_length)); 449 ASSERT_EQ("GET / HTTP/1.0", StringPiece(line, line_length));
441 ASSERT_EQ("GET", StringPiece(method, method_length)); 450 ASSERT_EQ("GET", StringPiece(method, method_length));
442 ASSERT_EQ("/", StringPiece(request_uri, request_uri_length)); 451 ASSERT_EQ("/", StringPiece(request_uri, request_uri_length));
443 ASSERT_EQ("HTTP/1.0", StringPiece(version, version_length)); 452 ASSERT_EQ("HTTP/1.0", StringPiece(version, version_length));
444 ASSERT_EQ(2, std::distance(frame_headers_->header_lines_begin(), 453 ASSERT_EQ(2,
445 frame_headers_->header_lines_end())); 454 std::distance(frame_headers_->header_lines_begin(),
455 frame_headers_->header_lines_end()));
446 } 456 }
447 457
448 TEST_F(BalsaFrameTest, GetResponseSplit) { 458 TEST_F(BalsaFrameTest, GetResponseSplit) {
449 const char input[] = "HTTP/1.1 200 OK\r\n" 459 const char input[] =
460 "HTTP/1.1 200 OK\r\n"
450 "Content-type: text/plain\r\n" 461 "Content-type: text/plain\r\n"
451 "Content-Length: 14\r\n\r\n" 462 "Content-Length: 14\r\n\r\n"
452 "hello"; 463 "hello";
453 const char input2[] = ", world\r\n"; 464 const char input2[] = ", world\r\n";
454 const char* body1 = NULL; 465 const char* body1 = NULL;
455 size_t body1_length = 0; 466 size_t body1_length = 0;
456 const char* body1_data = NULL; 467 const char* body1_data = NULL;
457 size_t body1_data_length = 0; 468 size_t body1_data_length = 0;
458 const char* body2 = NULL; 469 const char* body2 = NULL;
459 size_t body2_length = 0; 470 size_t body2_length = 0;
460 const char* body2_data = NULL; 471 const char* body2_data = NULL;
461 size_t body2_data_length = 0; 472 size_t body2_data_length = 0;
462 testing::MockFunction<void(int)> checkpoint; 473 testing::MockFunction<void(int)> checkpoint;
463 474
464 frame_->set_balsa_headers(frame_headers_.get()); 475 frame_->set_balsa_headers(frame_headers_.get());
465 frame_->set_is_request(false); 476 frame_->set_is_request(false);
466 477
467 { 478 {
468 InSequence s; 479 InSequence s;
469 EXPECT_CALL(*visitor_, ProcessResponseFirstLine(_, _, _, _, _, _, _, _)); 480 EXPECT_CALL(*visitor_, ProcessResponseFirstLine(_, _, _, _, _, _, _, _));
470 EXPECT_CALL(*visitor_, ProcessHeaderInput(_, _)); 481 EXPECT_CALL(*visitor_, ProcessHeaderInput(_, _));
471 EXPECT_CALL(*visitor_, ProcessHeaders(_)); 482 EXPECT_CALL(*visitor_, ProcessHeaders(_));
472 EXPECT_CALL(*visitor_, HeaderDone()); 483 EXPECT_CALL(*visitor_, HeaderDone());
473 EXPECT_CALL(checkpoint, Call(0)); 484 EXPECT_CALL(checkpoint, Call(0));
474 EXPECT_CALL(*visitor_, ProcessBodyInput(_, _)) 485 EXPECT_CALL(*visitor_, ProcessBodyInput(_, _))
475 .WillOnce(DoAll(SaveArg<0>(&body1), SaveArg<1>(&body1_length))); 486 .WillOnce(DoAll(SaveArg<0>(&body1), SaveArg<1>(&body1_length)));
476 EXPECT_CALL(*visitor_, ProcessBodyData(_, _)) 487 EXPECT_CALL(*visitor_, ProcessBodyData(_, _)).WillOnce(
477 .WillOnce(DoAll(SaveArg<0>(&body1_data), 488 DoAll(SaveArg<0>(&body1_data), SaveArg<1>(&body1_data_length)));
478 SaveArg<1>(&body1_data_length)));
479 EXPECT_CALL(checkpoint, Call(1)); 489 EXPECT_CALL(checkpoint, Call(1));
480 EXPECT_CALL(*visitor_, ProcessBodyInput(_, _)) 490 EXPECT_CALL(*visitor_, ProcessBodyInput(_, _))
481 .WillOnce(DoAll(SaveArg<0>(&body2), SaveArg<1>(&body2_length))); 491 .WillOnce(DoAll(SaveArg<0>(&body2), SaveArg<1>(&body2_length)));
482 EXPECT_CALL(*visitor_, ProcessBodyData(_, _)) 492 EXPECT_CALL(*visitor_, ProcessBodyData(_, _)).WillOnce(
483 .WillOnce(DoAll(SaveArg<0>(&body2_data), 493 DoAll(SaveArg<0>(&body2_data), SaveArg<1>(&body2_data_length)));
484 SaveArg<1>(&body2_data_length)));
485 EXPECT_CALL(*visitor_, MessageDone()); 494 EXPECT_CALL(*visitor_, MessageDone());
486 } 495 }
487 496
488 size_t read = frame_->ProcessInput(input, strlen(input)); 497 size_t read = frame_->ProcessInput(input, strlen(input));
489 ASSERT_EQ(65u, read); 498 ASSERT_EQ(65u, read);
490 ASSERT_EQ(BalsaFrameEnums::READING_CONTENT, frame_->ParseState()); 499 ASSERT_EQ(BalsaFrameEnums::READING_CONTENT, frame_->ParseState());
491 checkpoint.Call(0); 500 checkpoint.Call(0);
492 read += frame_->ProcessInput(&input[read], strlen(input) - read); 501 read += frame_->ProcessInput(&input[read], strlen(input) - read);
493 ASSERT_EQ(strlen(input), read); 502 ASSERT_EQ(strlen(input), read);
494 ASSERT_EQ(BalsaFrameEnums::READING_CONTENT, frame_->ParseState()); 503 ASSERT_EQ(BalsaFrameEnums::READING_CONTENT, frame_->ParseState());
495 checkpoint.Call(1); 504 checkpoint.Call(1);
496 ASSERT_EQ(9u, frame_->BytesSafeToSplice()); 505 ASSERT_EQ(9u, frame_->BytesSafeToSplice());
497 read = frame_->ProcessInput(input2, strlen(input2)); 506 read = frame_->ProcessInput(input2, strlen(input2));
498 ASSERT_EQ(strlen(input2), read); 507 ASSERT_EQ(strlen(input2), read);
499 508
500 ASSERT_EQ(BalsaFrameEnums::MESSAGE_FULLY_READ, frame_->ParseState()); 509 ASSERT_EQ(BalsaFrameEnums::MESSAGE_FULLY_READ, frame_->ParseState());
501 ASSERT_TRUE(frame_->MessageFullyRead()); 510 ASSERT_TRUE(frame_->MessageFullyRead());
502 ASSERT_FALSE(frame_->Error()); 511 ASSERT_FALSE(frame_->Error());
503 ASSERT_EQ(0u, frame_->BytesSafeToSplice()); 512 ASSERT_EQ(0u, frame_->BytesSafeToSplice());
504 ASSERT_EQ("hello", StringPiece(body1, body1_length)); 513 ASSERT_EQ("hello", StringPiece(body1, body1_length));
505 ASSERT_EQ("hello", StringPiece(body1_data, body1_data_length)); 514 ASSERT_EQ("hello", StringPiece(body1_data, body1_data_length));
506 ASSERT_EQ(", world\r\n", StringPiece(body2, body2_length)); 515 ASSERT_EQ(", world\r\n", StringPiece(body2, body2_length));
507 ASSERT_EQ(", world\r\n", StringPiece(body2_data, body2_data_length)); 516 ASSERT_EQ(", world\r\n", StringPiece(body2_data, body2_data_length));
508 } 517 }
509 518
510 TEST_F(BalsaFrameTest, GetResponseBytesSpliced) { 519 TEST_F(BalsaFrameTest, GetResponseBytesSpliced) {
511 const char input[] = "HTTP/1.1 200 OK\r\n" 520 const char input[] =
521 "HTTP/1.1 200 OK\r\n"
512 "Content-type: text/plain\r\n" 522 "Content-type: text/plain\r\n"
513 "Content-Length: 14\r\n\r\n" 523 "Content-Length: 14\r\n\r\n"
514 "hello"; 524 "hello";
515 testing::MockFunction<void(int)> checkpoint; 525 testing::MockFunction<void(int)> checkpoint;
516 526
517 frame_->set_balsa_headers(frame_headers_.get()); 527 frame_->set_balsa_headers(frame_headers_.get());
518 frame_->set_is_request(false); 528 frame_->set_is_request(false);
519 529
520 { 530 {
521 InSequence s; 531 InSequence s;
(...skipping 24 matching lines...) Expand all
546 checkpoint.Call(2); 556 checkpoint.Call(2);
547 frame_->BytesSpliced(4); 557 frame_->BytesSpliced(4);
548 ASSERT_EQ(BalsaFrameEnums::MESSAGE_FULLY_READ, frame_->ParseState()); 558 ASSERT_EQ(BalsaFrameEnums::MESSAGE_FULLY_READ, frame_->ParseState());
549 559
550 ASSERT_TRUE(frame_->MessageFullyRead()); 560 ASSERT_TRUE(frame_->MessageFullyRead());
551 ASSERT_FALSE(frame_->Error()); 561 ASSERT_FALSE(frame_->Error());
552 ASSERT_EQ(0u, frame_->BytesSafeToSplice()); 562 ASSERT_EQ(0u, frame_->BytesSafeToSplice());
553 } 563 }
554 564
555 TEST_F(BalsaFrameTest, GetResponseBytesSplicedTooMany) { 565 TEST_F(BalsaFrameTest, GetResponseBytesSplicedTooMany) {
556 const char input[] = "HTTP/1.1 200 OK\r\n" 566 const char input[] =
567 "HTTP/1.1 200 OK\r\n"
557 "Content-type: text/plain\r\n" 568 "Content-type: text/plain\r\n"
558 "Content-Length: 14\r\n\r\n" 569 "Content-Length: 14\r\n\r\n"
559 "hello"; 570 "hello";
560 testing::MockFunction<void(int)> checkpoint; 571 testing::MockFunction<void(int)> checkpoint;
561 572
562 frame_->set_balsa_headers(frame_headers_.get()); 573 frame_->set_balsa_headers(frame_headers_.get());
563 frame_->set_is_request(false); 574 frame_->set_is_request(false);
564 575
565 { 576 {
566 InSequence s; 577 InSequence s;
(...skipping 23 matching lines...) Expand all
590 ASSERT_TRUE(frame_->Error()); 601 ASSERT_TRUE(frame_->Error());
591 ASSERT_EQ( 602 ASSERT_EQ(
592 BalsaFrameEnums::CALLED_BYTES_SPLICED_AND_EXCEEDED_SAFE_SPLICE_AMOUNT, 603 BalsaFrameEnums::CALLED_BYTES_SPLICED_AND_EXCEEDED_SAFE_SPLICE_AMOUNT,
593 frame_->ErrorCode()); 604 frame_->ErrorCode());
594 ASSERT_EQ(0u, frame_->BytesSafeToSplice()); 605 ASSERT_EQ(0u, frame_->BytesSafeToSplice());
595 } 606 }
596 607
597 } // namespace 608 } // namespace
598 609
599 } // namespace net 610 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698