#ifndef QUICHE_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_
#define QUICHE_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_
#include <cstdint>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "absl/container/flat_hash_map.h"
#include "absl/strings/ascii.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
#include "quiche/quic/core/congestion_control/loss_detection_interface.h"
#include "quiche/quic/core/congestion_control/send_algorithm_interface.h"
#include "quiche/quic/core/crypto/transport_parameters.h"
#include "quiche/quic/core/frames/quic_reset_stream_at_frame.h"
#include "quiche/quic/core/http/http_decoder.h"
#include "quiche/quic/core/http/quic_server_session_base.h"
#include "quiche/quic/core/http/quic_spdy_client_session_base.h"
#include "quiche/quic/core/http/quic_spdy_session.h"
#include "quiche/quic/core/quic_connection.h"
#include "quiche/quic/core/quic_connection_id.h"
#include "quiche/quic/core/quic_error_codes.h"
#include "quiche/quic/core/quic_framer.h"
#include "quiche/quic/core/quic_packet_writer.h"
#include "quiche/quic/core/quic_packet_writer_wrapper.h"
#include "quiche/quic/core/quic_packets.h"
#include "quiche/quic/core/quic_path_validator.h"
#include "quiche/quic/core/quic_sent_packet_manager.h"
#include "quiche/quic/core/quic_server_id.h"
#include "quiche/quic/core/quic_time.h"
#include "quiche/quic/core/quic_types.h"
#include "quiche/quic/core/quic_utils.h"
#include "quiche/quic/platform/api/quic_socket_address.h"
#include "quiche/quic/test_tools/mock_clock.h"
#include "quiche/quic/test_tools/mock_connection_id_generator.h"
#include "quiche/quic/test_tools/mock_quic_session_visitor.h"
#include "quiche/quic/test_tools/mock_random.h"
#include "quiche/quic/test_tools/quic_framer_peer.h"
#include "quiche/quic/test_tools/simple_quic_framer.h"
#include "quiche/common/capsule.h"
#include "quiche/common/http/http_header_block.h"
#include "quiche/common/simple_buffer_allocator.h"
namespace quic {
namespace test {
QuicConnectionId TestConnectionId();
QuicConnectionId TestConnectionId(uint64_t connection_number);
QuicConnectionId TestConnectionIdNineBytesLong(uint64_t connection_number);
uint64_t TestConnectionIdToUInt64(QuicConnectionId connection_id);
enum : uint16_t { … };
enum : uint32_t { … };
enum : uint64_t { … };
std::vector<uint8_t> CreateStatelessResetTokenForTest();
std::string TestHostname();
QuicServerId TestServerId();
QuicIpAddress TestPeerIPAddress();
ParsedQuicVersion QuicVersionMax();
ParsedQuicVersion QuicVersionMin();
void DisableQuicVersionsWithTls();
QuicEncryptedPacket* ConstructEncryptedPacket(
QuicConnectionId destination_connection_id,
QuicConnectionId source_connection_id, bool version_flag, bool reset_flag,
uint64_t packet_number, const std::string& data, bool full_padding,
QuicConnectionIdIncluded destination_connection_id_included,
QuicConnectionIdIncluded source_connection_id_included,
QuicPacketNumberLength packet_number_length,
ParsedQuicVersionVector* versions, Perspective perspective);
QuicEncryptedPacket* ConstructEncryptedPacket(
QuicConnectionId destination_connection_id,
QuicConnectionId source_connection_id, bool version_flag, bool reset_flag,
uint64_t packet_number, const std::string& data, bool full_padding,
QuicConnectionIdIncluded destination_connection_id_included,
QuicConnectionIdIncluded source_connection_id_included,
QuicPacketNumberLength packet_number_length,
ParsedQuicVersionVector* versions);
QuicEncryptedPacket* ConstructEncryptedPacket(
QuicConnectionId destination_connection_id,
QuicConnectionId source_connection_id, bool version_flag, bool reset_flag,
uint64_t packet_number, const std::string& data,
QuicConnectionIdIncluded destination_connection_id_included,
QuicConnectionIdIncluded source_connection_id_included,
QuicPacketNumberLength packet_number_length,
ParsedQuicVersionVector* versions);
QuicEncryptedPacket* ConstructEncryptedPacket(
QuicConnectionId destination_connection_id,
QuicConnectionId source_connection_id, bool version_flag, bool reset_flag,
uint64_t packet_number, const std::string& data,
QuicConnectionIdIncluded destination_connection_id_included,
QuicConnectionIdIncluded source_connection_id_included,
QuicPacketNumberLength packet_number_length);
QuicEncryptedPacket* ConstructEncryptedPacket(
QuicConnectionId destination_connection_id,
QuicConnectionId source_connection_id, bool version_flag, bool reset_flag,
uint64_t packet_number, const std::string& data);
std::unique_ptr<QuicEncryptedPacket> GetUndecryptableEarlyPacket(
const ParsedQuicVersion& version,
const QuicConnectionId& server_connection_id);
QuicReceivedPacket* ConstructReceivedPacket(
const QuicEncryptedPacket& encrypted_packet, QuicTime receipt_time);
QuicReceivedPacket* ConstructReceivedPacket(
const QuicEncryptedPacket& encrypted_packet, QuicTime receipt_time,
QuicEcnCodepoint ecn);
QuicEncryptedPacket* ConstructMisFramedEncryptedPacket(
QuicConnectionId destination_connection_id,
QuicConnectionId source_connection_id, bool version_flag, bool reset_flag,
uint64_t packet_number, const std::string& data,
QuicConnectionIdIncluded destination_connection_id_included,
QuicConnectionIdIncluded source_connection_id_included,
QuicPacketNumberLength packet_number_length, ParsedQuicVersion version,
Perspective perspective);
QuicConfig DefaultQuicConfig();
ParsedQuicVersionVector SupportedVersions(ParsedQuicVersion version);
struct QuicAckBlock { … };
QuicAckFrame InitAckFrame(const std::vector<QuicAckBlock>& ack_blocks);
QuicAckFrame InitAckFrame(uint64_t largest_acked);
QuicAckFrame InitAckFrame(QuicPacketNumber largest_acked);
QuicAckFrame MakeAckFrameWithAckBlocks(size_t num_ack_blocks,
uint64_t least_unacked);
QuicAckFrame MakeAckFrameWithGaps(uint64_t gap_size, size_t max_num_gaps,
uint64_t largest_acked);
EncryptionLevel HeaderToEncryptionLevel(const QuicPacketHeader& header);
std::unique_ptr<QuicPacket> BuildUnsizedDataPacket(
QuicFramer* framer, const QuicPacketHeader& header,
const QuicFrames& frames);
std::unique_ptr<QuicPacket> BuildUnsizedDataPacket(
QuicFramer* framer, const QuicPacketHeader& header,
const QuicFrames& frames, size_t packet_size);
std::string Sha1Hash(absl::string_view data);
bool ClearControlFrame(const QuicFrame& frame);
bool ClearControlFrameWithTransmissionType(const QuicFrame& frame,
TransmissionType type);
class SimpleRandom : public QuicRandom { … };
class MockFramerVisitor : public QuicFramerVisitorInterface { … };
class NoOpFramerVisitor : public QuicFramerVisitorInterface { … };
class MockQuicConnectionVisitor : public QuicConnectionVisitorInterface { … };
class MockQuicConnectionHelper : public QuicConnectionHelperInterface { … };
class MockAlarmFactory : public QuicAlarmFactory { … };
class TestAlarmFactory : public QuicAlarmFactory { … };
class MockQuicConnection : public QuicConnection { … };
class PacketProvider { … };
class PacketSavingConnection : public MockQuicConnection,
public PacketProvider { … };
class MockQuicSession : public QuicSession { … };
class MockQuicCryptoStream : public QuicCryptoStream { … };
class MockQuicSpdySession : public QuicSpdySession { … };
class MockHttp3DebugVisitor : public Http3DebugVisitor { … };
class TestQuicSpdyServerSession : public QuicServerSessionBase { … };
class TestQuicSpdyClientSession : public QuicSpdyClientSessionBase { … };
class MockPacketWriter : public QuicPacketWriter { … };
class MockSendAlgorithm : public SendAlgorithmInterface { … };
class MockLossAlgorithm : public LossDetectionInterface { … };
class MockAckListener : public QuicAckListenerInterface { … };
class MockNetworkChangeVisitor
: public QuicSentPacketManager::NetworkChangeVisitor { … };
class MockQuicConnectionDebugVisitor : public QuicConnectionDebugVisitor { … };
class MockReceivedPacketManager : public QuicReceivedPacketManager { … };
class MockPacketCreatorDelegate : public QuicPacketCreator::DelegateInterface { … };
class MockSessionNotifier : public SessionNotifierInterface { … };
class MockQuicPathValidationContext : public QuicPathValidationContext { … };
class MockQuicPathValidationResultDelegate
: public QuicPathValidator::ResultDelegate { … };
class MockHttpDecoderVisitor : public HttpDecoder::Visitor { … };
class QuicCryptoClientStreamPeer { … };
void CreateClientSessionForTest(
QuicServerId server_id, QuicTime::Delta connection_start_time,
const ParsedQuicVersionVector& supported_versions,
MockQuicConnectionHelper* helper, QuicAlarmFactory* alarm_factory,
QuicCryptoClientConfig* crypto_client_config,
PacketSavingConnection** client_connection,
TestQuicSpdyClientSession** client_session);
void CreateServerSessionForTest(
QuicServerId server_id, QuicTime::Delta connection_start_time,
ParsedQuicVersionVector supported_versions,
MockQuicConnectionHelper* helper, QuicAlarmFactory* alarm_factory,
QuicCryptoServerConfig* server_crypto_config,
QuicCompressedCertsCache* compressed_certs_cache,
PacketSavingConnection** server_connection,
TestQuicSpdyServerSession** server_session);
template <typename T>
void ExpectApproxEq(T expected, T actual, float relative_margin) { … }
#define EXPECT_APPROX_EQ(expected, actual, relative_margin) …
template <typename T>
QuicHeaderList AsHeaderList(const T& container) { … }
QuicStreamId GetNthClientInitiatedBidirectionalStreamId(
QuicTransportVersion version, int n);
QuicStreamId GetNthServerInitiatedBidirectionalStreamId(
QuicTransportVersion version, int n);
QuicStreamId GetNthServerInitiatedUnidirectionalStreamId(
QuicTransportVersion version, int n);
QuicStreamId GetNthClientInitiatedUnidirectionalStreamId(
QuicTransportVersion version, int n);
StreamType DetermineStreamType(QuicStreamId id, ParsedQuicVersion version,
Perspective perspective, bool is_incoming,
StreamType default_type);
quiche::QuicheMemSlice MemSliceFromString(absl::string_view data);
MATCHER_P(ReceivedPacketInfoEquals, info, "") { … }
MATCHER_P(ReceivedPacketInfoConnectionIdEquals, destination_connection_id, "") { … }
MATCHER_P2(InRange, min, max, "") { … }
MATCHER_P(IsError, expected,
absl::StrCat(negation ? "isn't equal to " : "is equal to ",
QuicErrorCodeToString(expected))) { … }
MATCHER(IsQuicNoError,
absl::StrCat(negation ? "isn't equal to " : "is equal to ",
QuicErrorCodeToString(QUIC_NO_ERROR))) { … }
MATCHER_P(IsStreamError, expected,
absl::StrCat(negation ? "isn't equal to " : "is equal to ",
QuicRstStreamErrorCodeToString(expected))) { … }
MATCHER(IsQuicStreamNoError,
absl::StrCat(negation ? "isn't equal to " : "is equal to ",
QuicRstStreamErrorCodeToString(QUIC_STREAM_NO_ERROR))) { … }
class TaggingEncrypter : public QuicEncrypter { … };
class TaggingDecrypter : public QuicDecrypter { … };
class StrictTaggingDecrypter : public TaggingDecrypter { … };
class TestPacketWriter : public QuicPacketWriter { … };
class DroppingPacketsWithSpecificDestinationWriter
: public QuicPacketWriterWrapper { … };
bool ParseClientVersionNegotiationProbePacket(
const char* packet_bytes, size_t packet_length,
char* destination_connection_id_bytes,
uint8_t* destination_connection_id_length_out);
bool WriteServerVersionNegotiationProbeResponse(
char* packet_bytes, size_t* packet_length_out,
const char* source_connection_id_bytes,
uint8_t source_connection_id_length);
class SavingHttp3DatagramVisitor : public QuicSpdyStream::Http3DatagramVisitor { … };
class SavingConnectIpVisitor : public QuicSpdyStream::ConnectIpVisitor { … };
inline std::string EscapeTestParamName(absl::string_view name) { … }
}
}
#endif