This source file includes following definitions.
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
#include "net/quic/quic_protocol.h"
#include "base/stl_util.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace net {
namespace test {
namespace {
TEST(QuicProtocolTest, MakeQuicTag) {
QuicTag tag = MakeQuicTag('A', 'B', 'C', 'D');
char bytes[4];
memcpy(bytes, &tag, 4);
EXPECT_EQ('A', bytes[0]);
EXPECT_EQ('B', bytes[1]);
EXPECT_EQ('C', bytes[2]);
EXPECT_EQ('D', bytes[3]);
}
TEST(QuicProtocolTest, IsAawaitingPacket) {
ReceivedPacketInfo received_info;
received_info.largest_observed = 10u;
EXPECT_TRUE(IsAwaitingPacket(received_info, 11u));
EXPECT_FALSE(IsAwaitingPacket(received_info, 1u));
received_info.missing_packets.insert(10);
EXPECT_TRUE(IsAwaitingPacket(received_info, 10u));
}
TEST(QuicProtocolTest, InsertMissingPacketsBetween) {
ReceivedPacketInfo received_info;
InsertMissingPacketsBetween(&received_info, 4u, 10u);
EXPECT_EQ(6u, received_info.missing_packets.size());
QuicPacketSequenceNumber i = 4;
for (SequenceNumberSet::iterator it = received_info.missing_packets.begin();
it != received_info.missing_packets.end(); ++it, ++i) {
EXPECT_EQ(i, *it);
}
}
TEST(QuicProtocolTest, QuicVersionToQuicTag) {
#if 0
ScopedMockLog log(kDoNotCaptureLogsYet);
EXPECT_CALL(log, Log(_, _, _)).Times(0);
log.StartCapturingLogs();
#endif
EXPECT_EQ(MakeQuicTag('Q', '0', '1', '6'),
QuicVersionToQuicTag(QUIC_VERSION_16));
for (size_t i = 0; i < arraysize(kSupportedQuicVersions); ++i) {
QuicVersion version = kSupportedQuicVersions[i];
EXPECT_LT(0u, QuicVersionToQuicTag(version));
}
}
TEST(QuicProtocolTest, QuicVersionToQuicTagUnsupported) {
#if 0
ScopedMockLog log(kDoNotCaptureLogsYet);
EXPECT_CALL(log, Log(ERROR, _, "Unsupported QuicVersion: 0")).Times(1);
log.StartCapturingLogs();
#endif
EXPECT_EQ(0u, QuicVersionToQuicTag(QUIC_VERSION_UNSUPPORTED));
}
TEST(QuicProtocolTest, QuicTagToQuicVersion) {
#if 0
ScopedMockLog log(kDoNotCaptureLogsYet);
EXPECT_CALL(log, Log(_, _, _)).Times(0);
log.StartCapturingLogs();
#endif
EXPECT_EQ(QUIC_VERSION_16,
QuicTagToQuicVersion(MakeQuicTag('Q', '0', '1', '6')));
for (size_t i = 0; i < arraysize(kSupportedQuicVersions); ++i) {
QuicVersion version = kSupportedQuicVersions[i];
QuicTag tag = QuicVersionToQuicTag(version);
EXPECT_LT(0u, tag);
QuicVersion tag_to_quic_version = QuicTagToQuicVersion(tag);
EXPECT_EQ(version, tag_to_quic_version);
EXPECT_NE(QUIC_VERSION_UNSUPPORTED, tag_to_quic_version);
}
}
TEST(QuicProtocolTest, QuicTagToQuicVersionUnsupported) {
#if 0
ScopedMockLog log(kDoNotCaptureLogsYet);
#ifndef NDEBUG
EXPECT_CALL(log, Log(INFO, _, "Unsupported QuicTag version: FAKE")).Times(1);
#endif
log.StartCapturingLogs();
#endif
EXPECT_EQ(QUIC_VERSION_UNSUPPORTED,
QuicTagToQuicVersion(MakeQuicTag('F', 'A', 'K', 'E')));
}
TEST(QuicProtocolTest, QuicVersionToString) {
EXPECT_EQ("QUIC_VERSION_16", QuicVersionToString(QUIC_VERSION_16));
EXPECT_EQ("QUIC_VERSION_UNSUPPORTED",
QuicVersionToString(QUIC_VERSION_UNSUPPORTED));
QuicVersion single_version[] = {QUIC_VERSION_16};
QuicVersionVector versions_vector;
for (size_t i = 0; i < arraysize(single_version); ++i) {
versions_vector.push_back(single_version[i]);
}
EXPECT_EQ("QUIC_VERSION_16", QuicVersionVectorToString(versions_vector));
QuicVersion multiple_versions[] = {QUIC_VERSION_UNSUPPORTED, QUIC_VERSION_16};
versions_vector.clear();
for (size_t i = 0; i < arraysize(multiple_versions); ++i) {
versions_vector.push_back(multiple_versions[i]);
}
EXPECT_EQ("QUIC_VERSION_UNSUPPORTED,QUIC_VERSION_16",
QuicVersionVectorToString(versions_vector));
for (size_t i = 0; i < arraysize(kSupportedQuicVersions); ++i) {
QuicVersion version = kSupportedQuicVersions[i];
EXPECT_NE("QUIC_VERSION_UNSUPPORTED", QuicVersionToString(version));
}
}
}
}
}