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

Side by Side Diff: net/quic/quic_protocol_test.cc

Issue 605163004: Land Recent QUIC Changes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@Final_0925
Patch Set: Created 6 years, 2 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
« no previous file with comments | « net/quic/quic_protocol.cc ('k') | net/quic/quic_sent_packet_manager.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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/quic/quic_protocol.h" 5 #include "net/quic/quic_protocol.h"
6 6
7 #include "base/stl_util.h" 7 #include "base/stl_util.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace net { 10 namespace net {
11 namespace test { 11 namespace test {
12 namespace { 12 namespace {
13 13
14 TEST(QuicProtocolTest, AdjustErrorForVersion) { 14 TEST(QuicProtocolTest, AdjustErrorForVersion) {
15 ASSERT_EQ(8, QUIC_STREAM_LAST_ERROR) 15 ASSERT_EQ(8, QUIC_STREAM_LAST_ERROR)
16 << "Any additions to QuicRstStreamErrorCode require an addition to " 16 << "Any additions to QuicRstStreamErrorCode require an addition to "
17 << "AdjustErrorForVersion and this associated test."; 17 << "AdjustErrorForVersion and this associated test.";
18 18
19 EXPECT_EQ(QUIC_STREAM_NO_ERROR,
20 AdjustErrorForVersion(QUIC_RST_FLOW_CONTROL_ACCOUNTING,
21 QUIC_VERSION_16));
22 EXPECT_EQ(QUIC_RST_FLOW_CONTROL_ACCOUNTING, AdjustErrorForVersion( 19 EXPECT_EQ(QUIC_RST_FLOW_CONTROL_ACCOUNTING, AdjustErrorForVersion(
23 QUIC_RST_FLOW_CONTROL_ACCOUNTING, 20 QUIC_RST_FLOW_CONTROL_ACCOUNTING,
24 QUIC_VERSION_18)); 21 QUIC_VERSION_18));
25 } 22 }
26 23
27 TEST(QuicProtocolTest, MakeQuicTag) { 24 TEST(QuicProtocolTest, MakeQuicTag) {
28 QuicTag tag = MakeQuicTag('A', 'B', 'C', 'D'); 25 QuicTag tag = MakeQuicTag('A', 'B', 'C', 'D');
29 char bytes[4]; 26 char bytes[4];
30 memcpy(bytes, &tag, 4); 27 memcpy(bytes, &tag, 4);
31 EXPECT_EQ('A', bytes[0]); 28 EXPECT_EQ('A', bytes[0]);
(...skipping 30 matching lines...) Expand all
62 59
63 // TODO(rtenneti): Enable checking of Log(ERROR) messages. 60 // TODO(rtenneti): Enable checking of Log(ERROR) messages.
64 #if 0 61 #if 0
65 // Any logs would indicate an unsupported version which we don't expect. 62 // Any logs would indicate an unsupported version which we don't expect.
66 ScopedMockLog log(kDoNotCaptureLogsYet); 63 ScopedMockLog log(kDoNotCaptureLogsYet);
67 EXPECT_CALL(log, Log(_, _, _)).Times(0); 64 EXPECT_CALL(log, Log(_, _, _)).Times(0);
68 log.StartCapturingLogs(); 65 log.StartCapturingLogs();
69 #endif 66 #endif
70 67
71 // Explicitly test a specific version. 68 // Explicitly test a specific version.
72 EXPECT_EQ(MakeQuicTag('Q', '0', '1', '6'), 69 EXPECT_EQ(MakeQuicTag('Q', '0', '1', '9'),
73 QuicVersionToQuicTag(QUIC_VERSION_16)); 70 QuicVersionToQuicTag(QUIC_VERSION_19));
74 71
75 // Loop over all supported versions and make sure that we never hit the 72 // Loop over all supported versions and make sure that we never hit the
76 // default case (i.e. all supported versions should be successfully converted 73 // default case (i.e. all supported versions should be successfully converted
77 // to valid QuicTags). 74 // to valid QuicTags).
78 for (size_t i = 0; i < arraysize(kSupportedQuicVersions); ++i) { 75 for (size_t i = 0; i < arraysize(kSupportedQuicVersions); ++i) {
79 QuicVersion version = kSupportedQuicVersions[i]; 76 QuicVersion version = kSupportedQuicVersions[i];
80 EXPECT_LT(0u, QuicVersionToQuicTag(version)); 77 EXPECT_LT(0u, QuicVersionToQuicTag(version));
81 } 78 }
82 } 79 }
83 80
(...skipping 17 matching lines...) Expand all
101 98
102 // TODO(rtenneti): Enable checking of Log(ERROR) messages. 99 // TODO(rtenneti): Enable checking of Log(ERROR) messages.
103 #if 0 100 #if 0
104 // Any logs would indicate an unsupported version which we don't expect. 101 // Any logs would indicate an unsupported version which we don't expect.
105 ScopedMockLog log(kDoNotCaptureLogsYet); 102 ScopedMockLog log(kDoNotCaptureLogsYet);
106 EXPECT_CALL(log, Log(_, _, _)).Times(0); 103 EXPECT_CALL(log, Log(_, _, _)).Times(0);
107 log.StartCapturingLogs(); 104 log.StartCapturingLogs();
108 #endif 105 #endif
109 106
110 // Explicitly test specific versions. 107 // Explicitly test specific versions.
111 EXPECT_EQ(QUIC_VERSION_16, 108 EXPECT_EQ(QUIC_VERSION_19,
112 QuicTagToQuicVersion(MakeQuicTag('Q', '0', '1', '6'))); 109 QuicTagToQuicVersion(MakeQuicTag('Q', '0', '1', '9')));
113 110
114 for (size_t i = 0; i < arraysize(kSupportedQuicVersions); ++i) { 111 for (size_t i = 0; i < arraysize(kSupportedQuicVersions); ++i) {
115 QuicVersion version = kSupportedQuicVersions[i]; 112 QuicVersion version = kSupportedQuicVersions[i];
116 113
117 // Get the tag from the version (we can loop over QuicVersions easily). 114 // Get the tag from the version (we can loop over QuicVersions easily).
118 QuicTag tag = QuicVersionToQuicTag(version); 115 QuicTag tag = QuicVersionToQuicTag(version);
119 EXPECT_LT(0u, tag); 116 EXPECT_LT(0u, tag);
120 117
121 // Now try converting back. 118 // Now try converting back.
122 QuicVersion tag_to_quic_version = QuicTagToQuicVersion(tag); 119 QuicVersion tag_to_quic_version = QuicTagToQuicVersion(tag);
(...skipping 10 matching lines...) Expand all
133 EXPECT_CALL(log, Log(INFO, _, "Unsupported QuicTag version: FAKE")).Times(1); 130 EXPECT_CALL(log, Log(INFO, _, "Unsupported QuicTag version: FAKE")).Times(1);
134 #endif 131 #endif
135 log.StartCapturingLogs(); 132 log.StartCapturingLogs();
136 #endif 133 #endif
137 134
138 EXPECT_EQ(QUIC_VERSION_UNSUPPORTED, 135 EXPECT_EQ(QUIC_VERSION_UNSUPPORTED,
139 QuicTagToQuicVersion(MakeQuicTag('F', 'A', 'K', 'E'))); 136 QuicTagToQuicVersion(MakeQuicTag('F', 'A', 'K', 'E')));
140 } 137 }
141 138
142 TEST(QuicProtocolTest, QuicVersionToString) { 139 TEST(QuicProtocolTest, QuicVersionToString) {
143 EXPECT_EQ("QUIC_VERSION_16", QuicVersionToString(QUIC_VERSION_16)); 140 EXPECT_EQ("QUIC_VERSION_19", QuicVersionToString(QUIC_VERSION_19));
144 EXPECT_EQ("QUIC_VERSION_UNSUPPORTED", 141 EXPECT_EQ("QUIC_VERSION_UNSUPPORTED",
145 QuicVersionToString(QUIC_VERSION_UNSUPPORTED)); 142 QuicVersionToString(QUIC_VERSION_UNSUPPORTED));
146 143
147 QuicVersion single_version[] = {QUIC_VERSION_16}; 144 QuicVersion single_version[] = {QUIC_VERSION_19};
148 QuicVersionVector versions_vector; 145 QuicVersionVector versions_vector;
149 for (size_t i = 0; i < arraysize(single_version); ++i) { 146 for (size_t i = 0; i < arraysize(single_version); ++i) {
150 versions_vector.push_back(single_version[i]); 147 versions_vector.push_back(single_version[i]);
151 } 148 }
152 EXPECT_EQ("QUIC_VERSION_16", QuicVersionVectorToString(versions_vector)); 149 EXPECT_EQ("QUIC_VERSION_19", QuicVersionVectorToString(versions_vector));
153 150
154 QuicVersion multiple_versions[] = {QUIC_VERSION_UNSUPPORTED, QUIC_VERSION_16}; 151 QuicVersion multiple_versions[] = {QUIC_VERSION_UNSUPPORTED, QUIC_VERSION_19};
155 versions_vector.clear(); 152 versions_vector.clear();
156 for (size_t i = 0; i < arraysize(multiple_versions); ++i) { 153 for (size_t i = 0; i < arraysize(multiple_versions); ++i) {
157 versions_vector.push_back(multiple_versions[i]); 154 versions_vector.push_back(multiple_versions[i]);
158 } 155 }
159 EXPECT_EQ("QUIC_VERSION_UNSUPPORTED,QUIC_VERSION_16", 156 EXPECT_EQ("QUIC_VERSION_UNSUPPORTED,QUIC_VERSION_19",
160 QuicVersionVectorToString(versions_vector)); 157 QuicVersionVectorToString(versions_vector));
161 158
162 // Make sure that all supported versions are present in QuicVersionToString. 159 // Make sure that all supported versions are present in QuicVersionToString.
163 for (size_t i = 0; i < arraysize(kSupportedQuicVersions); ++i) { 160 for (size_t i = 0; i < arraysize(kSupportedQuicVersions); ++i) {
164 QuicVersion version = kSupportedQuicVersions[i]; 161 QuicVersion version = kSupportedQuicVersions[i];
165 EXPECT_NE("QUIC_VERSION_UNSUPPORTED", QuicVersionToString(version)); 162 EXPECT_NE("QUIC_VERSION_UNSUPPORTED", QuicVersionToString(version));
166 } 163 }
167 } 164 }
168 165
169 } // namespace 166 } // namespace
170 } // namespace test 167 } // namespace test
171 } // namespace net 168 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_protocol.cc ('k') | net/quic/quic_sent_packet_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698