OLD | NEW |
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/hpack_header_table.h" | 5 #include "net/spdy/hpack/hpack_header_table.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | |
13 #include "base/macros.h" | 12 #include "base/macros.h" |
14 #include "net/spdy/hpack/hpack_constants.h" | 13 #include "net/spdy/hpack/hpack_constants.h" |
15 #include "net/spdy/hpack/hpack_entry.h" | 14 #include "net/spdy/hpack/hpack_entry.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
17 | 16 |
18 namespace net { | 17 namespace net { |
19 | 18 |
20 using base::StringPiece; | 19 using base::StringPiece; |
21 using std::distance; | 20 using std::distance; |
22 using std::string; | 21 using std::string; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 | 67 |
69 namespace { | 68 namespace { |
70 | 69 |
71 class HpackHeaderTableTest : public ::testing::Test { | 70 class HpackHeaderTableTest : public ::testing::Test { |
72 protected: | 71 protected: |
73 typedef std::vector<HpackEntry> HpackEntryVector; | 72 typedef std::vector<HpackEntry> HpackEntryVector; |
74 | 73 |
75 HpackHeaderTableTest() : table_(), peer_(&table_) {} | 74 HpackHeaderTableTest() : table_(), peer_(&table_) {} |
76 | 75 |
77 // Returns an entry whose Size() is equal to the given one. | 76 // Returns an entry whose Size() is equal to the given one. |
78 static HpackEntry MakeEntryOfSize(uint32 size) { | 77 static HpackEntry MakeEntryOfSize(uint32_t size) { |
79 EXPECT_GE(size, HpackEntry::kSizeOverhead); | 78 EXPECT_GE(size, HpackEntry::kSizeOverhead); |
80 string name((size - HpackEntry::kSizeOverhead) / 2, 'n'); | 79 string name((size - HpackEntry::kSizeOverhead) / 2, 'n'); |
81 string value(size - HpackEntry::kSizeOverhead - name.size(), 'v'); | 80 string value(size - HpackEntry::kSizeOverhead - name.size(), 'v'); |
82 HpackEntry entry(name, value, false, 0); | 81 HpackEntry entry(name, value, false, 0); |
83 EXPECT_EQ(size, entry.Size()); | 82 EXPECT_EQ(size, entry.Size()); |
84 return entry; | 83 return entry; |
85 } | 84 } |
86 | 85 |
87 // Returns a vector of entries whose total size is equal to the given | 86 // Returns a vector of entries whose total size is equal to the given |
88 // one. | 87 // one. |
89 static HpackEntryVector MakeEntriesOfTotalSize(uint32 total_size) { | 88 static HpackEntryVector MakeEntriesOfTotalSize(uint32_t total_size) { |
90 EXPECT_GE(total_size, HpackEntry::kSizeOverhead); | 89 EXPECT_GE(total_size, HpackEntry::kSizeOverhead); |
91 uint32 entry_size = HpackEntry::kSizeOverhead; | 90 uint32_t entry_size = HpackEntry::kSizeOverhead; |
92 uint32 remaining_size = total_size; | 91 uint32_t remaining_size = total_size; |
93 HpackEntryVector entries; | 92 HpackEntryVector entries; |
94 while (remaining_size > 0) { | 93 while (remaining_size > 0) { |
95 EXPECT_LE(entry_size, remaining_size); | 94 EXPECT_LE(entry_size, remaining_size); |
96 entries.push_back(MakeEntryOfSize(entry_size)); | 95 entries.push_back(MakeEntryOfSize(entry_size)); |
97 remaining_size -= entry_size; | 96 remaining_size -= entry_size; |
98 entry_size = std::min(remaining_size, entry_size + 32); | 97 entry_size = std::min(remaining_size, entry_size + 32); |
99 } | 98 } |
100 return entries; | 99 return entries; |
101 } | 100 } |
102 | 101 |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 HpackEntry entry2(DynamicEntry("name", "value")); | 434 HpackEntry entry2(DynamicEntry("name", "value")); |
436 | 435 |
437 HpackHeaderTable::EntryComparator comparator; | 436 HpackHeaderTable::EntryComparator comparator; |
438 EXPECT_FALSE(comparator(&entry1, &entry1)); | 437 EXPECT_FALSE(comparator(&entry1, &entry1)); |
439 EXPECT_FALSE(comparator(&entry2, &entry2)); | 438 EXPECT_FALSE(comparator(&entry2, &entry2)); |
440 } | 439 } |
441 | 440 |
442 } // namespace | 441 } // namespace |
443 | 442 |
444 } // namespace net | 443 } // namespace net |
OLD | NEW |