Chromium Code Reviews| 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_UNSAFE(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 | |
|
ramant (doing other things)
2013/07/23 03:01:30
Hi rch,
chromium doesn't have ScopedMockLog. Sho
Ryan Hamilton
2013/07/23 03:40:18
Sounds like a good TODO.
| |
| 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_UNSAFE(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_NE(0u, tag); | |
|
ramant (doing other things)
2013/07/23 03:01:30
We return 0 when we do LOG(ERROR).
Ryan Hamilton
2013/07/23 03:40:18
Not sure I understand what you mean? Is this code
ramant (doing other things)
2013/07/23 05:05:22
I have add line#87. Everything else is same as goo
| |
| 88 | |
| 89 // Now try converting back. | |
| 90 EXPECT_EQ(version, QuicTagToQuicVersion(tag)); | |
|
ramant (doing other things)
2013/07/23 03:01:30
kSupportedQuicVersions shouldn't have QUIC_VERSION
Ryan Hamilton
2013/07/23 03:40:18
Sounds good...
ramant (doing other things)
2013/07/23 05:05:22
Done.
| |
| 91 } | |
| 92 } | |
| 93 | |
| 94 TEST(QuicProtocolTest, QuicVersionToString) { | |
| 95 EXPECT_EQ("QUIC_VERSION_6", | |
| 96 QuicVersionToString(QUIC_VERSION_6)); | |
| 97 EXPECT_EQ("QUIC_VERSION_UNSUPPORTED", | |
| 98 QuicVersionToString(QUIC_VERSION_UNSUPPORTED)); | |
| 99 | |
| 100 QuicVersion single_version[] = {QUIC_VERSION_6}; | |
| 101 EXPECT_EQ("QUIC_VERSION_6,", QuicVersionArrayToString(single_version, | |
| 102 ARRAYSIZE_UNSAFE(single_version))); | |
| 103 // QuicVersion multiple_versions[] = {QUIC_VERSION_7, QUIC_VERSION_6}; | |
| 104 // EXPECT_EQ("QUIC_VERSION_7,QUIC_VERSION_6,", | |
| 105 // QuicVersionArrayToString(multiple_versions, | |
| 106 // ARRAYSIZE_UNSAFE(multiple_versions))); | |
| 107 } | |
| 108 | |
| 46 } // namespace | 109 } // namespace |
| 47 } // namespace test | 110 } // namespace test |
| 48 } // namespace net | 111 } // namespace net |
| OLD | NEW |