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

Side by Side Diff: net/quic/core/quic_versions_test.cc

Issue 2848203002: Add a platform implementation of QuicTest and QuicTestWithParam (Closed)
Patch Set: net/quic/platform/impl/quic_test_impl.cc Created 3 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
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/core/quic_versions.h" 5 #include "net/quic/core/quic_versions.h"
6 6
7 #include "net/quic/platform/api/quic_flags.h" 7 #include "net/quic/platform/api/quic_flags.h"
8 #include "net/quic/platform/api/quic_test.h"
8 #include "net/quic/test_tools/quic_test_utils.h" 9 #include "net/quic/test_tools/quic_test_utils.h"
9 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 10
12 namespace net { 11 namespace net {
13 namespace test { 12 namespace test {
14 namespace { 13 namespace {
15 14
16 TEST(QuicVersionsTest, QuicVersionToQuicTag) { 15 class QuicVersionsTest : public QuicTest {};
16
17 TEST_F(QuicVersionsTest, QuicVersionToQuicTag) {
17 // If you add a new version to the QuicVersion enum you will need to add a new 18 // If you add a new version to the QuicVersion enum you will need to add a new
18 // case to QuicVersionToQuicTag, otherwise this test will fail. 19 // case to QuicVersionToQuicTag, otherwise this test will fail.
19 20
20 // TODO(rtenneti): Enable checking of Log(ERROR) messages. 21 // TODO(rtenneti): Enable checking of Log(ERROR) messages.
21 #if 0 22 #if 0
22 // Any logs would indicate an unsupported version which we don't expect. 23 // Any logs would indicate an unsupported version which we don't expect.
23 ScopedMockLog log(kDoNotCaptureLogsYet); 24 ScopedMockLog log(kDoNotCaptureLogsYet);
24 EXPECT_CALL(log, Log(_, _, _)).Times(0); 25 EXPECT_CALL(log, Log(_, _, _)).Times(0);
25 log.StartCapturingLogs(); 26 log.StartCapturingLogs();
26 #endif 27 #endif
27 28
28 // Explicitly test a specific version. 29 // Explicitly test a specific version.
29 EXPECT_EQ(MakeQuicTag('Q', '0', '3', '5'), 30 EXPECT_EQ(MakeQuicTag('Q', '0', '3', '5'),
30 QuicVersionToQuicTag(QUIC_VERSION_35)); 31 QuicVersionToQuicTag(QUIC_VERSION_35));
31 32
32 // Loop over all supported versions and make sure that we never hit the 33 // Loop over all supported versions and make sure that we never hit the
33 // default case (i.e. all supported versions should be successfully converted 34 // default case (i.e. all supported versions should be successfully converted
34 // to valid QuicTags). 35 // to valid QuicTags).
35 for (size_t i = 0; i < arraysize(kSupportedQuicVersions); ++i) { 36 for (size_t i = 0; i < arraysize(kSupportedQuicVersions); ++i) {
36 QuicVersion version = kSupportedQuicVersions[i]; 37 QuicVersion version = kSupportedQuicVersions[i];
37 EXPECT_LT(0u, QuicVersionToQuicTag(version)); 38 EXPECT_LT(0u, QuicVersionToQuicTag(version));
38 } 39 }
39 } 40 }
40 41
41 TEST(QuicVersionsTest, QuicVersionToQuicTagUnsupported) { 42 TEST_F(QuicVersionsTest, QuicVersionToQuicTagUnsupported) {
42 // TODO(rtenneti): Enable checking of Log(ERROR) messages. 43 // TODO(rtenneti): Enable checking of Log(ERROR) messages.
43 #if 0 44 #if 0
44 // TODO(rjshade): Change to DFATAL once we actually support multiple versions, 45 // TODO(rjshade): Change to DFATAL once we actually support multiple versions,
45 // and QuicConnectionTest::SendVersionNegotiationPacket can be changed to use 46 // and QuicConnectionTest::SendVersionNegotiationPacket can be changed to use
46 // mis-matched versions rather than relying on QUIC_VERSION_UNSUPPORTED. 47 // mis-matched versions rather than relying on QUIC_VERSION_UNSUPPORTED.
47 ScopedMockLog log(kDoNotCaptureLogsYet); 48 ScopedMockLog log(kDoNotCaptureLogsYet);
48 EXPECT_CALL(log, Log(base_logging::ERROR, _, "Unsupported QuicVersion: 0")) 49 EXPECT_CALL(log, Log(base_logging::ERROR, _, "Unsupported QuicVersion: 0"))
49 .Times(1); 50 .Times(1);
50 log.StartCapturingLogs(); 51 log.StartCapturingLogs();
51 #endif 52 #endif
52 53
53 EXPECT_EQ(0u, QuicVersionToQuicTag(QUIC_VERSION_UNSUPPORTED)); 54 EXPECT_EQ(0u, QuicVersionToQuicTag(QUIC_VERSION_UNSUPPORTED));
54 } 55 }
55 56
56 TEST(QuicVersionsTest, QuicTagToQuicVersion) { 57 TEST_F(QuicVersionsTest, QuicTagToQuicVersion) {
57 // If you add a new version to the QuicVersion enum you will need to add a new 58 // If you add a new version to the QuicVersion enum you will need to add a new
58 // case to QuicTagToQuicVersion, otherwise this test will fail. 59 // case to QuicTagToQuicVersion, otherwise this test will fail.
59 60
60 // TODO(rtenneti): Enable checking of Log(ERROR) messages. 61 // TODO(rtenneti): Enable checking of Log(ERROR) messages.
61 #if 0 62 #if 0
62 // Any logs would indicate an unsupported version which we don't expect. 63 // Any logs would indicate an unsupported version which we don't expect.
63 ScopedMockLog log(kDoNotCaptureLogsYet); 64 ScopedMockLog log(kDoNotCaptureLogsYet);
64 EXPECT_CALL(log, Log(_, _, _)).Times(0); 65 EXPECT_CALL(log, Log(_, _, _)).Times(0);
65 log.StartCapturingLogs(); 66 log.StartCapturingLogs();
66 #endif 67 #endif
67 68
68 // Explicitly test specific versions. 69 // Explicitly test specific versions.
69 EXPECT_EQ(QUIC_VERSION_35, 70 EXPECT_EQ(QUIC_VERSION_35,
70 QuicTagToQuicVersion(MakeQuicTag('Q', '0', '3', '5'))); 71 QuicTagToQuicVersion(MakeQuicTag('Q', '0', '3', '5')));
71 72
72 for (size_t i = 0; i < arraysize(kSupportedQuicVersions); ++i) { 73 for (size_t i = 0; i < arraysize(kSupportedQuicVersions); ++i) {
73 QuicVersion version = kSupportedQuicVersions[i]; 74 QuicVersion version = kSupportedQuicVersions[i];
74 75
75 // Get the tag from the version (we can loop over QuicVersions easily). 76 // Get the tag from the version (we can loop over QuicVersions easily).
76 QuicTag tag = QuicVersionToQuicTag(version); 77 QuicTag tag = QuicVersionToQuicTag(version);
77 EXPECT_LT(0u, tag); 78 EXPECT_LT(0u, tag);
78 79
79 // Now try converting back. 80 // Now try converting back.
80 QuicVersion tag_to_quic_version = QuicTagToQuicVersion(tag); 81 QuicVersion tag_to_quic_version = QuicTagToQuicVersion(tag);
81 EXPECT_EQ(version, tag_to_quic_version); 82 EXPECT_EQ(version, tag_to_quic_version);
82 EXPECT_NE(QUIC_VERSION_UNSUPPORTED, tag_to_quic_version); 83 EXPECT_NE(QUIC_VERSION_UNSUPPORTED, tag_to_quic_version);
83 } 84 }
84 } 85 }
85 86
86 TEST(QuicVersionsTest, QuicTagToQuicVersionUnsupported) { 87 TEST_F(QuicVersionsTest, QuicTagToQuicVersionUnsupported) {
87 // TODO(rtenneti): Enable checking of Log(ERROR) messages. 88 // TODO(rtenneti): Enable checking of Log(ERROR) messages.
88 #if 0 89 #if 0
89 ScopedMockLog log(kDoNotCaptureLogsYet); 90 ScopedMockLog log(kDoNotCaptureLogsYet);
90 #ifndef NDEBUG 91 #ifndef NDEBUG
91 EXPECT_CALL(log, 92 EXPECT_CALL(log,
92 Log(base_logging::INFO, _, "Unsupported QuicTag version: FAKE")) 93 Log(base_logging::INFO, _, "Unsupported QuicTag version: FAKE"))
93 .Times(1); 94 .Times(1);
94 #endif 95 #endif
95 log.StartCapturingLogs(); 96 log.StartCapturingLogs();
96 #endif 97 #endif
97 98
98 EXPECT_EQ(QUIC_VERSION_UNSUPPORTED, 99 EXPECT_EQ(QUIC_VERSION_UNSUPPORTED,
99 QuicTagToQuicVersion(MakeQuicTag('F', 'A', 'K', 'E'))); 100 QuicTagToQuicVersion(MakeQuicTag('F', 'A', 'K', 'E')));
100 } 101 }
101 102
102 TEST(QuicVersionsTest, QuicVersionToString) { 103 TEST_F(QuicVersionsTest, QuicVersionToString) {
103 EXPECT_EQ("QUIC_VERSION_35", QuicVersionToString(QUIC_VERSION_35)); 104 EXPECT_EQ("QUIC_VERSION_35", QuicVersionToString(QUIC_VERSION_35));
104 EXPECT_EQ("QUIC_VERSION_UNSUPPORTED", 105 EXPECT_EQ("QUIC_VERSION_UNSUPPORTED",
105 QuicVersionToString(QUIC_VERSION_UNSUPPORTED)); 106 QuicVersionToString(QUIC_VERSION_UNSUPPORTED));
106 107
107 QuicVersion single_version[] = {QUIC_VERSION_35}; 108 QuicVersion single_version[] = {QUIC_VERSION_35};
108 QuicVersionVector versions_vector; 109 QuicVersionVector versions_vector;
109 for (size_t i = 0; i < arraysize(single_version); ++i) { 110 for (size_t i = 0; i < arraysize(single_version); ++i) {
110 versions_vector.push_back(single_version[i]); 111 versions_vector.push_back(single_version[i]);
111 } 112 }
112 EXPECT_EQ("QUIC_VERSION_35", QuicVersionVectorToString(versions_vector)); 113 EXPECT_EQ("QUIC_VERSION_35", QuicVersionVectorToString(versions_vector));
113 114
114 QuicVersion multiple_versions[] = {QUIC_VERSION_UNSUPPORTED, QUIC_VERSION_35}; 115 QuicVersion multiple_versions[] = {QUIC_VERSION_UNSUPPORTED, QUIC_VERSION_35};
115 versions_vector.clear(); 116 versions_vector.clear();
116 for (size_t i = 0; i < arraysize(multiple_versions); ++i) { 117 for (size_t i = 0; i < arraysize(multiple_versions); ++i) {
117 versions_vector.push_back(multiple_versions[i]); 118 versions_vector.push_back(multiple_versions[i]);
118 } 119 }
119 EXPECT_EQ("QUIC_VERSION_UNSUPPORTED,QUIC_VERSION_35", 120 EXPECT_EQ("QUIC_VERSION_UNSUPPORTED,QUIC_VERSION_35",
120 QuicVersionVectorToString(versions_vector)); 121 QuicVersionVectorToString(versions_vector));
121 122
122 // Make sure that all supported versions are present in QuicVersionToString. 123 // Make sure that all supported versions are present in QuicVersionToString.
123 for (size_t i = 0; i < arraysize(kSupportedQuicVersions); ++i) { 124 for (size_t i = 0; i < arraysize(kSupportedQuicVersions); ++i) {
124 QuicVersion version = kSupportedQuicVersions[i]; 125 QuicVersion version = kSupportedQuicVersions[i];
125 EXPECT_NE("QUIC_VERSION_UNSUPPORTED", QuicVersionToString(version)); 126 EXPECT_NE("QUIC_VERSION_UNSUPPORTED", QuicVersionToString(version));
126 } 127 }
127 } 128 }
128 129
129 TEST(QuicVersionsTest, FilterSupportedVersionsNo38) { 130 TEST_F(QuicVersionsTest, FilterSupportedVersionsNo38) {
130 QuicFlagSaver flags;
131 QuicVersionVector all_versions = {QUIC_VERSION_35, QUIC_VERSION_36, 131 QuicVersionVector all_versions = {QUIC_VERSION_35, QUIC_VERSION_36,
132 QUIC_VERSION_37, QUIC_VERSION_38, 132 QUIC_VERSION_37, QUIC_VERSION_38,
133 QUIC_VERSION_39}; 133 QUIC_VERSION_39};
134 134
135 FLAGS_quic_reloadable_flag_quic_enable_version_38 = false; 135 FLAGS_quic_reloadable_flag_quic_enable_version_38 = false;
136 136
137 QuicVersionVector filtered_versions = FilterSupportedVersions(all_versions); 137 QuicVersionVector filtered_versions = FilterSupportedVersions(all_versions);
138 ASSERT_EQ(3u, filtered_versions.size()); 138 ASSERT_EQ(3u, filtered_versions.size());
139 EXPECT_EQ(QUIC_VERSION_35, filtered_versions[0]); 139 EXPECT_EQ(QUIC_VERSION_35, filtered_versions[0]);
140 EXPECT_EQ(QUIC_VERSION_36, filtered_versions[1]); 140 EXPECT_EQ(QUIC_VERSION_36, filtered_versions[1]);
141 EXPECT_EQ(QUIC_VERSION_37, filtered_versions[2]); 141 EXPECT_EQ(QUIC_VERSION_37, filtered_versions[2]);
142 } 142 }
143 143
144 TEST(QuicVersionsTest, FilterSupportedVersionsNo39) { 144 TEST_F(QuicVersionsTest, FilterSupportedVersionsNo39) {
145 QuicVersionVector all_versions = {QUIC_VERSION_35, QUIC_VERSION_36, 145 QuicVersionVector all_versions = {QUIC_VERSION_35, QUIC_VERSION_36,
146 QUIC_VERSION_37, QUIC_VERSION_38, 146 QUIC_VERSION_37, QUIC_VERSION_38,
147 QUIC_VERSION_39}; 147 QUIC_VERSION_39};
148 148
149 FLAGS_quic_reloadable_flag_quic_enable_version_38 = true; 149 FLAGS_quic_reloadable_flag_quic_enable_version_38 = true;
150 FLAGS_quic_reloadable_flag_quic_enable_version_39 = false; 150 FLAGS_quic_reloadable_flag_quic_enable_version_39 = false;
151 151
152 QuicVersionVector filtered_versions = FilterSupportedVersions(all_versions); 152 QuicVersionVector filtered_versions = FilterSupportedVersions(all_versions);
153 ASSERT_EQ(4u, filtered_versions.size()); 153 ASSERT_EQ(4u, filtered_versions.size());
154 EXPECT_EQ(QUIC_VERSION_35, filtered_versions[0]); 154 EXPECT_EQ(QUIC_VERSION_35, filtered_versions[0]);
155 EXPECT_EQ(QUIC_VERSION_36, filtered_versions[1]); 155 EXPECT_EQ(QUIC_VERSION_36, filtered_versions[1]);
156 EXPECT_EQ(QUIC_VERSION_37, filtered_versions[2]); 156 EXPECT_EQ(QUIC_VERSION_37, filtered_versions[2]);
157 EXPECT_EQ(QUIC_VERSION_38, filtered_versions[3]); 157 EXPECT_EQ(QUIC_VERSION_38, filtered_versions[3]);
158 } 158 }
159 159
160 TEST(QuicVersionsTest, FilterSupportedVersionsAllVersions) { 160 TEST_F(QuicVersionsTest, FilterSupportedVersionsAllVersions) {
161 QuicFlagSaver flags;
162 QuicVersionVector all_versions = {QUIC_VERSION_35, QUIC_VERSION_36, 161 QuicVersionVector all_versions = {QUIC_VERSION_35, QUIC_VERSION_36,
163 QUIC_VERSION_37, QUIC_VERSION_38, 162 QUIC_VERSION_37, QUIC_VERSION_38,
164 QUIC_VERSION_39}; 163 QUIC_VERSION_39};
165 164
166 FLAGS_quic_reloadable_flag_quic_enable_version_38 = true; 165 FLAGS_quic_reloadable_flag_quic_enable_version_38 = true;
167 FLAGS_quic_reloadable_flag_quic_enable_version_39 = true; 166 FLAGS_quic_reloadable_flag_quic_enable_version_39 = true;
168 167
169 QuicVersionVector filtered_versions = FilterSupportedVersions(all_versions); 168 QuicVersionVector filtered_versions = FilterSupportedVersions(all_versions);
170 ASSERT_EQ(all_versions, filtered_versions); 169 ASSERT_EQ(all_versions, filtered_versions);
171 } 170 }
172 171
173 TEST(QuicVersionsTest, LookUpVersionByIndex) { 172 TEST_F(QuicVersionsTest, LookUpVersionByIndex) {
174 QuicVersionVector all_versions = {QUIC_VERSION_35, QUIC_VERSION_36, 173 QuicVersionVector all_versions = {QUIC_VERSION_35, QUIC_VERSION_36,
175 QUIC_VERSION_37, QUIC_VERSION_38, 174 QUIC_VERSION_37, QUIC_VERSION_38,
176 QUIC_VERSION_39}; 175 QUIC_VERSION_39};
177 int version_count = all_versions.size(); 176 int version_count = all_versions.size();
178 for (int i = -5; i <= version_count + 1; ++i) { 177 for (int i = -5; i <= version_count + 1; ++i) {
179 if (i >= 0 && i < version_count) { 178 if (i >= 0 && i < version_count) {
180 EXPECT_EQ(all_versions[i], VersionOfIndex(all_versions, i)[0]); 179 EXPECT_EQ(all_versions[i], VersionOfIndex(all_versions, i)[0]);
181 } else { 180 } else {
182 EXPECT_EQ(QUIC_VERSION_UNSUPPORTED, VersionOfIndex(all_versions, i)[0]); 181 EXPECT_EQ(QUIC_VERSION_UNSUPPORTED, VersionOfIndex(all_versions, i)[0]);
183 } 182 }
184 } 183 }
185 } 184 }
186 185
187 } // namespace 186 } // namespace
188 } // namespace test 187 } // namespace test
189 } // namespace net 188 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/core/quic_version_manager_test.cc ('k') | net/quic/core/quic_write_blocked_list_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698