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

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

Issue 355493003: Update net/spdy naming per style guideline with clang_tidy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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
« no previous file with comments | « no previous file | net/spdy/spdy_frame_builder.cc » ('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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/hpack_input_stream.h" 5 #include "net/spdy/hpack_input_stream.h"
6 6
7 #include <bitset> 7 #include <bitset>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/strings/string_piece.h" 12 #include "base/strings/string_piece.h"
13 #include "net/spdy/hpack_constants.h" 13 #include "net/spdy/hpack_constants.h"
14 #include "net/spdy/spdy_test_utils.h" 14 #include "net/spdy/spdy_test_utils.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 16
17 namespace net { 17 namespace net {
18 18
19 namespace { 19 namespace {
20 20
21 using base::StringPiece; 21 using base::StringPiece;
22 using std::string; 22 using std::string;
23 using test::a2b_hex; 23 using test::a2b_hex;
24 24
25 const size_t kLiteralBound = 1024; 25 const size_t kLiteralBound = 1024;
26 26
27 class HpackInputStreamTest : public ::testing::Test { 27 class HpackInputStreamTest : public ::testing::Test {
28 protected: 28 public:
29 virtual void SetUp() { 29 virtual void SetUp() {
30 std::vector<HpackHuffmanSymbol> code = HpackHuffmanCode(); 30 std::vector<HpackHuffmanSymbol> code = HpackHuffmanCode();
31 EXPECT_TRUE(huffman_table.Initialize(&code[0], code.size())); 31 EXPECT_TRUE(huffman_table_.Initialize(&code[0], code.size()));
32 } 32 }
33 33
34 HpackHuffmanTable huffman_table; 34 protected:
35 HpackHuffmanTable huffman_table_;
35 }; 36 };
36 37
37 // Hex representation of encoded length and Huffman string. 38 // Hex representation of encoded length and Huffman string.
38 const char kEncodedHuffmanFixture[] = "31" // Length prefix. 39 const char kEncodedHuffmanFixture[] = "31" // Length prefix.
39 "e0d6cf9f6e8f9fd3e5f6fa76fefd3c7e" 40 "e0d6cf9f6e8f9fd3e5f6fa76fefd3c7e"
40 "df9eff1f2f0f3cfe9f6fcf7f8f879f61" 41 "df9eff1f2f0f3cfe9f6fcf7f8f879f61"
41 "ad4f4cc9a973a2200ec3725e18b1b74e" 42 "ad4f4cc9a973a2200ec3725e18b1b74e"
42 "3f"; 43 "3f";
43 44
44 const char kDecodedHuffmanFixture[] = 45 const char kDecodedHuffmanFixture[] =
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 EXPECT_TRUE(input_stream.HasMoreData()); 515 EXPECT_TRUE(input_stream.HasMoreData());
515 StringPiece string_piece; 516 StringPiece string_piece;
516 EXPECT_FALSE(input_stream.DecodeNextIdentityString(&string_piece)); 517 EXPECT_FALSE(input_stream.DecodeNextIdentityString(&string_piece));
517 } 518 }
518 519
519 TEST_F(HpackInputStreamTest, DecodeNextHuffmanString) { 520 TEST_F(HpackInputStreamTest, DecodeNextHuffmanString) {
520 string output, input(a2b_hex(kEncodedHuffmanFixture)); 521 string output, input(a2b_hex(kEncodedHuffmanFixture));
521 HpackInputStream input_stream(arraysize(kDecodedHuffmanFixture)-1, input); 522 HpackInputStream input_stream(arraysize(kDecodedHuffmanFixture)-1, input);
522 523
523 EXPECT_TRUE(input_stream.HasMoreData()); 524 EXPECT_TRUE(input_stream.HasMoreData());
524 EXPECT_TRUE(input_stream.DecodeNextHuffmanString(huffman_table, &output)); 525 EXPECT_TRUE(input_stream.DecodeNextHuffmanString(huffman_table_, &output));
525 EXPECT_EQ(kDecodedHuffmanFixture, output); 526 EXPECT_EQ(kDecodedHuffmanFixture, output);
526 EXPECT_FALSE(input_stream.HasMoreData()); 527 EXPECT_FALSE(input_stream.HasMoreData());
527 } 528 }
528 529
529 TEST_F(HpackInputStreamTest, DecodeNextHuffmanStringSizeLimit) { 530 TEST_F(HpackInputStreamTest, DecodeNextHuffmanStringSizeLimit) {
530 string output, input(a2b_hex(kEncodedHuffmanFixture)); 531 string output, input(a2b_hex(kEncodedHuffmanFixture));
531 // Max string literal is one byte shorter than the decoded fixture. 532 // Max string literal is one byte shorter than the decoded fixture.
532 HpackInputStream input_stream(arraysize(kDecodedHuffmanFixture)-2, input); 533 HpackInputStream input_stream(arraysize(kDecodedHuffmanFixture)-2, input);
533 534
534 // Decoded string overflows the max string literal. 535 // Decoded string overflows the max string literal.
535 EXPECT_TRUE(input_stream.HasMoreData()); 536 EXPECT_TRUE(input_stream.HasMoreData());
536 EXPECT_FALSE(input_stream.DecodeNextHuffmanString(huffman_table, &output)); 537 EXPECT_FALSE(input_stream.DecodeNextHuffmanString(huffman_table_, &output));
537 } 538 }
538 539
539 TEST_F(HpackInputStreamTest, DecodeNextHuffmanStringNotEnoughInput) { 540 TEST_F(HpackInputStreamTest, DecodeNextHuffmanStringNotEnoughInput) {
540 string output, input(a2b_hex(kEncodedHuffmanFixture)); 541 string output, input(a2b_hex(kEncodedHuffmanFixture));
541 input[0]++; // Input prefix is one byte larger than available input. 542 input[0]++; // Input prefix is one byte larger than available input.
542 HpackInputStream input_stream(arraysize(kDecodedHuffmanFixture)-1, input); 543 HpackInputStream input_stream(arraysize(kDecodedHuffmanFixture)-1, input);
543 544
544 // Not enough buffer for declared encoded length. 545 // Not enough buffer for declared encoded length.
545 EXPECT_TRUE(input_stream.HasMoreData()); 546 EXPECT_TRUE(input_stream.HasMoreData());
546 EXPECT_FALSE(input_stream.DecodeNextHuffmanString(huffman_table, &output)); 547 EXPECT_FALSE(input_stream.DecodeNextHuffmanString(huffman_table_, &output));
547 } 548 }
548 549
549 TEST_F(HpackInputStreamTest, PeekBitsAndConsume) { 550 TEST_F(HpackInputStreamTest, PeekBitsAndConsume) {
550 HpackInputStream input_stream(kLiteralBound, "\xad\xab\xad\xab\xad"); 551 HpackInputStream input_stream(kLiteralBound, "\xad\xab\xad\xab\xad");
551 552
552 uint32 bits = 0; 553 uint32 bits = 0;
553 size_t peeked_count = 0; 554 size_t peeked_count = 0;
554 555
555 // Read 0xad. 556 // Read 0xad.
556 EXPECT_TRUE(input_stream.PeekBits(&peeked_count, &bits)); 557 EXPECT_TRUE(input_stream.PeekBits(&peeked_count, &bits));
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 621
621 input_stream.ConsumeBits(6); 622 input_stream.ConsumeBits(6);
622 EXPECT_TRUE(input_stream.HasMoreData()); 623 EXPECT_TRUE(input_stream.HasMoreData());
623 input_stream.ConsumeByteRemainder(); 624 input_stream.ConsumeByteRemainder();
624 EXPECT_FALSE(input_stream.HasMoreData()); 625 EXPECT_FALSE(input_stream.HasMoreData());
625 } 626 }
626 627
627 } // namespace 628 } // namespace
628 629
629 } // namespace net 630 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/spdy/spdy_frame_builder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698