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

Side by Side Diff: net/spdy/spdy_alt_svc_wire_format_test.cc

Issue 1535363003: Switch to standard integer types in net/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: stddef 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
« no previous file with comments | « net/spdy/spdy_alt_svc_wire_format.cc ('k') | net/spdy/spdy_buffer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 #include "net/spdy/spdy_alt_svc_wire_format.h" 5 #include "net/spdy/spdy_alt_svc_wire_format.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "testing/gmock/include/gmock/gmock.h" 8 #include "testing/gmock/include/gmock/gmock.h"
9 #include "testing/platform_test.h" 9 #include "testing/platform_test.h"
10 10
(...skipping 12 matching lines...) Expand all
23 SpdyAltSvcWireFormat::SkipWhiteSpace(c, end); 23 SpdyAltSvcWireFormat::SkipWhiteSpace(c, end);
24 } 24 }
25 static bool PercentDecode(StringPiece::const_iterator c, 25 static bool PercentDecode(StringPiece::const_iterator c,
26 StringPiece::const_iterator end, 26 StringPiece::const_iterator end,
27 std::string* output) { 27 std::string* output) {
28 return SpdyAltSvcWireFormat::PercentDecode(c, end, output); 28 return SpdyAltSvcWireFormat::PercentDecode(c, end, output);
29 } 29 }
30 static bool ParseAltAuthority(StringPiece::const_iterator c, 30 static bool ParseAltAuthority(StringPiece::const_iterator c,
31 StringPiece::const_iterator end, 31 StringPiece::const_iterator end,
32 std::string* host, 32 std::string* host,
33 uint16* port) { 33 uint16_t* port) {
34 return SpdyAltSvcWireFormat::ParseAltAuthority(c, end, host, port); 34 return SpdyAltSvcWireFormat::ParseAltAuthority(c, end, host, port);
35 } 35 }
36 static bool ParsePositiveInteger16(StringPiece::const_iterator c, 36 static bool ParsePositiveInteger16(StringPiece::const_iterator c,
37 StringPiece::const_iterator end, 37 StringPiece::const_iterator end,
38 uint16* max_age) { 38 uint16_t* max_age) {
39 return SpdyAltSvcWireFormat::ParsePositiveInteger16(c, end, max_age); 39 return SpdyAltSvcWireFormat::ParsePositiveInteger16(c, end, max_age);
40 } 40 }
41 static bool ParsePositiveInteger32(StringPiece::const_iterator c, 41 static bool ParsePositiveInteger32(StringPiece::const_iterator c,
42 StringPiece::const_iterator end, 42 StringPiece::const_iterator end,
43 uint32* max_age) { 43 uint32_t* max_age) {
44 return SpdyAltSvcWireFormat::ParsePositiveInteger32(c, end, max_age); 44 return SpdyAltSvcWireFormat::ParsePositiveInteger32(c, end, max_age);
45 } 45 }
46 static bool ParseProbability(StringPiece::const_iterator c, 46 static bool ParseProbability(StringPiece::const_iterator c,
47 StringPiece::const_iterator end, 47 StringPiece::const_iterator end,
48 double* probability) { 48 double* probability) {
49 return SpdyAltSvcWireFormat::ParseProbability(c, end, probability); 49 return SpdyAltSvcWireFormat::ParseProbability(c, end, probability);
50 } 50 }
51 }; 51 };
52 52
53 } // namespace test 53 } // namespace test
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 EXPECT_FALSE(test::SpdyAltSvcWireFormatPeer::PercentDecode( 424 EXPECT_FALSE(test::SpdyAltSvcWireFormatPeer::PercentDecode(
425 input.begin(), input.end(), &output)) 425 input.begin(), input.end(), &output))
426 << input; 426 << input;
427 } 427 }
428 } 428 }
429 429
430 // Test ParseAltAuthority() on valid input. 430 // Test ParseAltAuthority() on valid input.
431 TEST(SpdyAltSvcWireFormatTest, ParseAltAuthorityValid) { 431 TEST(SpdyAltSvcWireFormatTest, ParseAltAuthorityValid) {
432 StringPiece input(":42"); 432 StringPiece input(":42");
433 std::string host; 433 std::string host;
434 uint16 port; 434 uint16_t port;
435 ASSERT_TRUE(test::SpdyAltSvcWireFormatPeer::ParseAltAuthority( 435 ASSERT_TRUE(test::SpdyAltSvcWireFormatPeer::ParseAltAuthority(
436 input.begin(), input.end(), &host, &port)); 436 input.begin(), input.end(), &host, &port));
437 EXPECT_TRUE(host.empty()); 437 EXPECT_TRUE(host.empty());
438 EXPECT_EQ(42, port); 438 EXPECT_EQ(42, port);
439 439
440 input = StringPiece("foo:137"); 440 input = StringPiece("foo:137");
441 ASSERT_TRUE(test::SpdyAltSvcWireFormatPeer::ParseAltAuthority( 441 ASSERT_TRUE(test::SpdyAltSvcWireFormatPeer::ParseAltAuthority(
442 input.begin(), input.end(), &host, &port)); 442 input.begin(), input.end(), &host, &port));
443 EXPECT_EQ("foo", host); 443 EXPECT_EQ("foo", host);
444 EXPECT_EQ(137, port); 444 EXPECT_EQ(137, port);
445 } 445 }
446 446
447 // Test ParseAltAuthority() on invalid input: empty string, no port, zero port, 447 // Test ParseAltAuthority() on invalid input: empty string, no port, zero port,
448 // non-digit characters following port. 448 // non-digit characters following port.
449 TEST(SpdyAltSvcWireFormatTest, ParseAltAuthorityInvalid) { 449 TEST(SpdyAltSvcWireFormatTest, ParseAltAuthorityInvalid) {
450 const char* invalid_input_array[] = {"", ":", "foo:", ":bar", ":0", "foo:0", 450 const char* invalid_input_array[] = {"", ":", "foo:", ":bar", ":0", "foo:0",
451 ":12bar", "foo:23bar", " ", ":12 ", "foo:12 "}; 451 ":12bar", "foo:23bar", " ", ":12 ", "foo:12 "};
452 for (const char* invalid_input : invalid_input_array) { 452 for (const char* invalid_input : invalid_input_array) {
453 StringPiece input(invalid_input); 453 StringPiece input(invalid_input);
454 std::string host; 454 std::string host;
455 uint16 port; 455 uint16_t port;
456 EXPECT_FALSE(test::SpdyAltSvcWireFormatPeer::ParseAltAuthority( 456 EXPECT_FALSE(test::SpdyAltSvcWireFormatPeer::ParseAltAuthority(
457 input.begin(), input.end(), &host, &port)) 457 input.begin(), input.end(), &host, &port))
458 << input; 458 << input;
459 } 459 }
460 } 460 }
461 461
462 // Test ParseInteger() on valid input. 462 // Test ParseInteger() on valid input.
463 TEST(SpdyAltSvcWireFormatTest, ParseIntegerValid) { 463 TEST(SpdyAltSvcWireFormatTest, ParseIntegerValid) {
464 StringPiece input("3"); 464 StringPiece input("3");
465 uint16 value; 465 uint16_t value;
466 ASSERT_TRUE(test::SpdyAltSvcWireFormatPeer::ParsePositiveInteger16( 466 ASSERT_TRUE(test::SpdyAltSvcWireFormatPeer::ParsePositiveInteger16(
467 input.begin(), input.end(), &value)); 467 input.begin(), input.end(), &value));
468 EXPECT_EQ(3, value); 468 EXPECT_EQ(3, value);
469 469
470 input = StringPiece("1337"); 470 input = StringPiece("1337");
471 ASSERT_TRUE(test::SpdyAltSvcWireFormatPeer::ParsePositiveInteger16( 471 ASSERT_TRUE(test::SpdyAltSvcWireFormatPeer::ParsePositiveInteger16(
472 input.begin(), input.end(), &value)); 472 input.begin(), input.end(), &value));
473 EXPECT_EQ(1337, value); 473 EXPECT_EQ(1337, value);
474 } 474 }
475 475
476 // Test ParseIntegerValid() on invalid input: empty, zero, non-numeric, trailing 476 // Test ParseIntegerValid() on invalid input: empty, zero, non-numeric, trailing
477 // non-numeric characters. 477 // non-numeric characters.
478 TEST(SpdyAltSvcWireFormatTest, ParseIntegerInvalid) { 478 TEST(SpdyAltSvcWireFormatTest, ParseIntegerInvalid) {
479 const char* invalid_input_array[] = {"", " ", "a", "0", "00", "1 ", "12b"}; 479 const char* invalid_input_array[] = {"", " ", "a", "0", "00", "1 ", "12b"};
480 for (const char* invalid_input : invalid_input_array) { 480 for (const char* invalid_input : invalid_input_array) {
481 StringPiece input(invalid_input); 481 StringPiece input(invalid_input);
482 uint16 value; 482 uint16_t value;
483 EXPECT_FALSE(test::SpdyAltSvcWireFormatPeer::ParsePositiveInteger16( 483 EXPECT_FALSE(test::SpdyAltSvcWireFormatPeer::ParsePositiveInteger16(
484 input.begin(), input.end(), &value)) 484 input.begin(), input.end(), &value))
485 << input; 485 << input;
486 } 486 }
487 } 487 }
488 488
489 // Test ParseIntegerValid() around overflow limit. 489 // Test ParseIntegerValid() around overflow limit.
490 TEST(SpdyAltSvcWireFormatTest, ParseIntegerOverflow) { 490 TEST(SpdyAltSvcWireFormatTest, ParseIntegerOverflow) {
491 // Largest possible uint16 value. 491 // Largest possible uint16_t value.
492 StringPiece input("65535"); 492 StringPiece input("65535");
493 uint16 value16; 493 uint16_t value16;
494 ASSERT_TRUE(test::SpdyAltSvcWireFormatPeer::ParsePositiveInteger16( 494 ASSERT_TRUE(test::SpdyAltSvcWireFormatPeer::ParsePositiveInteger16(
495 input.begin(), input.end(), &value16)); 495 input.begin(), input.end(), &value16));
496 EXPECT_EQ(65535, value16); 496 EXPECT_EQ(65535, value16);
497 497
498 // Overflow uint16, ParsePositiveInteger16() should return false. 498 // Overflow uint16_t, ParsePositiveInteger16() should return false.
499 input = StringPiece("65536"); 499 input = StringPiece("65536");
500 ASSERT_FALSE(test::SpdyAltSvcWireFormatPeer::ParsePositiveInteger16( 500 ASSERT_FALSE(test::SpdyAltSvcWireFormatPeer::ParsePositiveInteger16(
501 input.begin(), input.end(), &value16)); 501 input.begin(), input.end(), &value16));
502 502
503 // However, even if overflow is not checked for, 65536 overflows to 0, which 503 // However, even if overflow is not checked for, 65536 overflows to 0, which
504 // returns false anyway. Check for a larger number which overflows to 1. 504 // returns false anyway. Check for a larger number which overflows to 1.
505 input = StringPiece("65537"); 505 input = StringPiece("65537");
506 ASSERT_FALSE(test::SpdyAltSvcWireFormatPeer::ParsePositiveInteger16( 506 ASSERT_FALSE(test::SpdyAltSvcWireFormatPeer::ParsePositiveInteger16(
507 input.begin(), input.end(), &value16)); 507 input.begin(), input.end(), &value16));
508 508
509 // Largest possible uint32 value. 509 // Largest possible uint32_t value.
510 input = StringPiece("4294967295"); 510 input = StringPiece("4294967295");
511 uint32 value32; 511 uint32_t value32;
512 ASSERT_TRUE(test::SpdyAltSvcWireFormatPeer::ParsePositiveInteger32( 512 ASSERT_TRUE(test::SpdyAltSvcWireFormatPeer::ParsePositiveInteger32(
513 input.begin(), input.end(), &value32)); 513 input.begin(), input.end(), &value32));
514 EXPECT_EQ(4294967295, value32); 514 EXPECT_EQ(4294967295, value32);
515 515
516 // Overflow uint32, ParsePositiveInteger32() should return false. 516 // Overflow uint32_t, ParsePositiveInteger32() should return false.
517 input = StringPiece("4294967296"); 517 input = StringPiece("4294967296");
518 ASSERT_FALSE(test::SpdyAltSvcWireFormatPeer::ParsePositiveInteger32( 518 ASSERT_FALSE(test::SpdyAltSvcWireFormatPeer::ParsePositiveInteger32(
519 input.begin(), input.end(), &value32)); 519 input.begin(), input.end(), &value32));
520 520
521 // However, even if overflow is not checked for, 4294967296 overflows to 0, 521 // However, even if overflow is not checked for, 4294967296 overflows to 0,
522 // which returns false anyway. Check for a larger number which overflows to 522 // which returns false anyway. Check for a larger number which overflows to
523 // 1. 523 // 1.
524 input = StringPiece("4294967297"); 524 input = StringPiece("4294967297");
525 ASSERT_FALSE(test::SpdyAltSvcWireFormatPeer::ParsePositiveInteger32( 525 ASSERT_FALSE(test::SpdyAltSvcWireFormatPeer::ParsePositiveInteger32(
526 input.begin(), input.end(), &value32)); 526 input.begin(), input.end(), &value32));
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 StringPiece input(invalid_input); 587 StringPiece input(invalid_input);
588 double probability; 588 double probability;
589 EXPECT_FALSE(test::SpdyAltSvcWireFormatPeer::ParseProbability( 589 EXPECT_FALSE(test::SpdyAltSvcWireFormatPeer::ParseProbability(
590 input.begin(), input.end(), &probability)); 590 input.begin(), input.end(), &probability));
591 } 591 }
592 } 592 }
593 593
594 } // namespace 594 } // namespace
595 595
596 } // namespace net 596 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_alt_svc_wire_format.cc ('k') | net/spdy/spdy_buffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698