OLD | NEW |
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 { |
(...skipping 25 matching lines...) Expand all Loading... |
36 InsertMissingPacketsBetween(&received_info, 4u, 10u); | 36 InsertMissingPacketsBetween(&received_info, 4u, 10u); |
37 EXPECT_EQ(6u, received_info.missing_packets.size()); | 37 EXPECT_EQ(6u, received_info.missing_packets.size()); |
38 | 38 |
39 QuicPacketSequenceNumber i = 4; | 39 QuicPacketSequenceNumber i = 4; |
40 for (SequenceNumberSet::iterator it = received_info.missing_packets.begin(); | 40 for (SequenceNumberSet::iterator it = received_info.missing_packets.begin(); |
41 it != received_info.missing_packets.end(); ++it, ++i) { | 41 it != received_info.missing_packets.end(); ++it, ++i) { |
42 EXPECT_EQ(i, *it); | 42 EXPECT_EQ(i, *it); |
43 } | 43 } |
44 } | 44 } |
45 | 45 |
| 46 TEST(QuicProtocolTest, QuicVersionToQuicTag) { |
| 47 // If you add a new version to the QuicVersion enum you will need to add a new |
| 48 // case to QuicVersionToQuicTag, otherwise this test will fail. |
| 49 |
| 50 // Explicitly test a specific version. |
| 51 EXPECT_EQ(MakeQuicTag('Q', '0', '0', '6'), |
| 52 QuicVersionToQuicTag(QUIC_VERSION_6)); |
| 53 |
| 54 // Loop over all supported versions and make sure that we never hit the |
| 55 // default case (i.e. all supported versions should be successfully converted |
| 56 // to valid QuicTags). |
| 57 for (size_t i = 0; i < arraysize(kSupportedQuicVersions); ++i) { |
| 58 const QuicVersion& version = kSupportedQuicVersions[i]; |
| 59 EXPECT_LT(0u, QuicVersionToQuicTag(version)); |
| 60 } |
| 61 } |
| 62 |
| 63 TEST(QuicProtocolTest, QuicTagToQuicVersion) { |
| 64 // If you add a new version to the QuicVersion enum you will need to add a new |
| 65 // case to QuicTagToQuicVersion, otherwise this test will fail. |
| 66 |
| 67 // Explicitly test specific versions. |
| 68 EXPECT_EQ(QUIC_VERSION_6, |
| 69 QuicTagToQuicVersion(MakeQuicTag('Q', '0', '0', '6'))); |
| 70 EXPECT_EQ(QUIC_VERSION_UNSUPPORTED, |
| 71 QuicTagToQuicVersion(MakeQuicTag('F', 'A', 'K', 'E'))); |
| 72 |
| 73 // TODO(rtenneti): Enable checking of Log(ERROR) messages. |
| 74 #if 0 |
| 75 // Loop over all supported versions, and make sure we never hit the default |
| 76 // case (which would result in a LOG(ERROR)). |
| 77 ScopedMockLog log(kDoNotCaptureLogsYet); |
| 78 EXPECT_CALL(log, Log(ERROR, _, _)).Times(0); |
| 79 log.StartCapturingLogs(); |
| 80 #endif |
| 81 |
| 82 for (size_t i = 0; i < arraysize(kSupportedQuicVersions); ++i) { |
| 83 const QuicVersion& version = kSupportedQuicVersions[i]; |
| 84 |
| 85 // Get the tag from the version (we can loop over QuicVersions easily). |
| 86 QuicTag tag = QuicVersionToQuicTag(version); |
| 87 EXPECT_LT(0u, tag); |
| 88 |
| 89 // Now try converting back. |
| 90 QuicVersion tag_to_quic_version = QuicTagToQuicVersion(tag); |
| 91 EXPECT_EQ(version, tag_to_quic_version); |
| 92 EXPECT_NE(QUIC_VERSION_UNSUPPORTED, tag_to_quic_version); |
| 93 } |
| 94 } |
| 95 |
| 96 TEST(QuicProtocolTest, QuicVersionToString) { |
| 97 EXPECT_EQ("QUIC_VERSION_6", |
| 98 QuicVersionToString(QUIC_VERSION_6)); |
| 99 EXPECT_EQ("QUIC_VERSION_UNSUPPORTED", |
| 100 QuicVersionToString(QUIC_VERSION_UNSUPPORTED)); |
| 101 |
| 102 QuicVersion single_version[] = {QUIC_VERSION_6}; |
| 103 EXPECT_EQ("QUIC_VERSION_6,", QuicVersionArrayToString(single_version, |
| 104 arraysize(single_version))); |
| 105 // QuicVersion multiple_versions[] = {QUIC_VERSION_7, QUIC_VERSION_6}; |
| 106 // EXPECT_EQ("QUIC_VERSION_7,QUIC_VERSION_6,", |
| 107 // QuicVersionArrayToString(multiple_versions, |
| 108 // arraysize(multiple_versions))); |
| 109 } |
| 110 |
46 } // namespace | 111 } // namespace |
47 } // namespace test | 112 } // namespace test |
48 } // namespace net | 113 } // namespace net |
OLD | NEW |