Replace deprecated version of absl::HexStringToBytes in quic/core/qpack tests Replaces the deprecated version of absl::HexStringToBytes that returns std::string with the version that returns bool and populates a passed in std::string. This CL is not expected to introduce any changes in functionality other than now verifying that the call to absl::HexStringToBytes was successful. This allows the Chrome build of QUICHE to build without the `-Wno-deprecated-declarations` clang flag. PiperOrigin-RevId: 614716628
diff --git a/quiche/quic/core/qpack/qpack_decoded_headers_accumulator_test.cc b/quiche/quic/core/qpack/qpack_decoded_headers_accumulator_test.cc index 4af9353..3b64e99 100644 --- a/quiche/quic/core/qpack/qpack_decoded_headers_accumulator_test.cc +++ b/quiche/quic/core/qpack/qpack_decoded_headers_accumulator_test.cc
@@ -5,6 +5,7 @@ #include "quiche/quic/core/qpack/qpack_decoded_headers_accumulator.h" #include <cstring> +#include <string> #include "absl/strings/escaping.h" #include "absl/strings/string_view.h" @@ -79,7 +80,9 @@ // HEADERS frame payload must have a complete Header Block Prefix. TEST_F(QpackDecodedHeadersAccumulatorTest, TruncatedHeaderBlockPrefix) { - accumulator_.Decode(absl::HexStringToBytes("00")); + std::string encoded_data; + ASSERT_TRUE(absl::HexStringToBytes("00", &encoded_data)); + accumulator_.Decode(encoded_data); EXPECT_CALL(visitor_, OnHeaderDecodingError(QUIC_QPACK_DECOMPRESSION_FAILED, @@ -88,7 +91,8 @@ } TEST_F(QpackDecodedHeadersAccumulatorTest, EmptyHeaderList) { - std::string encoded_data(absl::HexStringToBytes("0000")); + std::string encoded_data; + ASSERT_TRUE(absl::HexStringToBytes("0000", &encoded_data)); accumulator_.Decode(encoded_data); QuicHeaderList header_list; @@ -104,7 +108,9 @@ // This payload is the prefix of a valid payload, but EndHeaderBlock() is called // before it can be completely decoded. TEST_F(QpackDecodedHeadersAccumulatorTest, TruncatedPayload) { - accumulator_.Decode(absl::HexStringToBytes("00002366")); + std::string encoded_data; + ASSERT_TRUE(absl::HexStringToBytes("00002366", &encoded_data)); + accumulator_.Decode(encoded_data); EXPECT_CALL(visitor_, OnHeaderDecodingError(QUIC_QPACK_DECOMPRESSION_FAILED, Eq("Incomplete header block."))); @@ -116,11 +122,14 @@ EXPECT_CALL(visitor_, OnHeaderDecodingError(QUIC_QPACK_DECOMPRESSION_FAILED, Eq("Static table entry not found."))); - accumulator_.Decode(absl::HexStringToBytes("0000ff23ff24")); + std::string encoded_data; + ASSERT_TRUE(absl::HexStringToBytes("0000ff23ff24", &encoded_data)); + accumulator_.Decode(encoded_data); } TEST_F(QpackDecodedHeadersAccumulatorTest, Success) { - std::string encoded_data(absl::HexStringToBytes("000023666f6f03626172")); + std::string encoded_data; + ASSERT_TRUE(absl::HexStringToBytes("000023666f6f03626172", &encoded_data)); accumulator_.Decode(encoded_data); QuicHeaderList header_list; @@ -137,18 +146,22 @@ // Test that Decode() calls are not ignored after header list limit is exceeded, // otherwise decoding could fail with "incomplete header block" error. TEST_F(QpackDecodedHeadersAccumulatorTest, ExceedLimitThenSplitInstruction) { + std::string encoded_data; // Total length of header list exceeds kMaxHeaderListSize. - accumulator_.Decode(absl::HexStringToBytes( + ASSERT_TRUE(absl::HexStringToBytes( "0000" // header block prefix "26666f6f626172" // header key: "foobar" "7d61616161616161616161616161616161616161" // header value: 'a' 125 times "616161616161616161616161616161616161616161616161616161616161616161616161" "616161616161616161616161616161616161616161616161616161616161616161616161" "61616161616161616161616161616161616161616161616161616161616161616161" - "ff")); // first byte of a two-byte long Indexed Header Field instruction - accumulator_.Decode(absl::HexStringToBytes( - "0f" // second byte of a two-byte long Indexed Header Field instruction - )); + "ff", // first byte of a two-byte long Indexed Header Field instruction + &encoded_data)); + accumulator_.Decode(encoded_data); + ASSERT_TRUE(absl::HexStringToBytes( + "0f", // second byte of a two-byte long Indexed Header Field instruction + &encoded_data)); + accumulator_.Decode(encoded_data); EXPECT_CALL(visitor_, OnHeadersDecoded(_, true)); accumulator_.EndHeaderBlock(); @@ -156,15 +169,18 @@ // Test that header list limit enforcement works with blocked encoding. TEST_F(QpackDecodedHeadersAccumulatorTest, ExceedLimitBlocked) { + std::string encoded_data; // Total length of header list exceeds kMaxHeaderListSize. - accumulator_.Decode(absl::HexStringToBytes( + ASSERT_TRUE(absl::HexStringToBytes( "0200" // header block prefix "80" // reference to dynamic table entry not yet received "26666f6f626172" // header key: "foobar" "7d61616161616161616161616161616161616161" // header value: 'a' 125 times "616161616161616161616161616161616161616161616161616161616161616161616161" "616161616161616161616161616161616161616161616161616161616161616161616161" - "61616161616161616161616161616161616161616161616161616161616161616161")); + "61616161616161616161616161616161616161616161616161616161616161616161", + &encoded_data)); + accumulator_.Decode(encoded_data); accumulator_.EndHeaderBlock(); // Set dynamic table capacity. @@ -181,8 +197,9 @@ } TEST_F(QpackDecodedHeadersAccumulatorTest, BlockedDecoding) { + std::string encoded_data; // Reference to dynamic table entry not yet received. - std::string encoded_data(absl::HexStringToBytes("020080")); + ASSERT_TRUE(absl::HexStringToBytes("020080", &encoded_data)); accumulator_.Decode(encoded_data); accumulator_.EndHeaderBlock(); @@ -208,8 +225,10 @@ TEST_F(QpackDecodedHeadersAccumulatorTest, BlockedDecodingUnblockedBeforeEndOfHeaderBlock) { + std::string encoded_data; // Reference to dynamic table entry not yet received. - accumulator_.Decode(absl::HexStringToBytes("020080")); + ASSERT_TRUE(absl::HexStringToBytes("020080", &encoded_data)); + accumulator_.Decode(encoded_data); // Set dynamic table capacity. qpack_decoder_.OnSetDynamicTableCapacity(kMaxDynamicTableCapacity); @@ -219,7 +238,8 @@ // Rest of header block: same entry again. EXPECT_CALL(decoder_stream_sender_delegate_, WriteStreamData(Eq(kHeaderAcknowledgement))); - accumulator_.Decode(absl::HexStringToBytes("80")); + ASSERT_TRUE(absl::HexStringToBytes("80", &encoded_data)); + accumulator_.Decode(encoded_data); QuicHeaderList header_list; EXPECT_CALL(visitor_, OnHeadersDecoded(_, false)) @@ -235,14 +255,18 @@ // Regression test for https://crbug.com/1024263. TEST_F(QpackDecodedHeadersAccumulatorTest, BlockedDecodingUnblockedAndErrorBeforeEndOfHeaderBlock) { + std::string encoded_data; // Required Insert Count higher than number of entries causes decoding to be // blocked. - accumulator_.Decode(absl::HexStringToBytes("0200")); + ASSERT_TRUE(absl::HexStringToBytes("0200", &encoded_data)); + accumulator_.Decode(encoded_data); // Indexed Header Field instruction addressing dynamic table entry with // relative index 0, absolute index 0. - accumulator_.Decode(absl::HexStringToBytes("80")); + ASSERT_TRUE(absl::HexStringToBytes("80", &encoded_data)); + accumulator_.Decode(encoded_data); // Relative index larger than or equal to Base is invalid. - accumulator_.Decode(absl::HexStringToBytes("81")); + ASSERT_TRUE(absl::HexStringToBytes("81", &encoded_data)); + accumulator_.Decode(encoded_data); // Set dynamic table capacity. qpack_decoder_.OnSetDynamicTableCapacity(kMaxDynamicTableCapacity);
diff --git a/quiche/quic/core/qpack/qpack_decoder_stream_receiver_test.cc b/quiche/quic/core/qpack/qpack_decoder_stream_receiver_test.cc index 6cee903..0acb0fd 100644 --- a/quiche/quic/core/qpack/qpack_decoder_stream_receiver_test.cc +++ b/quiche/quic/core/qpack/qpack_decoder_stream_receiver_test.cc
@@ -38,60 +38,78 @@ }; TEST_F(QpackDecoderStreamReceiverTest, InsertCountIncrement) { + std::string encoded_data; EXPECT_CALL(delegate_, OnInsertCountIncrement(0)); - stream_.Decode(absl::HexStringToBytes("00")); + ASSERT_TRUE(absl::HexStringToBytes("00", &encoded_data)); + stream_.Decode(encoded_data); EXPECT_CALL(delegate_, OnInsertCountIncrement(10)); - stream_.Decode(absl::HexStringToBytes("0a")); + ASSERT_TRUE(absl::HexStringToBytes("0a", &encoded_data)); + stream_.Decode(encoded_data); EXPECT_CALL(delegate_, OnInsertCountIncrement(63)); - stream_.Decode(absl::HexStringToBytes("3f00")); + ASSERT_TRUE(absl::HexStringToBytes("3f00", &encoded_data)); + stream_.Decode(encoded_data); EXPECT_CALL(delegate_, OnInsertCountIncrement(200)); - stream_.Decode(absl::HexStringToBytes("3f8901")); + ASSERT_TRUE(absl::HexStringToBytes("3f8901", &encoded_data)); + stream_.Decode(encoded_data); EXPECT_CALL(delegate_, OnErrorDetected(QUIC_QPACK_DECODER_STREAM_INTEGER_TOO_LARGE, Eq("Encoded integer too large."))); - stream_.Decode(absl::HexStringToBytes("3fffffffffffffffffffff")); + ASSERT_TRUE(absl::HexStringToBytes("3fffffffffffffffffffff", &encoded_data)); + stream_.Decode(encoded_data); } TEST_F(QpackDecoderStreamReceiverTest, HeaderAcknowledgement) { + std::string encoded_data; EXPECT_CALL(delegate_, OnHeaderAcknowledgement(0)); - stream_.Decode(absl::HexStringToBytes("80")); + ASSERT_TRUE(absl::HexStringToBytes("80", &encoded_data)); + stream_.Decode(encoded_data); EXPECT_CALL(delegate_, OnHeaderAcknowledgement(37)); - stream_.Decode(absl::HexStringToBytes("a5")); + ASSERT_TRUE(absl::HexStringToBytes("a5", &encoded_data)); + stream_.Decode(encoded_data); EXPECT_CALL(delegate_, OnHeaderAcknowledgement(127)); - stream_.Decode(absl::HexStringToBytes("ff00")); + ASSERT_TRUE(absl::HexStringToBytes("ff00", &encoded_data)); + stream_.Decode(encoded_data); EXPECT_CALL(delegate_, OnHeaderAcknowledgement(503)); - stream_.Decode(absl::HexStringToBytes("fff802")); + ASSERT_TRUE(absl::HexStringToBytes("fff802", &encoded_data)); + stream_.Decode(encoded_data); EXPECT_CALL(delegate_, OnErrorDetected(QUIC_QPACK_DECODER_STREAM_INTEGER_TOO_LARGE, Eq("Encoded integer too large."))); - stream_.Decode(absl::HexStringToBytes("ffffffffffffffffffffff")); + ASSERT_TRUE(absl::HexStringToBytes("ffffffffffffffffffffff", &encoded_data)); + stream_.Decode(encoded_data); } TEST_F(QpackDecoderStreamReceiverTest, StreamCancellation) { + std::string encoded_data; EXPECT_CALL(delegate_, OnStreamCancellation(0)); - stream_.Decode(absl::HexStringToBytes("40")); + ASSERT_TRUE(absl::HexStringToBytes("40", &encoded_data)); + stream_.Decode(encoded_data); EXPECT_CALL(delegate_, OnStreamCancellation(19)); - stream_.Decode(absl::HexStringToBytes("53")); + ASSERT_TRUE(absl::HexStringToBytes("53", &encoded_data)); + stream_.Decode(encoded_data); EXPECT_CALL(delegate_, OnStreamCancellation(63)); - stream_.Decode(absl::HexStringToBytes("7f00")); + ASSERT_TRUE(absl::HexStringToBytes("7f00", &encoded_data)); + stream_.Decode(encoded_data); EXPECT_CALL(delegate_, OnStreamCancellation(110)); - stream_.Decode(absl::HexStringToBytes("7f2f")); + ASSERT_TRUE(absl::HexStringToBytes("7f2f", &encoded_data)); + stream_.Decode(encoded_data); EXPECT_CALL(delegate_, OnErrorDetected(QUIC_QPACK_DECODER_STREAM_INTEGER_TOO_LARGE, Eq("Encoded integer too large."))); - stream_.Decode(absl::HexStringToBytes("7fffffffffffffffffffff")); + ASSERT_TRUE(absl::HexStringToBytes("7fffffffffffffffffffff", &encoded_data)); + stream_.Decode(encoded_data); } } // namespace
diff --git a/quiche/quic/core/qpack/qpack_decoder_stream_sender_test.cc b/quiche/quic/core/qpack/qpack_decoder_stream_sender_test.cc index 8c43af5..dee6282 100644 --- a/quiche/quic/core/qpack/qpack_decoder_stream_sender_test.cc +++ b/quiche/quic/core/qpack/qpack_decoder_stream_sender_test.cc
@@ -4,6 +4,8 @@ #include "quiche/quic/core/qpack/qpack_decoder_stream_sender.h" +#include <string> + #include "absl/strings/escaping.h" #include "quiche/quic/platform/api/quic_test.h" #include "quiche/quic/test_tools/qpack/qpack_test_utils.h" @@ -27,72 +29,89 @@ }; TEST_F(QpackDecoderStreamSenderTest, InsertCountIncrement) { - EXPECT_CALL(delegate_, WriteStreamData(Eq(absl::HexStringToBytes("00")))); + std::string stream_data; + ASSERT_TRUE(absl::HexStringToBytes("00", &stream_data)); + EXPECT_CALL(delegate_, WriteStreamData(Eq(stream_data))); stream_.SendInsertCountIncrement(0); stream_.Flush(); - EXPECT_CALL(delegate_, WriteStreamData(Eq(absl::HexStringToBytes("0a")))); + ASSERT_TRUE(absl::HexStringToBytes("0a", &stream_data)); + EXPECT_CALL(delegate_, WriteStreamData(Eq(stream_data))); stream_.SendInsertCountIncrement(10); stream_.Flush(); - EXPECT_CALL(delegate_, WriteStreamData(Eq(absl::HexStringToBytes("3f00")))); + ASSERT_TRUE(absl::HexStringToBytes("3f00", &stream_data)); + EXPECT_CALL(delegate_, WriteStreamData(Eq(stream_data))); stream_.SendInsertCountIncrement(63); stream_.Flush(); - EXPECT_CALL(delegate_, WriteStreamData(Eq(absl::HexStringToBytes("3f8901")))); + ASSERT_TRUE(absl::HexStringToBytes("3f8901", &stream_data)); + EXPECT_CALL(delegate_, WriteStreamData(Eq(stream_data))); stream_.SendInsertCountIncrement(200); stream_.Flush(); } TEST_F(QpackDecoderStreamSenderTest, HeaderAcknowledgement) { - EXPECT_CALL(delegate_, WriteStreamData(Eq(absl::HexStringToBytes("80")))); + std::string stream_data; + ASSERT_TRUE(absl::HexStringToBytes("80", &stream_data)); + EXPECT_CALL(delegate_, WriteStreamData(Eq(stream_data))); stream_.SendHeaderAcknowledgement(0); stream_.Flush(); - EXPECT_CALL(delegate_, WriteStreamData(Eq(absl::HexStringToBytes("a5")))); + ASSERT_TRUE(absl::HexStringToBytes("a5", &stream_data)); + EXPECT_CALL(delegate_, WriteStreamData(Eq(stream_data))); stream_.SendHeaderAcknowledgement(37); stream_.Flush(); - EXPECT_CALL(delegate_, WriteStreamData(Eq(absl::HexStringToBytes("ff00")))); + ASSERT_TRUE(absl::HexStringToBytes("ff00", &stream_data)); + EXPECT_CALL(delegate_, WriteStreamData(Eq(stream_data))); stream_.SendHeaderAcknowledgement(127); stream_.Flush(); - EXPECT_CALL(delegate_, WriteStreamData(Eq(absl::HexStringToBytes("fff802")))); + ASSERT_TRUE(absl::HexStringToBytes("fff802", &stream_data)); + EXPECT_CALL(delegate_, WriteStreamData(Eq(stream_data))); stream_.SendHeaderAcknowledgement(503); stream_.Flush(); } TEST_F(QpackDecoderStreamSenderTest, StreamCancellation) { - EXPECT_CALL(delegate_, WriteStreamData(Eq(absl::HexStringToBytes("40")))); + std::string stream_data; + ASSERT_TRUE(absl::HexStringToBytes("40", &stream_data)); + EXPECT_CALL(delegate_, WriteStreamData(Eq(stream_data))); stream_.SendStreamCancellation(0); stream_.Flush(); - EXPECT_CALL(delegate_, WriteStreamData(Eq(absl::HexStringToBytes("53")))); + ASSERT_TRUE(absl::HexStringToBytes("53", &stream_data)); + EXPECT_CALL(delegate_, WriteStreamData(Eq(stream_data))); stream_.SendStreamCancellation(19); stream_.Flush(); - EXPECT_CALL(delegate_, WriteStreamData(Eq(absl::HexStringToBytes("7f00")))); + ASSERT_TRUE(absl::HexStringToBytes("7f00", &stream_data)); + EXPECT_CALL(delegate_, WriteStreamData(Eq(stream_data))); stream_.SendStreamCancellation(63); stream_.Flush(); - EXPECT_CALL(delegate_, WriteStreamData(Eq(absl::HexStringToBytes("7f2f")))); + ASSERT_TRUE(absl::HexStringToBytes("7f2f", &stream_data)); + EXPECT_CALL(delegate_, WriteStreamData(Eq(stream_data))); stream_.SendStreamCancellation(110); stream_.Flush(); } TEST_F(QpackDecoderStreamSenderTest, Coalesce) { + std::string stream_data; stream_.SendInsertCountIncrement(10); stream_.SendHeaderAcknowledgement(37); stream_.SendStreamCancellation(0); - EXPECT_CALL(delegate_, WriteStreamData(Eq(absl::HexStringToBytes("0aa540")))); + ASSERT_TRUE(absl::HexStringToBytes("0aa540", &stream_data)); + EXPECT_CALL(delegate_, WriteStreamData(Eq(stream_data))); stream_.Flush(); stream_.SendInsertCountIncrement(63); stream_.SendStreamCancellation(110); - EXPECT_CALL(delegate_, - WriteStreamData(Eq(absl::HexStringToBytes("3f007f2f")))); + ASSERT_TRUE(absl::HexStringToBytes("3f007f2f", &stream_data)); + EXPECT_CALL(delegate_, WriteStreamData(Eq(stream_data))); stream_.Flush(); }
diff --git a/quiche/quic/core/qpack/qpack_decoder_test.cc b/quiche/quic/core/qpack/qpack_decoder_test.cc index b82e958..ce37190 100644 --- a/quiche/quic/core/qpack/qpack_decoder_test.cc +++ b/quiche/quic/core/qpack/qpack_decoder_test.cc
@@ -5,6 +5,7 @@ #include "quiche/quic/core/qpack/qpack_decoder.h" #include <algorithm> +#include <string> #include "absl/strings/escaping.h" #include "absl/strings/string_view.h" @@ -118,7 +119,9 @@ Eq("Incomplete header data prefix."))); // Header Data Prefix is at least two bytes long. - DecodeHeaderBlock(absl::HexStringToBytes("00")); + std::string input; + ASSERT_TRUE(absl::HexStringToBytes("00", &input)); + DecodeHeaderBlock(input); } // Regression test for https://1025209: QpackProgressiveDecoder must not crash @@ -131,41 +134,53 @@ Eq("Encoded integer too large."))); // Encoded Required Insert Count in Header Data Prefix is too large. - DecodeData(absl::HexStringToBytes("ffffffffffffffffffffffffffff")); + std::string input; + ASSERT_TRUE(absl::HexStringToBytes("ffffffffffffffffffffffffffff", &input)); + DecodeData(input); } TEST_P(QpackDecoderTest, EmptyHeaderBlock) { EXPECT_CALL(handler_, OnDecodingCompleted()); - DecodeHeaderBlock(absl::HexStringToBytes("0000")); + std::string input; + ASSERT_TRUE(absl::HexStringToBytes("0000", &input)); + DecodeHeaderBlock(input); } TEST_P(QpackDecoderTest, LiteralEntryEmptyName) { EXPECT_CALL(handler_, OnHeaderDecoded(Eq(""), Eq("foo"))); EXPECT_CALL(handler_, OnDecodingCompleted()); - DecodeHeaderBlock(absl::HexStringToBytes("00002003666f6f")); + std::string input; + ASSERT_TRUE(absl::HexStringToBytes("00002003666f6f", &input)); + DecodeHeaderBlock(input); } TEST_P(QpackDecoderTest, LiteralEntryEmptyValue) { EXPECT_CALL(handler_, OnHeaderDecoded(Eq("foo"), Eq(""))); EXPECT_CALL(handler_, OnDecodingCompleted()); - DecodeHeaderBlock(absl::HexStringToBytes("000023666f6f00")); + std::string input; + ASSERT_TRUE(absl::HexStringToBytes("000023666f6f00", &input)); + DecodeHeaderBlock(input); } TEST_P(QpackDecoderTest, LiteralEntryEmptyNameAndValue) { EXPECT_CALL(handler_, OnHeaderDecoded(Eq(""), Eq(""))); EXPECT_CALL(handler_, OnDecodingCompleted()); - DecodeHeaderBlock(absl::HexStringToBytes("00002000")); + std::string input; + ASSERT_TRUE(absl::HexStringToBytes("00002000", &input)); + DecodeHeaderBlock(input); } TEST_P(QpackDecoderTest, SimpleLiteralEntry) { EXPECT_CALL(handler_, OnHeaderDecoded(Eq("foo"), Eq("bar"))); EXPECT_CALL(handler_, OnDecodingCompleted()); - DecodeHeaderBlock(absl::HexStringToBytes("000023666f6f03626172")); + std::string input; + ASSERT_TRUE(absl::HexStringToBytes("000023666f6f03626172", &input)); + DecodeHeaderBlock(input); } TEST_P(QpackDecoderTest, MultipleLiteralEntries) { @@ -174,7 +189,8 @@ EXPECT_CALL(handler_, OnHeaderDecoded(Eq("foobaar"), absl::string_view(str))); EXPECT_CALL(handler_, OnDecodingCompleted()); - DecodeHeaderBlock(absl::HexStringToBytes( + std::string input; + ASSERT_TRUE(absl::HexStringToBytes( "0000" // prefix "23666f6f03626172" // foo: bar "2700666f6f62616172" // 7 octet long header name, the smallest number @@ -184,7 +200,9 @@ "6161616161616161616161616161616161616161616161616161616161616161616161" "6161616161616161616161616161616161616161616161616161616161616161616161" "6161616161616161616161616161616161616161616161616161616161616161616161" - "616161616161")); + "616161616161", + &input)); + DecodeHeaderBlock(input); } // Name Length value is too large for varint decoder to decode. @@ -193,7 +211,9 @@ OnDecodingErrorDetected(QUIC_QPACK_DECOMPRESSION_FAILED, Eq("Encoded integer too large."))); - DecodeHeaderBlock(absl::HexStringToBytes("000027ffffffffffffffffffff")); + std::string input; + ASSERT_TRUE(absl::HexStringToBytes("000027ffffffffffffffffffff", &input)); + DecodeHeaderBlock(input); } // Name Length value can be decoded by varint decoder but exceeds 1 MB limit. @@ -202,7 +222,9 @@ OnDecodingErrorDetected(QUIC_QPACK_DECOMPRESSION_FAILED, Eq("String literal too long."))); - DecodeHeaderBlock(absl::HexStringToBytes("000027ffff7f")); + std::string input; + ASSERT_TRUE(absl::HexStringToBytes("000027ffff7f", &input)); + DecodeHeaderBlock(input); } // Value Length value is too large for varint decoder to decode. @@ -211,8 +233,10 @@ OnDecodingErrorDetected(QUIC_QPACK_DECOMPRESSION_FAILED, Eq("Encoded integer too large."))); - DecodeHeaderBlock( - absl::HexStringToBytes("000023666f6f7fffffffffffffffffffff")); + std::string input; + ASSERT_TRUE( + absl::HexStringToBytes("000023666f6f7fffffffffffffffffffff", &input)); + DecodeHeaderBlock(input); } // Value Length value can be decoded by varint decoder but exceeds 1 MB limit. @@ -221,13 +245,18 @@ OnDecodingErrorDetected(QUIC_QPACK_DECOMPRESSION_FAILED, Eq("String literal too long."))); - DecodeHeaderBlock(absl::HexStringToBytes("000023666f6f7fffff7f")); + std::string input; + ASSERT_TRUE(absl::HexStringToBytes("000023666f6f7fffff7f", &input)); + DecodeHeaderBlock(input); } TEST_P(QpackDecoderTest, LineFeedInValue) { EXPECT_CALL(handler_, OnHeaderDecoded(Eq("foo"), Eq("ba\nr"))); EXPECT_CALL(handler_, OnDecodingCompleted()); - DecodeHeaderBlock(absl::HexStringToBytes("000023666f6f0462610a72")); + + std::string input; + ASSERT_TRUE(absl::HexStringToBytes("000023666f6f0462610a72", &input)); + DecodeHeaderBlock(input); } TEST_P(QpackDecoderTest, IncompleteHeaderBlock) { @@ -235,15 +264,19 @@ OnDecodingErrorDetected(QUIC_QPACK_DECOMPRESSION_FAILED, Eq("Incomplete header block."))); - DecodeHeaderBlock(absl::HexStringToBytes("00002366")); + std::string input; + ASSERT_TRUE(absl::HexStringToBytes("00002366", &input)); + DecodeHeaderBlock(input); } TEST_P(QpackDecoderTest, HuffmanSimple) { EXPECT_CALL(handler_, OnHeaderDecoded(Eq("custom-key"), Eq("custom-value"))); EXPECT_CALL(handler_, OnDecodingCompleted()); - DecodeHeaderBlock( - absl::HexStringToBytes("00002f0125a849e95ba97d7f8925a849e95bb8e8b4bf")); + std::string input; + ASSERT_TRUE(absl::HexStringToBytes( + "00002f0125a849e95ba97d7f8925a849e95bb8e8b4bf", &input)); + DecodeHeaderBlock(input); } TEST_P(QpackDecoderTest, AlternatingHuffmanNonHuffman) { @@ -251,7 +284,8 @@ .Times(4); EXPECT_CALL(handler_, OnDecodingCompleted()); - DecodeHeaderBlock(absl::HexStringToBytes( + std::string input; + ASSERT_TRUE(absl::HexStringToBytes( "0000" // Prefix. "2f0125a849e95ba97d7f" // Huffman-encoded name. "8925a849e95bb8e8b4bf" // Huffman-encoded value. @@ -260,7 +294,9 @@ "2f0125a849e95ba97d7f" // Huffman-encoded name. "0c637573746f6d2d76616c7565" // Non-Huffman encoded value. "2703637573746f6d2d6b6579" // Non-Huffman encoded name. - "8925a849e95bb8e8b4bf")); // Huffman-encoded value. + "8925a849e95bb8e8b4bf", // Huffman-encoded value. + &input)); + DecodeHeaderBlock(input); } TEST_P(QpackDecoderTest, HuffmanNameDoesNotHaveEOSPrefix) { @@ -270,8 +306,10 @@ // 'y' ends in 0b0 on the most significant bit of the last byte. // The remaining 7 bits must be a prefix of EOS, which is all 1s. - DecodeHeaderBlock( - absl::HexStringToBytes("00002f0125a849e95ba97d7e8925a849e95bb8e8b4bf")); + std::string input; + ASSERT_TRUE(absl::HexStringToBytes( + "00002f0125a849e95ba97d7e8925a849e95bb8e8b4bf", &input)); + DecodeHeaderBlock(input); } TEST_P(QpackDecoderTest, HuffmanValueDoesNotHaveEOSPrefix) { @@ -281,8 +319,10 @@ // 'e' ends in 0b101, taking up the 3 most significant bits of the last byte. // The remaining 5 bits must be a prefix of EOS, which is all 1s. - DecodeHeaderBlock( - absl::HexStringToBytes("00002f0125a849e95ba97d7f8925a849e95bb8e8b4be")); + std::string input; + ASSERT_TRUE(absl::HexStringToBytes( + "00002f0125a849e95ba97d7f8925a849e95bb8e8b4be", &input)); + DecodeHeaderBlock(input); } TEST_P(QpackDecoderTest, HuffmanNameEOSPrefixTooLong) { @@ -293,8 +333,10 @@ // The trailing EOS prefix must be at most 7 bits long. Appending one octet // with value 0xff is invalid, even though 0b111111111111111 (15 bits) is a // prefix of EOS. - DecodeHeaderBlock( - absl::HexStringToBytes("00002f0225a849e95ba97d7fff8925a849e95bb8e8b4bf")); + std::string input; + ASSERT_TRUE(absl::HexStringToBytes( + "00002f0225a849e95ba97d7fff8925a849e95bb8e8b4bf", &input)); + DecodeHeaderBlock(input); } TEST_P(QpackDecoderTest, HuffmanValueEOSPrefixTooLong) { @@ -305,8 +347,10 @@ // The trailing EOS prefix must be at most 7 bits long. Appending one octet // with value 0xff is invalid, even though 0b1111111111111 (13 bits) is a // prefix of EOS. - DecodeHeaderBlock( - absl::HexStringToBytes("00002f0125a849e95ba97d7f8a25a849e95bb8e8b4bfff")); + std::string input; + ASSERT_TRUE(absl::HexStringToBytes( + "00002f0125a849e95ba97d7f8a25a849e95bb8e8b4bfff", &input)); + DecodeHeaderBlock(input); } TEST_P(QpackDecoderTest, StaticTable) { @@ -327,8 +371,10 @@ EXPECT_CALL(handler_, OnDecodingCompleted()); - DecodeHeaderBlock(absl::HexStringToBytes( - "0000d1dfccd45f108621e9aec2a11f5c8294e75f000554524143455f1000")); + std::string input; + ASSERT_TRUE(absl::HexStringToBytes( + "0000d1dfccd45f108621e9aec2a11f5c8294e75f000554524143455f1000", &input)); + DecodeHeaderBlock(input); } TEST_P(QpackDecoderTest, TooHighStaticTableIndex) { @@ -341,18 +387,23 @@ OnDecodingErrorDetected(QUIC_QPACK_DECOMPRESSION_FAILED, Eq("Static table entry not found."))); - DecodeHeaderBlock(absl::HexStringToBytes("0000ff23ff24")); + std::string input; + ASSERT_TRUE(absl::HexStringToBytes("0000ff23ff24", &input)); + DecodeHeaderBlock(input); } TEST_P(QpackDecoderTest, DynamicTable) { - DecodeEncoderStreamData(absl::HexStringToBytes( + std::string input; + ASSERT_TRUE(absl::HexStringToBytes( "3fe107" // Set dynamic table capacity to 1024. "6294e703626172" // Add literal entry with name "foo" and value "bar". "80035a5a5a" // Add entry with name of dynamic table entry index 0 // (relative index) and value "ZZZ". "cf8294e7" // Add entry with name of static table entry index 15 // and value "foo". - "01")); // Duplicate entry with relative index 1. + "01", // Duplicate entry with relative index 1. + &input)); + DecodeEncoderStreamData(input); // Now there are four entries in the dynamic table. // Entry 0: "foo", "bar" @@ -381,15 +432,17 @@ .InSequence(s); } - DecodeHeaderBlock(absl::HexStringToBytes( + ASSERT_TRUE(absl::HexStringToBytes( "0500" // Required Insert Count 4 and Delta Base 0. // Base is 4 + 0 = 4. "83" // Dynamic table entry with relative index 3, absolute index 0. "82" // Dynamic table entry with relative index 2, absolute index 1. "81" // Dynamic table entry with relative index 1, absolute index 2. "80" // Dynamic table entry with relative index 0, absolute index 3. - "41025a5a")); // Name of entry 1 (relative index) from dynamic table, - // with value "ZZ". + "41025a5a", // Name of entry 1 (relative index) from dynamic table, + // with value "ZZ". + &input)); + DecodeHeaderBlock(input); if (GetQuicRestartFlag(quic_opport_bundle_qpack_decoder_data3)) { FlushDecoderStream(); } @@ -412,15 +465,17 @@ .InSequence(s); } - DecodeHeaderBlock(absl::HexStringToBytes( + ASSERT_TRUE(absl::HexStringToBytes( "0502" // Required Insert Count 4 and Delta Base 2. // Base is 4 + 2 = 6. "85" // Dynamic table entry with relative index 5, absolute index 0. "84" // Dynamic table entry with relative index 4, absolute index 1. "83" // Dynamic table entry with relative index 3, absolute index 2. "82" // Dynamic table entry with relative index 2, absolute index 3. - "43025a5a")); // Name of entry 3 (relative index) from dynamic table, - // with value "ZZ". + "43025a5a", // Name of entry 3 (relative index) from dynamic table, + // with value "ZZ". + &input)); + DecodeHeaderBlock(input); if (GetQuicRestartFlag(quic_opport_bundle_qpack_decoder_data3)) { FlushDecoderStream(); } @@ -443,63 +498,76 @@ .InSequence(s); } - DecodeHeaderBlock(absl::HexStringToBytes( + ASSERT_TRUE(absl::HexStringToBytes( "0582" // Required Insert Count 4 and Delta Base 2 with sign bit set. // Base is 4 - 2 - 1 = 1. "80" // Dynamic table entry with relative index 0, absolute index 0. "10" // Dynamic table entry with post-base index 0, absolute index 1. "11" // Dynamic table entry with post-base index 1, absolute index 2. "12" // Dynamic table entry with post-base index 2, absolute index 3. - "01025a5a")); // Name of entry 1 (post-base index) from dynamic table, - // with value "ZZ". + "01025a5a", // Name of entry 1 (post-base index) from dynamic table, + // with value "ZZ". + &input)); + DecodeHeaderBlock(input); if (GetQuicRestartFlag(quic_opport_bundle_qpack_decoder_data3)) { FlushDecoderStream(); } } TEST_P(QpackDecoderTest, DecreasingDynamicTableCapacityEvictsEntries) { + std::string input; // Set dynamic table capacity to 1024. - DecodeEncoderStreamData(absl::HexStringToBytes("3fe107")); + ASSERT_TRUE(absl::HexStringToBytes("3fe107", &input)); + DecodeEncoderStreamData(input); // Add literal entry with name "foo" and value "bar". - DecodeEncoderStreamData(absl::HexStringToBytes("6294e703626172")); + ASSERT_TRUE(absl::HexStringToBytes("6294e703626172", &input)); + DecodeEncoderStreamData(input); EXPECT_CALL(handler_, OnHeaderDecoded(Eq("foo"), Eq("bar"))); EXPECT_CALL(handler_, OnDecodingCompleted()); EXPECT_CALL(decoder_stream_sender_delegate_, WriteStreamData(Eq(kHeaderAcknowledgement))); - DecodeHeaderBlock(absl::HexStringToBytes( - "0200" // Required Insert Count 1 and Delta Base 0. - // Base is 1 + 0 = 1. - "80")); // Dynamic table entry with relative index 0, absolute index 0. + ASSERT_TRUE(absl::HexStringToBytes( + "0200" // Required Insert Count 1 and Delta Base 0. + // Base is 1 + 0 = 1. + "80", // Dynamic table entry with relative index 0, absolute index 0. + &input)); + DecodeHeaderBlock(input); // Change dynamic table capacity to 32 bytes, smaller than the entry. // This must cause the entry to be evicted. - DecodeEncoderStreamData(absl::HexStringToBytes("3f01")); + ASSERT_TRUE(absl::HexStringToBytes("3f01", &input)); + DecodeEncoderStreamData(input); EXPECT_CALL(handler_, OnDecodingErrorDetected( QUIC_QPACK_DECOMPRESSION_FAILED, Eq("Dynamic table entry already evicted."))); - DecodeHeaderBlock(absl::HexStringToBytes( - "0200" // Required Insert Count 1 and Delta Base 0. - // Base is 1 + 0 = 1. - "80")); // Dynamic table entry with relative index 0, absolute index 0. + ASSERT_TRUE(absl::HexStringToBytes( + "0200" // Required Insert Count 1 and Delta Base 0. + // Base is 1 + 0 = 1. + "80", // Dynamic table entry with relative index 0, absolute index 0. + &input)); + DecodeHeaderBlock(input); if (GetQuicRestartFlag(quic_opport_bundle_qpack_decoder_data3)) { FlushDecoderStream(); } } TEST_P(QpackDecoderTest, EncoderStreamErrorEntryTooLarge) { + std::string input; EXPECT_CALL( encoder_stream_error_delegate_, OnEncoderStreamError(QUIC_QPACK_ENCODER_STREAM_ERROR_INSERTING_LITERAL, Eq("Error inserting literal entry."))); // Set dynamic table capacity to 34. - DecodeEncoderStreamData(absl::HexStringToBytes("3f03")); + ASSERT_TRUE(absl::HexStringToBytes("3f03", &input)); + DecodeEncoderStreamData(input); // Add literal entry with name "foo" and value "bar", size is 32 + 3 + 3 = 38. - DecodeEncoderStreamData(absl::HexStringToBytes("6294e703626172")); + ASSERT_TRUE(absl::HexStringToBytes("6294e703626172", &input)); + DecodeEncoderStreamData(input); } TEST_P(QpackDecoderTest, EncoderStreamErrorInvalidStaticTableEntry) { @@ -509,7 +577,9 @@ Eq("Invalid static table entry."))); // Address invalid static table entry index 99. - DecodeEncoderStreamData(absl::HexStringToBytes("ff2400")); + std::string input; + ASSERT_TRUE(absl::HexStringToBytes("ff2400", &input)); + DecodeEncoderStreamData(input); } TEST_P(QpackDecoderTest, EncoderStreamErrorInvalidDynamicTableEntry) { @@ -518,12 +588,15 @@ QUIC_QPACK_ENCODER_STREAM_INSERTION_INVALID_RELATIVE_INDEX, Eq("Invalid relative index."))); - DecodeEncoderStreamData(absl::HexStringToBytes( + std::string input; + ASSERT_TRUE(absl::HexStringToBytes( "3fe107" // Set dynamic table capacity to 1024. "6294e703626172" // Add literal entry with name "foo" and value "bar". - "8100")); // Address dynamic table entry with relative index 1. Such - // entry does not exist. The most recently added and only - // dynamic table entry has relative index 0. + "8100", // Address dynamic table entry with relative index 1. Such + // entry does not exist. The most recently added and only + // dynamic table entry has relative index 0. + &input)); + DecodeEncoderStreamData(input); } TEST_P(QpackDecoderTest, EncoderStreamErrorDuplicateInvalidEntry) { @@ -532,12 +605,15 @@ QUIC_QPACK_ENCODER_STREAM_DUPLICATE_INVALID_RELATIVE_INDEX, Eq("Invalid relative index."))); - DecodeEncoderStreamData(absl::HexStringToBytes( + std::string input; + ASSERT_TRUE(absl::HexStringToBytes( "3fe107" // Set dynamic table capacity to 1024. "6294e703626172" // Add literal entry with name "foo" and value "bar". - "01")); // Duplicate dynamic table entry with relative index 1. Such - // entry does not exist. The most recently added and only - // dynamic table entry has relative index 0. + "01", // Duplicate dynamic table entry with relative index 1. Such + // entry does not exist. The most recently added and only + // dynamic table entry has relative index 0. + &input)); + DecodeEncoderStreamData(input); } TEST_P(QpackDecoderTest, EncoderStreamErrorTooLargeInteger) { @@ -545,23 +621,30 @@ OnEncoderStreamError(QUIC_QPACK_ENCODER_STREAM_INTEGER_TOO_LARGE, Eq("Encoded integer too large."))); - DecodeEncoderStreamData(absl::HexStringToBytes("3fffffffffffffffffffff")); + std::string input; + ASSERT_TRUE(absl::HexStringToBytes("3fffffffffffffffffffff", &input)); + DecodeEncoderStreamData(input); } TEST_P(QpackDecoderTest, InvalidDynamicEntryWhenBaseIsZero) { EXPECT_CALL(handler_, OnDecodingErrorDetected(QUIC_QPACK_DECOMPRESSION_FAILED, Eq("Invalid relative index."))); + std::string input; // Set dynamic table capacity to 1024. - DecodeEncoderStreamData(absl::HexStringToBytes("3fe107")); + ASSERT_TRUE(absl::HexStringToBytes("3fe107", &input)); + DecodeEncoderStreamData(input); // Add literal entry with name "foo" and value "bar". - DecodeEncoderStreamData(absl::HexStringToBytes("6294e703626172")); + ASSERT_TRUE(absl::HexStringToBytes("6294e703626172", &input)); + DecodeEncoderStreamData(input); - DecodeHeaderBlock(absl::HexStringToBytes( - "0280" // Required Insert Count is 1. Base 1 - 1 - 0 = 0 is explicitly - // permitted by the spec. - "80")); // However, addressing entry with relative index 0 would point to - // absolute index -1, which is invalid. + ASSERT_TRUE(absl::HexStringToBytes( + "0280" // Required Insert Count is 1. Base 1 - 1 - 0 = 0 is explicitly + // permitted by the spec. + "80", // However, addressing entry with relative index 0 would point to + // absolute index -1, which is invalid. + &input)); + DecodeHeaderBlock(input); } TEST_P(QpackDecoderTest, InvalidNegativeBase) { @@ -570,87 +653,108 @@ // Required Insert Count 1, Delta Base 1 with sign bit set, Base would // be 1 - 1 - 1 = -1, but it is not allowed to be negative. - DecodeHeaderBlock(absl::HexStringToBytes("0281")); + std::string input; + ASSERT_TRUE(absl::HexStringToBytes("0281", &input)); + DecodeHeaderBlock(input); } TEST_P(QpackDecoderTest, InvalidDynamicEntryByRelativeIndex) { + std::string input; // Set dynamic table capacity to 1024. - DecodeEncoderStreamData(absl::HexStringToBytes("3fe107")); + ASSERT_TRUE(absl::HexStringToBytes("3fe107", &input)); + DecodeEncoderStreamData(input); // Add literal entry with name "foo" and value "bar". - DecodeEncoderStreamData(absl::HexStringToBytes("6294e703626172")); + ASSERT_TRUE(absl::HexStringToBytes("6294e703626172", &input)); + DecodeEncoderStreamData(input); EXPECT_CALL(handler_, OnDecodingErrorDetected(QUIC_QPACK_DECOMPRESSION_FAILED, Eq("Invalid relative index."))); - DecodeHeaderBlock(absl::HexStringToBytes( + ASSERT_TRUE(absl::HexStringToBytes( + "0200" // Required Insert Count 1 and Delta Base 0. + // Base is 1 + 0 = 1. + "81", // Indexed Header Field instruction addressing relative index 1. + // This is absolute index -1, which is invalid. + &input)); + DecodeHeaderBlock(input); + + EXPECT_CALL(handler_, OnDecodingErrorDetected(QUIC_QPACK_DECOMPRESSION_FAILED, + Eq("Invalid relative index."))); + + ASSERT_TRUE(absl::HexStringToBytes( "0200" // Required Insert Count 1 and Delta Base 0. // Base is 1 + 0 = 1. - "81")); // Indexed Header Field instruction addressing relative index 1. - // This is absolute index -1, which is invalid. - - EXPECT_CALL(handler_, OnDecodingErrorDetected(QUIC_QPACK_DECOMPRESSION_FAILED, - Eq("Invalid relative index."))); - - DecodeHeaderBlock(absl::HexStringToBytes( - "0200" // Required Insert Count 1 and Delta Base 0. - // Base is 1 + 0 = 1. - "4100")); // Literal Header Field with Name Reference instruction - // addressing relative index 1. This is absolute index -1, - // which is invalid. + "4100", // Literal Header Field with Name Reference instruction + // addressing relative index 1. This is absolute index -1, + // which is invalid. + &input)); + DecodeHeaderBlock(input); } TEST_P(QpackDecoderTest, EvictedDynamicTableEntry) { + std::string input; // Update dynamic table capacity to 128. - DecodeEncoderStreamData(absl::HexStringToBytes("3f61")); + ASSERT_TRUE(absl::HexStringToBytes("3f61", &input)); + DecodeEncoderStreamData(input); // Add literal entry with name "foo" and value "bar", size 32 + 3 + 3 = 38. // This fits in the table three times. - DecodeEncoderStreamData(absl::HexStringToBytes("6294e703626172")); + ASSERT_TRUE(absl::HexStringToBytes("6294e703626172", &input)); + DecodeEncoderStreamData(input); // Duplicate entry four times. This evicts the first two instances. - DecodeEncoderStreamData(absl::HexStringToBytes("00000000")); + ASSERT_TRUE(absl::HexStringToBytes("00000000", &input)); + DecodeEncoderStreamData(input); EXPECT_CALL(handler_, OnDecodingErrorDetected( QUIC_QPACK_DECOMPRESSION_FAILED, Eq("Dynamic table entry already evicted."))); - DecodeHeaderBlock(absl::HexStringToBytes( + ASSERT_TRUE(absl::HexStringToBytes( + "0500" // Required Insert Count 4 and Delta Base 0. + // Base is 4 + 0 = 4. + "82", // Indexed Header Field instruction addressing relative index 2. + // This is absolute index 1. Such entry does not exist. + &input)); + DecodeHeaderBlock(input); + + EXPECT_CALL(handler_, OnDecodingErrorDetected( + QUIC_QPACK_DECOMPRESSION_FAILED, + Eq("Dynamic table entry already evicted."))); + + ASSERT_TRUE(absl::HexStringToBytes( "0500" // Required Insert Count 4 and Delta Base 0. // Base is 4 + 0 = 4. - "82")); // Indexed Header Field instruction addressing relative index 2. - // This is absolute index 1. Such entry does not exist. + "4200", // Literal Header Field with Name Reference instruction + // addressing relative index 2. This is absolute index 1. Such + // entry does not exist. + &input)); + DecodeHeaderBlock(input); EXPECT_CALL(handler_, OnDecodingErrorDetected( QUIC_QPACK_DECOMPRESSION_FAILED, Eq("Dynamic table entry already evicted."))); - DecodeHeaderBlock(absl::HexStringToBytes( - "0500" // Required Insert Count 4 and Delta Base 0. - // Base is 4 + 0 = 4. - "4200")); // Literal Header Field with Name Reference instruction - // addressing relative index 2. This is absolute index 1. Such - // entry does not exist. + ASSERT_TRUE(absl::HexStringToBytes( + "0380" // Required Insert Count 2 and Delta Base 0 with sign bit set. + // Base is 2 - 0 - 1 = 1 + "10", // Indexed Header Field instruction addressing dynamic table + // entry with post-base index 0, absolute index 1. Such entry + // does not exist. + &input)); + DecodeHeaderBlock(input); EXPECT_CALL(handler_, OnDecodingErrorDetected( QUIC_QPACK_DECOMPRESSION_FAILED, Eq("Dynamic table entry already evicted."))); - DecodeHeaderBlock(absl::HexStringToBytes( + ASSERT_TRUE(absl::HexStringToBytes( "0380" // Required Insert Count 2 and Delta Base 0 with sign bit set. // Base is 2 - 0 - 1 = 1 - "10")); // Indexed Header Field instruction addressing dynamic table - // entry with post-base index 0, absolute index 1. Such entry - // does not exist. - - EXPECT_CALL(handler_, OnDecodingErrorDetected( - QUIC_QPACK_DECOMPRESSION_FAILED, - Eq("Dynamic table entry already evicted."))); - - DecodeHeaderBlock(absl::HexStringToBytes( - "0380" // Required Insert Count 2 and Delta Base 0 with sign bit set. - // Base is 2 - 0 - 1 = 1 - "0000")); // Literal Header Field With Name Reference instruction - // addressing dynamic table entry with post-base index 0, - // absolute index 1. Such entry does not exist. + "0000", // Literal Header Field With Name Reference instruction + // addressing dynamic table entry with post-base index 0, + // absolute index 1. Such entry does not exist. + &input)); + DecodeHeaderBlock(input); } TEST_P(QpackDecoderTest, TableCapacityMustNotExceedMaximum) { @@ -660,12 +764,16 @@ Eq("Error updating dynamic table capacity."))); // Try to update dynamic table capacity to 2048, which exceeds the maximum. - DecodeEncoderStreamData(absl::HexStringToBytes("3fe10f")); + std::string input; + ASSERT_TRUE(absl::HexStringToBytes("3fe10f", &input)); + DecodeEncoderStreamData(input); } TEST_P(QpackDecoderTest, SetDynamicTableCapacity) { // Update dynamic table capacity to 128, which does not exceed the maximum. - DecodeEncoderStreamData(absl::HexStringToBytes("3f61")); + std::string input; + ASSERT_TRUE(absl::HexStringToBytes("3f61", &input)); + DecodeEncoderStreamData(input); } TEST_P(QpackDecoderTest, InvalidEncodedRequiredInsertCount) { @@ -676,7 +784,9 @@ EXPECT_CALL(handler_, OnDecodingErrorDetected( QUIC_QPACK_DECOMPRESSION_FAILED, Eq("Error decoding Required Insert Count."))); - DecodeHeaderBlock(absl::HexStringToBytes("4100")); + std::string input; + ASSERT_TRUE(absl::HexStringToBytes("4100", &input)); + DecodeHeaderBlock(input); } // Regression test for https://crbug.com/970218: Decoder must stop processing @@ -686,20 +796,27 @@ QUIC_QPACK_DECOMPRESSION_FAILED, Eq("Error decoding Required Insert Count."))); // Header Block Prefix followed by some extra data. - DecodeHeaderBlock(absl::HexStringToBytes("410000")); + std::string input; + ASSERT_TRUE(absl::HexStringToBytes("410000", &input)); + DecodeHeaderBlock(input); } TEST_P(QpackDecoderTest, WrappedRequiredInsertCount) { + std::string input; // Maximum dynamic table capacity is 1024. // MaxEntries is 1024 / 32 = 32. // Set dynamic table capacity to 1024. - DecodeEncoderStreamData(absl::HexStringToBytes("3fe107")); + ASSERT_TRUE(absl::HexStringToBytes("3fe107", &input)); + DecodeEncoderStreamData(input); // Add literal entry with name "foo" and a 600 byte long value. This will fit // in the dynamic table once but not twice. - DecodeEncoderStreamData( - absl::HexStringToBytes("6294e7" // Name "foo". - "7fd903")); // Value length 600. + ASSERT_TRUE( + absl::HexStringToBytes("6294e7" // Name "foo". + "7fd903", // Value length 600. + &input)); + DecodeEncoderStreamData(input); + std::string header_value(600, 'Z'); DecodeEncoderStreamData(header_value); @@ -714,36 +831,46 @@ WriteStreamData(Eq(kHeaderAcknowledgement))); // Send header block with Required Insert Count = 201. - DecodeHeaderBlock(absl::HexStringToBytes( - "0a00" // Encoded Required Insert Count 10, Required Insert Count 201, - // Delta Base 0, Base 201. - "80")); // Emit dynamic table entry with relative index 0. + ASSERT_TRUE(absl::HexStringToBytes( + "0a00" // Encoded Required Insert Count 10, Required Insert Count 201, + // Delta Base 0, Base 201. + "80", // Emit dynamic table entry with relative index 0. + &input)); + DecodeHeaderBlock(input); if (GetQuicRestartFlag(quic_opport_bundle_qpack_decoder_data3)) { FlushDecoderStream(); } } TEST_P(QpackDecoderTest, NonZeroRequiredInsertCountButNoDynamicEntries) { + std::string input; // Set dynamic table capacity to 1024. - DecodeEncoderStreamData(absl::HexStringToBytes("3fe107")); + ASSERT_TRUE(absl::HexStringToBytes("3fe107", &input)); + DecodeEncoderStreamData(input); // Add literal entry with name "foo" and value "bar". - DecodeEncoderStreamData(absl::HexStringToBytes("6294e703626172")); + ASSERT_TRUE(absl::HexStringToBytes("6294e703626172", &input)); + DecodeEncoderStreamData(input); EXPECT_CALL(handler_, OnHeaderDecoded(Eq(":method"), Eq("GET"))); EXPECT_CALL(handler_, OnDecodingErrorDetected(QUIC_QPACK_DECOMPRESSION_FAILED, Eq("Required Insert Count too large."))); - DecodeHeaderBlock(absl::HexStringToBytes( - "0200" // Required Insert Count is 1. - "d1")); // But the only instruction references the static table. + ASSERT_TRUE(absl::HexStringToBytes( + "0200" // Required Insert Count is 1. + "d1", // But the only instruction references the static table. + &input)); + DecodeHeaderBlock(input); } TEST_P(QpackDecoderTest, AddressEntryNotAllowedByRequiredInsertCount) { + std::string input; // Set dynamic table capacity to 1024. - DecodeEncoderStreamData(absl::HexStringToBytes("3fe107")); + ASSERT_TRUE(absl::HexStringToBytes("3fe107", &input)); + DecodeEncoderStreamData(input); // Add literal entry with name "foo" and value "bar". - DecodeEncoderStreamData(absl::HexStringToBytes("6294e703626172")); + ASSERT_TRUE(absl::HexStringToBytes("6294e703626172", &input)); + DecodeEncoderStreamData(input); EXPECT_CALL( handler_, @@ -751,12 +878,30 @@ QUIC_QPACK_DECOMPRESSION_FAILED, Eq("Absolute Index must be smaller than Required Insert Count."))); - DecodeHeaderBlock(absl::HexStringToBytes( + ASSERT_TRUE(absl::HexStringToBytes( + "0201" // Required Insert Count 1 and Delta Base 1. + // Base is 1 + 1 = 2. + "80", // Indexed Header Field instruction addressing dynamic table + // entry with relative index 0, absolute index 1. This is not + // allowed by Required Insert Count. + &input)); + DecodeHeaderBlock(input); + + EXPECT_CALL( + handler_, + OnDecodingErrorDetected( + QUIC_QPACK_DECOMPRESSION_FAILED, + Eq("Absolute Index must be smaller than Required Insert Count."))); + + ASSERT_TRUE(absl::HexStringToBytes( "0201" // Required Insert Count 1 and Delta Base 1. // Base is 1 + 1 = 2. - "80")); // Indexed Header Field instruction addressing dynamic table - // entry with relative index 0, absolute index 1. This is not - // allowed by Required Insert Count. + "4000", // Literal Header Field with Name Reference instruction + // addressing dynamic table entry with relative index 0, + // absolute index 1. This is not allowed by Required Index + // Count. + &input)); + DecodeHeaderBlock(input); EXPECT_CALL( handler_, @@ -764,13 +909,15 @@ QUIC_QPACK_DECOMPRESSION_FAILED, Eq("Absolute Index must be smaller than Required Insert Count."))); - DecodeHeaderBlock(absl::HexStringToBytes( - "0201" // Required Insert Count 1 and Delta Base 1. - // Base is 1 + 1 = 2. - "4000")); // Literal Header Field with Name Reference instruction - // addressing dynamic table entry with relative index 0, - // absolute index 1. This is not allowed by Required Index - // Count. + ASSERT_TRUE(absl::HexStringToBytes( + "0200" // Required Insert Count 1 and Delta Base 0. + // Base is 1 + 0 = 1. + "10", // Indexed Header Field with Post-Base Index instruction + // addressing dynamic table entry with post-base index 0, + // absolute index 1. This is not allowed by Required Insert + // Count. + &input)); + DecodeHeaderBlock(input); EXPECT_CALL( handler_, @@ -778,98 +925,101 @@ QUIC_QPACK_DECOMPRESSION_FAILED, Eq("Absolute Index must be smaller than Required Insert Count."))); - DecodeHeaderBlock(absl::HexStringToBytes( + ASSERT_TRUE(absl::HexStringToBytes( "0200" // Required Insert Count 1 and Delta Base 0. // Base is 1 + 0 = 1. - "10")); // Indexed Header Field with Post-Base Index instruction - // addressing dynamic table entry with post-base index 0, - // absolute index 1. This is not allowed by Required Insert - // Count. - - EXPECT_CALL( - handler_, - OnDecodingErrorDetected( - QUIC_QPACK_DECOMPRESSION_FAILED, - Eq("Absolute Index must be smaller than Required Insert Count."))); - - DecodeHeaderBlock(absl::HexStringToBytes( - "0200" // Required Insert Count 1 and Delta Base 0. - // Base is 1 + 0 = 1. - "0000")); // Literal Header Field with Post-Base Name Reference - // instruction addressing dynamic table entry with post-base - // index 0, absolute index 1. This is not allowed by Required - // Index Count. + "0000", // Literal Header Field with Post-Base Name Reference + // instruction addressing dynamic table entry with post-base + // index 0, absolute index 1. This is not allowed by Required + // Index Count. + &input)); + DecodeHeaderBlock(input); } TEST_P(QpackDecoderTest, PromisedRequiredInsertCountLargerThanActual) { + std::string input; // Set dynamic table capacity to 1024. - DecodeEncoderStreamData(absl::HexStringToBytes("3fe107")); + ASSERT_TRUE(absl::HexStringToBytes("3fe107", &input)); + DecodeEncoderStreamData(input); // Add literal entry with name "foo" and value "bar". - DecodeEncoderStreamData(absl::HexStringToBytes("6294e703626172")); + ASSERT_TRUE(absl::HexStringToBytes("6294e703626172", &input)); + DecodeEncoderStreamData(input); // Duplicate entry twice so that decoding of header blocks with Required // Insert Count not exceeding 3 is not blocked. - DecodeEncoderStreamData(absl::HexStringToBytes("00")); - DecodeEncoderStreamData(absl::HexStringToBytes("00")); + ASSERT_TRUE(absl::HexStringToBytes("00", &input)); + DecodeEncoderStreamData(input); + DecodeEncoderStreamData(input); EXPECT_CALL(handler_, OnHeaderDecoded(Eq("foo"), Eq("bar"))); EXPECT_CALL(handler_, OnDecodingErrorDetected(QUIC_QPACK_DECOMPRESSION_FAILED, Eq("Required Insert Count too large."))); - DecodeHeaderBlock(absl::HexStringToBytes( + ASSERT_TRUE(absl::HexStringToBytes( + "0300" // Required Insert Count 2 and Delta Base 0. + // Base is 2 + 0 = 2. + "81", // Indexed Header Field instruction addressing dynamic table + // entry with relative index 1, absolute index 0. Header block + // requires insert count of 1, even though Required Insert Count + // is 2. + &input)); + DecodeHeaderBlock(input); + + EXPECT_CALL(handler_, OnHeaderDecoded(Eq("foo"), Eq(""))); + EXPECT_CALL(handler_, + OnDecodingErrorDetected(QUIC_QPACK_DECOMPRESSION_FAILED, + Eq("Required Insert Count too large."))); + + ASSERT_TRUE(absl::HexStringToBytes( "0300" // Required Insert Count 2 and Delta Base 0. // Base is 2 + 0 = 2. - "81")); // Indexed Header Field instruction addressing dynamic table - // entry with relative index 1, absolute index 0. Header block - // requires insert count of 1, even though Required Insert Count - // is 2. - - EXPECT_CALL(handler_, OnHeaderDecoded(Eq("foo"), Eq(""))); - EXPECT_CALL(handler_, - OnDecodingErrorDetected(QUIC_QPACK_DECOMPRESSION_FAILED, - Eq("Required Insert Count too large."))); - - DecodeHeaderBlock(absl::HexStringToBytes( - "0300" // Required Insert Count 2 and Delta Base 0. - // Base is 2 + 0 = 2. - "4100")); // Literal Header Field with Name Reference instruction - // addressing dynamic table entry with relative index 1, - // absolute index 0. Header block requires insert count of 1, - // even though Required Insert Count is 2. + "4100", // Literal Header Field with Name Reference instruction + // addressing dynamic table entry with relative index 1, + // absolute index 0. Header block requires insert count of 1, + // even though Required Insert Count is 2. + &input)); + DecodeHeaderBlock(input); EXPECT_CALL(handler_, OnHeaderDecoded(Eq("foo"), Eq("bar"))); EXPECT_CALL(handler_, OnDecodingErrorDetected(QUIC_QPACK_DECOMPRESSION_FAILED, Eq("Required Insert Count too large."))); - DecodeHeaderBlock(absl::HexStringToBytes( - "0481" // Required Insert Count 3 and Delta Base 1 with sign bit set. - // Base is 3 - 1 - 1 = 1. - "10")); // Indexed Header Field with Post-Base Index instruction - // addressing dynamic table entry with post-base index 0, - // absolute index 1. Header block requires insert count of 2, - // even though Required Insert Count is 3. + ASSERT_TRUE(absl::HexStringToBytes( + "0481" // Required Insert Count 3 and Delta Base 1 with sign bit set. + // Base is 3 - 1 - 1 = 1. + "10", // Indexed Header Field with Post-Base Index instruction + // addressing dynamic table entry with post-base index 0, + // absolute index 1. Header block requires insert count of 2, + // even though Required Insert Count is 3. + &input)); + DecodeHeaderBlock(input); EXPECT_CALL(handler_, OnHeaderDecoded(Eq("foo"), Eq(""))); EXPECT_CALL(handler_, OnDecodingErrorDetected(QUIC_QPACK_DECOMPRESSION_FAILED, Eq("Required Insert Count too large."))); - DecodeHeaderBlock(absl::HexStringToBytes( - "0481" // Required Insert Count 3 and Delta Base 1 with sign bit set. - // Base is 3 - 1 - 1 = 1. - "0000")); // Literal Header Field with Post-Base Name Reference - // instruction addressing dynamic table entry with post-base - // index 0, absolute index 1. Header block requires insert - // count of 2, even though Required Insert Count is 3. + ASSERT_TRUE(absl::HexStringToBytes( + "0481" // Required Insert Count 3 and Delta Base 1 with sign bit set. + // Base is 3 - 1 - 1 = 1. + "0000", // Literal Header Field with Post-Base Name Reference + // instruction addressing dynamic table entry with post-base + // index 0, absolute index 1. Header block requires insert + // count of 2, even though Required Insert Count is 3. + &input)); + DecodeHeaderBlock(input); } TEST_P(QpackDecoderTest, BlockedDecoding) { - DecodeHeaderBlock(absl::HexStringToBytes( - "0200" // Required Insert Count 1 and Delta Base 0. - // Base is 1 + 0 = 1. - "80")); // Indexed Header Field instruction addressing dynamic table - // entry with relative index 0, absolute index 0. + std::string input; + ASSERT_TRUE(absl::HexStringToBytes( + "0200" // Required Insert Count 1 and Delta Base 0. + // Base is 1 + 0 = 1. + "80", // Indexed Header Field instruction addressing dynamic table + // entry with relative index 0, absolute index 0. + &input)); + DecodeHeaderBlock(input); EXPECT_CALL(handler_, OnHeaderDecoded(Eq("foo"), Eq("bar"))); EXPECT_CALL(handler_, OnDecodingCompleted()); @@ -877,25 +1027,31 @@ WriteStreamData(Eq(kHeaderAcknowledgement))); // Set dynamic table capacity to 1024. - DecodeEncoderStreamData(absl::HexStringToBytes("3fe107")); + ASSERT_TRUE(absl::HexStringToBytes("3fe107", &input)); + DecodeEncoderStreamData(input); // Add literal entry with name "foo" and value "bar". - DecodeEncoderStreamData(absl::HexStringToBytes("6294e703626172")); + ASSERT_TRUE(absl::HexStringToBytes("6294e703626172", &input)); + DecodeEncoderStreamData(input); if (GetQuicRestartFlag(quic_opport_bundle_qpack_decoder_data3)) { FlushDecoderStream(); } } TEST_P(QpackDecoderTest, BlockedDecodingUnblockedBeforeEndOfHeaderBlock) { + std::string input; StartDecoding(); - DecodeData(absl::HexStringToBytes( - "0200" // Required Insert Count 1 and Delta Base 0. - // Base is 1 + 0 = 1. - "80" // Indexed Header Field instruction addressing dynamic table - // entry with relative index 0, absolute index 0. - "d1")); // Static table entry with index 17. + ASSERT_TRUE(absl::HexStringToBytes( + "0200" // Required Insert Count 1 and Delta Base 0. + // Base is 1 + 0 = 1. + "80" // Indexed Header Field instruction addressing dynamic table + // entry with relative index 0, absolute index 0. + "d1", // Static table entry with index 17. + &input)); + DecodeData(input); // Set dynamic table capacity to 1024. - DecodeEncoderStreamData(absl::HexStringToBytes("3fe107")); + ASSERT_TRUE(absl::HexStringToBytes("3fe107", &input)); + DecodeEncoderStreamData(input); // Add literal entry with name "foo" and value "bar". Decoding is now // unblocked because dynamic table Insert Count reached the Required Insert @@ -903,17 +1059,20 @@ // the already consumed part of the header block. EXPECT_CALL(handler_, OnHeaderDecoded(Eq("foo"), Eq("bar"))); EXPECT_CALL(handler_, OnHeaderDecoded(Eq(":method"), Eq("GET"))); - DecodeEncoderStreamData(absl::HexStringToBytes("6294e703626172")); + ASSERT_TRUE(absl::HexStringToBytes("6294e703626172", &input)); + DecodeEncoderStreamData(input); Mock::VerifyAndClearExpectations(&handler_); // Rest of header block is processed by QpackProgressiveDecoder // in the unblocked state. EXPECT_CALL(handler_, OnHeaderDecoded(Eq("foo"), Eq("bar"))); EXPECT_CALL(handler_, OnHeaderDecoded(Eq(":scheme"), Eq("https"))); - DecodeData(absl::HexStringToBytes( - "80" // Indexed Header Field instruction addressing dynamic table - // entry with relative index 0, absolute index 0. - "d7")); // Static table entry with index 23. + ASSERT_TRUE(absl::HexStringToBytes( + "80" // Indexed Header Field instruction addressing dynamic table + // entry with relative index 0, absolute index 0. + "d7", // Static table entry with index 23. + &input)); + DecodeData(input); Mock::VerifyAndClearExpectations(&handler_); EXPECT_CALL(handler_, OnDecodingCompleted()); @@ -928,16 +1087,20 @@ // Regression test for https://crbug.com/1024263. TEST_P(QpackDecoderTest, BlockedDecodingUnblockedAndErrorBeforeEndOfHeaderBlock) { + std::string input; StartDecoding(); - DecodeData(absl::HexStringToBytes( - "0200" // Required Insert Count 1 and Delta Base 0. - // Base is 1 + 0 = 1. - "80" // Indexed Header Field instruction addressing dynamic table - // entry with relative index 0, absolute index 0. - "81")); // Relative index 1 is equal to Base, therefore invalid. + ASSERT_TRUE(absl::HexStringToBytes( + "0200" // Required Insert Count 1 and Delta Base 0. + // Base is 1 + 0 = 1. + "80" // Indexed Header Field instruction addressing dynamic table + // entry with relative index 0, absolute index 0. + "81", // Relative index 1 is equal to Base, therefore invalid. + &input)); + DecodeData(input); // Set dynamic table capacity to 1024. - DecodeEncoderStreamData(absl::HexStringToBytes("3fe107")); + ASSERT_TRUE(absl::HexStringToBytes("3fe107", &input)); + DecodeEncoderStreamData(input); // Add literal entry with name "foo" and value "bar". Decoding is now // unblocked because dynamic table Insert Count reached the Required Insert @@ -946,27 +1109,34 @@ EXPECT_CALL(handler_, OnHeaderDecoded(Eq("foo"), Eq("bar"))); EXPECT_CALL(handler_, OnDecodingErrorDetected(QUIC_QPACK_DECOMPRESSION_FAILED, Eq("Invalid relative index."))); - DecodeEncoderStreamData(absl::HexStringToBytes("6294e703626172")); + ASSERT_TRUE(absl::HexStringToBytes("6294e703626172", &input)); + DecodeEncoderStreamData(input); } // Make sure that Required Insert Count is compared to Insert Count, // not size of dynamic table. TEST_P(QpackDecoderTest, BlockedDecodingAndEvictedEntries) { + std::string input; // Update dynamic table capacity to 128. // At most three non-empty entries fit in the dynamic table. - DecodeEncoderStreamData(absl::HexStringToBytes("3f61")); + ASSERT_TRUE(absl::HexStringToBytes("3f61", &input)); + DecodeEncoderStreamData(input); - DecodeHeaderBlock(absl::HexStringToBytes( - "0700" // Required Insert Count 6 and Delta Base 0. - // Base is 6 + 0 = 6. - "80")); // Indexed Header Field instruction addressing dynamic table - // entry with relative index 0, absolute index 5. + ASSERT_TRUE(absl::HexStringToBytes( + "0700" // Required Insert Count 6 and Delta Base 0. + // Base is 6 + 0 = 6. + "80", // Indexed Header Field instruction addressing dynamic table + // entry with relative index 0, absolute index 5. + &input)); + DecodeHeaderBlock(input); // Add literal entry with name "foo" and value "bar". - DecodeEncoderStreamData(absl::HexStringToBytes("6294e703626172")); + ASSERT_TRUE(absl::HexStringToBytes("6294e703626172", &input)); + DecodeEncoderStreamData(input); // Duplicate entry four times. This evicts the first two instances. - DecodeEncoderStreamData(absl::HexStringToBytes("00000000")); + ASSERT_TRUE(absl::HexStringToBytes("00000000", &input)); + DecodeEncoderStreamData(input); EXPECT_CALL(handler_, OnHeaderDecoded(Eq("foo"), Eq("baz"))); EXPECT_CALL(handler_, OnDecodingCompleted()); @@ -975,7 +1145,8 @@ // Add literal entry with name "foo" and value "bar". // Insert Count is now 6, reaching Required Insert Count of the header block. - DecodeEncoderStreamData(absl::HexStringToBytes("6294e70362617a")); + ASSERT_TRUE(absl::HexStringToBytes("6294e70362617a", &input)); + DecodeEncoderStreamData(input); if (GetQuicRestartFlag(quic_opport_bundle_qpack_decoder_data3)) { FlushDecoderStream(); } @@ -984,7 +1155,8 @@ TEST_P(QpackDecoderTest, TooManyBlockedStreams) { // Required Insert Count 1 and Delta Base 0. // Without any dynamic table entries received, decoding is blocked. - std::string data = absl::HexStringToBytes("0200"); + std::string data; + ASSERT_TRUE(absl::HexStringToBytes("0200", &data)); auto progressive_decoder1 = CreateProgressiveDecoder(/* stream_id = */ 1); progressive_decoder1->Decode(data); @@ -999,10 +1171,13 @@ } TEST_P(QpackDecoderTest, InsertCountIncrement) { - DecodeEncoderStreamData(absl::HexStringToBytes( + std::string input; + ASSERT_TRUE(absl::HexStringToBytes( "3fe107" // Set dynamic table capacity to 1024. "6294e703626172" // Add literal entry with name "foo" and value "bar". - "00")); // Duplicate entry. + "00", // Duplicate entry. + &input)); + DecodeEncoderStreamData(input); EXPECT_CALL(handler_, OnHeaderDecoded(Eq("foo"), Eq("bar"))); EXPECT_CALL(handler_, OnDecodingCompleted()); @@ -1010,15 +1185,20 @@ // Decoder received two insertions, but Header Acknowledgement only increases // Known Insert Count to one. Decoder should send an Insert Count Increment // instruction with increment of one to update Known Insert Count to two. + std::string expected_data; + ASSERT_TRUE(absl::HexStringToBytes( + "81" // Header Acknowledgement on stream 1 + "01", // Insert Count Increment with increment of one + &expected_data)); EXPECT_CALL(decoder_stream_sender_delegate_, - WriteStreamData(Eq(absl::HexStringToBytes( - "81" // Header Acknowledgement on stream 1 - "01")))); // Insert Count Increment with increment of one + WriteStreamData(Eq(expected_data))); - DecodeHeaderBlock(absl::HexStringToBytes( - "0200" // Required Insert Count 1 and Delta Base 0. - // Base is 1 + 0 = 1. - "80")); // Dynamic table entry with relative index 0, absolute index 0. + ASSERT_TRUE(absl::HexStringToBytes( + "0200" // Required Insert Count 1 and Delta Base 0. + // Base is 1 + 0 = 1. + "80", // Dynamic table entry with relative index 0, absolute index 0. + &input)); + DecodeHeaderBlock(input); if (GetQuicRestartFlag(quic_opport_bundle_qpack_decoder_data3)) { FlushDecoderStream(); }
diff --git a/quiche/quic/core/qpack/qpack_encoder_stream_receiver_test.cc b/quiche/quic/core/qpack/qpack_encoder_stream_receiver_test.cc index 5ab7042..401281f 100644 --- a/quiche/quic/core/qpack/qpack_encoder_stream_receiver_test.cc +++ b/quiche/quic/core/qpack/qpack_encoder_stream_receiver_test.cc
@@ -56,14 +56,17 @@ EXPECT_CALL(*delegate(), OnInsertWithNameReference(false, 42, Eq(std::string(127, 'Z')))); - Decode(absl::HexStringToBytes( + std::string encoded_data; + ASSERT_TRUE(absl::HexStringToBytes( "c500" "c28294e7" "bf4a03626172" "aa7f005a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a" "5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a" "5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a" - "5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a")); + "5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a", + &encoded_data)); + Decode(encoded_data); } TEST_F(QpackEncoderStreamReceiverTest, InsertWithNameReferenceIndexTooLarge) { @@ -71,7 +74,10 @@ OnErrorDetected(QUIC_QPACK_ENCODER_STREAM_INTEGER_TOO_LARGE, Eq("Encoded integer too large."))); - Decode(absl::HexStringToBytes("bfffffffffffffffffffffff")); + std::string encoded_data; + ASSERT_TRUE( + absl::HexStringToBytes("bfffffffffffffffffffffff", &encoded_data)); + Decode(encoded_data); } TEST_F(QpackEncoderStreamReceiverTest, InsertWithNameReferenceValueTooLong) { @@ -79,7 +85,10 @@ OnErrorDetected(QUIC_QPACK_ENCODER_STREAM_INTEGER_TOO_LARGE, Eq("Encoded integer too large."))); - Decode(absl::HexStringToBytes("c57fffffffffffffffffffff")); + std::string encoded_data; + ASSERT_TRUE( + absl::HexStringToBytes("c57fffffffffffffffffffff", &encoded_data)); + Decode(encoded_data); } TEST_F(QpackEncoderStreamReceiverTest, InsertWithoutNameReference) { @@ -95,7 +104,8 @@ OnInsertWithoutNameReference(Eq(std::string(31, 'Z')), Eq(std::string(127, 'Z')))); - Decode(absl::HexStringToBytes( + std::string encoded_data; + ASSERT_TRUE(absl::HexStringToBytes( "4000" "4362617203626172" "6294e78294e7" @@ -103,7 +113,9 @@ "5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a" "5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a" "5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a" - "5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a")); + "5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a", + &encoded_data)); + Decode(encoded_data); } // Name Length value is too large for varint decoder to decode. @@ -113,7 +125,9 @@ OnErrorDetected(QUIC_QPACK_ENCODER_STREAM_INTEGER_TOO_LARGE, Eq("Encoded integer too large."))); - Decode(absl::HexStringToBytes("5fffffffffffffffffffff")); + std::string encoded_data; + ASSERT_TRUE(absl::HexStringToBytes("5fffffffffffffffffffff", &encoded_data)); + Decode(encoded_data); } // Name Length value can be decoded by varint decoder but exceeds 1 MB limit. @@ -123,7 +137,9 @@ OnErrorDetected(QUIC_QPACK_ENCODER_STREAM_STRING_LITERAL_TOO_LONG, Eq("String literal too long."))); - Decode(absl::HexStringToBytes("5fffff7f")); + std::string encoded_data; + ASSERT_TRUE(absl::HexStringToBytes("5fffff7f", &encoded_data)); + Decode(encoded_data); } // Value Length value is too large for varint decoder to decode. @@ -133,7 +149,10 @@ OnErrorDetected(QUIC_QPACK_ENCODER_STREAM_INTEGER_TOO_LARGE, Eq("Encoded integer too large."))); - Decode(absl::HexStringToBytes("436261727fffffffffffffffffffff")); + std::string encoded_data; + ASSERT_TRUE( + absl::HexStringToBytes("436261727fffffffffffffffffffff", &encoded_data)); + Decode(encoded_data); } // Value Length value can be decoded by varint decoder but exceeds 1 MB limit. @@ -143,7 +162,9 @@ OnErrorDetected(QUIC_QPACK_ENCODER_STREAM_STRING_LITERAL_TOO_LONG, Eq("String literal too long."))); - Decode(absl::HexStringToBytes("436261727fffff7f")); + std::string encoded_data; + ASSERT_TRUE(absl::HexStringToBytes("436261727fffff7f", &encoded_data)); + Decode(encoded_data); } TEST_F(QpackEncoderStreamReceiverTest, Duplicate) { @@ -152,7 +173,9 @@ // Large index requires two extension bytes. EXPECT_CALL(*delegate(), OnDuplicate(500)); - Decode(absl::HexStringToBytes("111fd503")); + std::string encoded_data; + ASSERT_TRUE(absl::HexStringToBytes("111fd503", &encoded_data)); + Decode(encoded_data); } TEST_F(QpackEncoderStreamReceiverTest, DuplicateIndexTooLarge) { @@ -160,7 +183,9 @@ OnErrorDetected(QUIC_QPACK_ENCODER_STREAM_INTEGER_TOO_LARGE, Eq("Encoded integer too large."))); - Decode(absl::HexStringToBytes("1fffffffffffffffffffff")); + std::string encoded_data; + ASSERT_TRUE(absl::HexStringToBytes("1fffffffffffffffffffff", &encoded_data)); + Decode(encoded_data); } TEST_F(QpackEncoderStreamReceiverTest, SetDynamicTableCapacity) { @@ -169,7 +194,9 @@ // Large capacity requires two extension bytes. EXPECT_CALL(*delegate(), OnSetDynamicTableCapacity(500)); - Decode(absl::HexStringToBytes("313fd503")); + std::string encoded_data; + ASSERT_TRUE(absl::HexStringToBytes("313fd503", &encoded_data)); + Decode(encoded_data); } TEST_F(QpackEncoderStreamReceiverTest, SetDynamicTableCapacityTooLarge) { @@ -177,7 +204,9 @@ OnErrorDetected(QUIC_QPACK_ENCODER_STREAM_INTEGER_TOO_LARGE, Eq("Encoded integer too large."))); - Decode(absl::HexStringToBytes("3fffffffffffffffffffff")); + std::string encoded_data; + ASSERT_TRUE(absl::HexStringToBytes("3fffffffffffffffffffff", &encoded_data)); + Decode(encoded_data); } TEST_F(QpackEncoderStreamReceiverTest, InvalidHuffmanEncoding) { @@ -185,7 +214,9 @@ OnErrorDetected(QUIC_QPACK_ENCODER_STREAM_HUFFMAN_ENCODING_ERROR, Eq("Error in Huffman-encoded string."))); - Decode(absl::HexStringToBytes("c281ff")); + std::string encoded_data; + ASSERT_TRUE(absl::HexStringToBytes("c281ff", &encoded_data)); + Decode(encoded_data); } } // namespace
diff --git a/quiche/quic/core/qpack/qpack_encoder_stream_sender_test.cc b/quiche/quic/core/qpack/qpack_encoder_stream_sender_test.cc index 6fcf151..823cae8 100644 --- a/quiche/quic/core/qpack/qpack_encoder_stream_sender_test.cc +++ b/quiche/quic/core/qpack/qpack_encoder_stream_sender_test.cc
@@ -4,6 +4,8 @@ #include "quiche/quic/core/qpack/qpack_encoder_stream_sender.h" +#include <string> + #include "absl/strings/escaping.h" #include "quiche/quic/platform/api/quic_test.h" #include "quiche/quic/test_tools/qpack/qpack_test_utils.h" @@ -39,7 +41,8 @@ EXPECT_EQ(0u, stream_.BufferedByteCount()); // Static, index fits in prefix, empty value. - std::string expected_encoded_data = absl::HexStringToBytes("c500"); + std::string expected_encoded_data; + ASSERT_TRUE(absl::HexStringToBytes("c500", &expected_encoded_data)); EXPECT_CALL(delegate_, WriteStreamData(Eq(expected_encoded_data))); stream_.SendInsertWithNameReference(true, 5, ""); EXPECT_EQ(expected_encoded_data.size(), stream_.BufferedByteCount()); @@ -47,10 +50,10 @@ if (DisableHuffmanEncoding()) { // Static, index fits in prefix, not Huffman encoded value. - expected_encoded_data = absl::HexStringToBytes("c203666f6f"); + ASSERT_TRUE(absl::HexStringToBytes("c203666f6f", &expected_encoded_data)); } else { // Static, index fits in prefix, Huffman encoded value. - expected_encoded_data = absl::HexStringToBytes("c28294e7"); + ASSERT_TRUE(absl::HexStringToBytes("c28294e7", &expected_encoded_data)); } EXPECT_CALL(delegate_, WriteStreamData(Eq(expected_encoded_data))); stream_.SendInsertWithNameReference(true, 2, "foo"); @@ -58,7 +61,7 @@ stream_.Flush(); // Not static, index does not fit in prefix, not Huffman encoded value. - expected_encoded_data = absl::HexStringToBytes("bf4a03626172"); + ASSERT_TRUE(absl::HexStringToBytes("bf4a03626172", &expected_encoded_data)); EXPECT_CALL(delegate_, WriteStreamData(Eq(expected_encoded_data))); stream_.SendInsertWithNameReference(false, 137, "bar"); EXPECT_EQ(expected_encoded_data.size(), stream_.BufferedByteCount()); @@ -66,11 +69,12 @@ // Value length does not fit in prefix. // 'Z' would be Huffman encoded to 8 bits, so no Huffman encoding is used. - expected_encoded_data = absl::HexStringToBytes( + ASSERT_TRUE(absl::HexStringToBytes( "aa7f005a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a" "5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a" "5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a" - "5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a"); + "5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a", + &expected_encoded_data)); EXPECT_CALL(delegate_, WriteStreamData(Eq(expected_encoded_data))); stream_.SendInsertWithNameReference(false, 42, std::string(127, 'Z')); EXPECT_EQ(expected_encoded_data.size(), stream_.BufferedByteCount()); @@ -81,7 +85,8 @@ EXPECT_EQ(0u, stream_.BufferedByteCount()); // Empty name and value. - std::string expected_encoded_data = absl::HexStringToBytes("4000"); + std::string expected_encoded_data; + ASSERT_TRUE(absl::HexStringToBytes("4000", &expected_encoded_data)); EXPECT_CALL(delegate_, WriteStreamData(Eq(expected_encoded_data))); stream_.SendInsertWithoutNameReference("", ""); EXPECT_EQ(expected_encoded_data.size(), stream_.BufferedByteCount()); @@ -89,10 +94,11 @@ if (DisableHuffmanEncoding()) { // Not Huffman encoded short strings. - expected_encoded_data = absl::HexStringToBytes("43666f6f03666f6f"); + ASSERT_TRUE( + absl::HexStringToBytes("43666f6f03666f6f", &expected_encoded_data)); } else { // Huffman encoded short strings. - expected_encoded_data = absl::HexStringToBytes("6294e78294e7"); + ASSERT_TRUE(absl::HexStringToBytes("6294e78294e7", &expected_encoded_data)); } EXPECT_CALL(delegate_, WriteStreamData(Eq(expected_encoded_data))); @@ -101,7 +107,8 @@ stream_.Flush(); // Not Huffman encoded short strings. - expected_encoded_data = absl::HexStringToBytes("4362617203626172"); + ASSERT_TRUE( + absl::HexStringToBytes("4362617203626172", &expected_encoded_data)); EXPECT_CALL(delegate_, WriteStreamData(Eq(expected_encoded_data))); stream_.SendInsertWithoutNameReference("bar", "bar"); EXPECT_EQ(expected_encoded_data.size(), stream_.BufferedByteCount()); @@ -109,12 +116,13 @@ // Not Huffman encoded long strings; length does not fit on prefix. // 'Z' would be Huffman encoded to 8 bits, so no Huffman encoding is used. - expected_encoded_data = absl::HexStringToBytes( + ASSERT_TRUE(absl::HexStringToBytes( "5f005a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a7f" "005a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a" "5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a" "5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a" - "5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a"); + "5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a", + &expected_encoded_data)); EXPECT_CALL(delegate_, WriteStreamData(Eq(expected_encoded_data))); stream_.SendInsertWithoutNameReference(std::string(31, 'Z'), std::string(127, 'Z')); @@ -126,14 +134,15 @@ EXPECT_EQ(0u, stream_.BufferedByteCount()); // Small index fits in prefix. - std::string expected_encoded_data = absl::HexStringToBytes("11"); + std::string expected_encoded_data; + ASSERT_TRUE(absl::HexStringToBytes("11", &expected_encoded_data)); EXPECT_CALL(delegate_, WriteStreamData(Eq(expected_encoded_data))); stream_.SendDuplicate(17); EXPECT_EQ(expected_encoded_data.size(), stream_.BufferedByteCount()); stream_.Flush(); // Large index requires two extension bytes. - expected_encoded_data = absl::HexStringToBytes("1fd503"); + ASSERT_TRUE(absl::HexStringToBytes("1fd503", &expected_encoded_data)); EXPECT_CALL(delegate_, WriteStreamData(Eq(expected_encoded_data))); stream_.SendDuplicate(500); EXPECT_EQ(expected_encoded_data.size(), stream_.BufferedByteCount()); @@ -144,7 +153,8 @@ EXPECT_EQ(0u, stream_.BufferedByteCount()); // Small capacity fits in prefix. - std::string expected_encoded_data = absl::HexStringToBytes("31"); + std::string expected_encoded_data; + ASSERT_TRUE(absl::HexStringToBytes("31", &expected_encoded_data)); EXPECT_CALL(delegate_, WriteStreamData(Eq(expected_encoded_data))); stream_.SendSetDynamicTableCapacity(17); EXPECT_EQ(expected_encoded_data.size(), stream_.BufferedByteCount()); @@ -152,7 +162,7 @@ EXPECT_EQ(0u, stream_.BufferedByteCount()); // Large capacity requires two extension bytes. - expected_encoded_data = absl::HexStringToBytes("3fd503"); + ASSERT_TRUE(absl::HexStringToBytes("3fd503", &expected_encoded_data)); EXPECT_CALL(delegate_, WriteStreamData(Eq(expected_encoded_data))); stream_.SendSetDynamicTableCapacity(500); EXPECT_EQ(expected_encoded_data.size(), stream_.BufferedByteCount()); @@ -176,17 +186,19 @@ std::string expected_encoded_data; if (DisableHuffmanEncoding()) { - expected_encoded_data = absl::HexStringToBytes( + ASSERT_TRUE(absl::HexStringToBytes( "c500" // Insert entry with static name reference. "c203666f6f" // Insert entry with static name reference. "43666f6f03666f6f" // Insert literal entry. - "11"); // Duplicate entry. + "11", // Duplicate entry. + &expected_encoded_data)); } else { - expected_encoded_data = absl::HexStringToBytes( + ASSERT_TRUE(absl::HexStringToBytes( "c500" // Insert entry with static name reference. "c28294e7" // Insert entry with static name reference. "6294e78294e7" // Insert literal entry. - "11"); // Duplicate entry. + "11", // Duplicate entry. + &expected_encoded_data)); } EXPECT_CALL(delegate_, WriteStreamData(Eq(expected_encoded_data))); EXPECT_EQ(expected_encoded_data.size(), stream_.BufferedByteCount());
diff --git a/quiche/quic/core/qpack/qpack_encoder_test.cc b/quiche/quic/core/qpack/qpack_encoder_test.cc index d484cbf..5b775cd 100644 --- a/quiche/quic/core/qpack/qpack_encoder_test.cc +++ b/quiche/quic/core/qpack/qpack_encoder_test.cc
@@ -78,7 +78,9 @@ spdy::Http2HeaderBlock header_list; std::string output = Encode(header_list); - EXPECT_EQ(absl::HexStringToBytes("0000"), output); + std::string expected_output; + ASSERT_TRUE(absl::HexStringToBytes("0000", &expected_output)); + EXPECT_EQ(expected_output, output); } TEST_P(QpackEncoderTest, EmptyName) { @@ -88,11 +90,13 @@ header_list[""] = "foo"; std::string output = Encode(header_list); + std::string expected_output; if (DisableHuffmanEncoding()) { - EXPECT_EQ(absl::HexStringToBytes("00002003666f6f"), output); + ASSERT_TRUE(absl::HexStringToBytes("00002003666f6f", &expected_output)); } else { - EXPECT_EQ(absl::HexStringToBytes("0000208294e7"), output); + ASSERT_TRUE(absl::HexStringToBytes("0000208294e7", &expected_output)); } + EXPECT_EQ(expected_output, output); } TEST_P(QpackEncoderTest, EmptyValue) { @@ -102,11 +106,13 @@ header_list["foo"] = ""; std::string output = Encode(header_list); + std::string expected_output; if (DisableHuffmanEncoding()) { - EXPECT_EQ(absl::HexStringToBytes("000023666f6f00"), output); + ASSERT_TRUE(absl::HexStringToBytes("000023666f6f00", &expected_output)); } else { - EXPECT_EQ(absl::HexStringToBytes("00002a94e700"), output); + ASSERT_TRUE(absl::HexStringToBytes("00002a94e700", &expected_output)); } + EXPECT_EQ(expected_output, output); } TEST_P(QpackEncoderTest, EmptyNameAndValue) { @@ -116,7 +122,9 @@ header_list[""] = ""; std::string output = Encode(header_list); - EXPECT_EQ(absl::HexStringToBytes("00002000"), output); + std::string expected_output; + ASSERT_TRUE(absl::HexStringToBytes("00002000", &expected_output)); + EXPECT_EQ(expected_output, output); } TEST_P(QpackEncoderTest, Simple) { @@ -126,11 +134,14 @@ header_list["foo"] = "bar"; std::string output = Encode(header_list); + std::string expected_output; if (DisableHuffmanEncoding()) { - EXPECT_EQ(absl::HexStringToBytes("000023666f6f03626172"), output); + ASSERT_TRUE( + absl::HexStringToBytes("000023666f6f03626172", &expected_output)); } else { - EXPECT_EQ(absl::HexStringToBytes("00002a94e703626172"), output); + ASSERT_TRUE(absl::HexStringToBytes("00002a94e703626172", &expected_output)); } + EXPECT_EQ(expected_output, output); } TEST_P(QpackEncoderTest, Multiple) { @@ -142,17 +153,17 @@ header_list["ZZZZZZZ"] = std::string(127, 'Z'); std::string output = Encode(header_list); - std::string expected; + std::string expected_output_hex; if (DisableHuffmanEncoding()) { - expected = absl::HexStringToBytes( - "0000" // prefix - "23666f6f03626172"); // foo: bar + expected_output_hex = + "0000" // prefix + "23666f6f03626172"; // foo: bar } else { - expected = absl::HexStringToBytes( - "0000" // prefix - "2a94e703626172"); // foo: bar + expected_output_hex = + "0000" // prefix + "2a94e703626172"; // foo: bar } - expected += absl::HexStringToBytes( + expected_output_hex += "27005a5a5a5a5a5a5a" // 7 octet long header name, the smallest number // that does not fit on a 3-bit prefix. "7f005a5a5a5a5a5a5a" // 127 octet long header value, the smallest @@ -160,8 +171,10 @@ "5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a" "5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a" "5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a" - "5a5a5a5a5a5a5a5a5a"); - EXPECT_EQ(expected, output); + "5a5a5a5a5a5a5a5a5a"; + std::string expected_output; + ASSERT_TRUE(absl::HexStringToBytes(expected_output_hex, &expected_output)); + EXPECT_EQ(expected_output, output); } TEST_P(QpackEncoderTest, StaticTable) { @@ -174,7 +187,9 @@ header_list["location"] = ""; std::string output = Encode(header_list); - EXPECT_EQ(absl::HexStringToBytes("0000d1dfcc"), output); + std::string expected_output; + ASSERT_TRUE(absl::HexStringToBytes("0000d1dfcc", &expected_output)); + EXPECT_EQ(expected_output, output); } { spdy::Http2HeaderBlock header_list; @@ -183,14 +198,15 @@ header_list["location"] = "foo"; std::string output = Encode(header_list); + std::string expected_output; if (DisableHuffmanEncoding()) { - EXPECT_EQ( - absl::HexStringToBytes("0000d45f1008636f6d70726573735c03666f6f"), - output); + ASSERT_TRUE(absl::HexStringToBytes( + "0000d45f1008636f6d70726573735c03666f6f", &expected_output)); } else { - EXPECT_EQ(absl::HexStringToBytes("0000d45f108621e9aec2a11f5c8294e7"), - output); + ASSERT_TRUE(absl::HexStringToBytes("0000d45f108621e9aec2a11f5c8294e7", + &expected_output)); } + EXPECT_EQ(expected_output, output); } { spdy::Http2HeaderBlock header_list; @@ -198,7 +214,10 @@ header_list["accept-encoding"] = ""; std::string output = Encode(header_list); - EXPECT_EQ(absl::HexStringToBytes("00005f000554524143455f1000"), output); + std::string expected_output; + ASSERT_TRUE( + absl::HexStringToBytes("00005f000554524143455f1000", &expected_output)); + EXPECT_EQ(expected_output, output); } } @@ -209,8 +228,9 @@ QpackEncoder encoder(&decoder_stream_error_delegate_, HuffmanEncoding()); encoder.set_qpack_stream_sender_delegate(&encoder_stream_sender_delegate_); - encoder.decoder_stream_receiver()->Decode( - absl::HexStringToBytes("ffffffffffffffffffffff")); + std::string input; + ASSERT_TRUE(absl::HexStringToBytes("ffffffffffffffffffffff", &input)); + encoder.decoder_stream_receiver()->Decode(input); } TEST_P(QpackEncoderTest, SplitAlongNullCharacter) { @@ -220,21 +240,23 @@ header_list["foo"] = absl::string_view("bar\0bar\0baz", 11); std::string output = Encode(header_list); + std::string expected_output; if (DisableHuffmanEncoding()) { - EXPECT_EQ(absl::HexStringToBytes("0000" // prefix - "23666f6f03626172" // foo: bar - "23666f6f03626172" // foo: bar - "23666f6f0362617a" // foo: bar - ), - output); + ASSERT_TRUE( + absl::HexStringToBytes("0000" // prefix + "23666f6f03626172" // foo: bar + "23666f6f03626172" // foo: bar + "23666f6f0362617a", // foo: bar + &expected_output)); } else { - EXPECT_EQ(absl::HexStringToBytes("0000" // prefix - "2a94e703626172" // foo: bar - "2a94e703626172" // foo: bar - "2a94e70362617a" // foo: baz - ), - output); + ASSERT_TRUE( + absl::HexStringToBytes("0000" // prefix + "2a94e703626172" // foo: bar + "2a94e703626172" // foo: bar + "2a94e70362617a", // foo: baz + &expected_output)); } + EXPECT_EQ(expected_output, output); } TEST_P(QpackEncoderTest, ZeroInsertCountIncrement) { @@ -306,32 +328,37 @@ header_list["cookie"] = "baz"; // name matches static entry // Set Dynamic Table Capacity instruction. - std::string set_dyanamic_table_capacity = absl::HexStringToBytes("3fe11f"); + std::string set_dyanamic_table_capacity; + ASSERT_TRUE(absl::HexStringToBytes("3fe11f", &set_dyanamic_table_capacity)); // Insert three entries into the dynamic table. - std::string insert_entries; + std::string insert_entries_hex; if (DisableHuffmanEncoding()) { - insert_entries = absl::HexStringToBytes( - "43" // insert without name reference - "666f6f"); // Huffman-encoded name "foo" + insert_entries_hex = + "43" // insert without name reference + "666f6f"; // Huffman-encoded name "foo" } else { - insert_entries = absl::HexStringToBytes( - "62" // insert without name reference - "94e7"); // Huffman-encoded name "foo" + insert_entries_hex = + "62" // insert without name reference + "94e7"; // Huffman-encoded name "foo" } - insert_entries += absl::HexStringToBytes( - "03626172" // value "bar" - "80" // insert with name reference, dynamic index 0 - "0362617a" // value "baz" - "c5" // insert with name reference, static index 5 - "0362617a"); // value "baz" + insert_entries_hex += + "03626172" // value "bar" + "80" // insert with name reference, dynamic index 0 + "0362617a" // value "baz" + "c5" // insert with name reference, static index 5 + "0362617a"; // value "baz" + std::string insert_entries; + ASSERT_TRUE(absl::HexStringToBytes(insert_entries_hex, &insert_entries)); EXPECT_CALL(encoder_stream_sender_delegate_, WriteStreamData(Eq( absl::StrCat(set_dyanamic_table_capacity, insert_entries)))); - EXPECT_EQ(absl::HexStringToBytes( - "0400" // prefix - "828180"), // dynamic entries with relative index 0, 1, and 2 - Encode(header_list)); + std::string expected_output; + ASSERT_TRUE(absl::HexStringToBytes( + "0400" // prefix + "828180", // dynamic entries with relative index 0, 1, and 2 + &expected_output)); + EXPECT_EQ(expected_output, Encode(header_list)); EXPECT_EQ(insert_entries.size(), encoder_stream_sent_byte_count_); } @@ -352,33 +379,39 @@ header_list["bar"] = "baz"; // no match // Set Dynamic Table Capacity instruction. - std::string set_dyanamic_table_capacity = absl::HexStringToBytes("3f07"); + std::string set_dyanamic_table_capacity; + ASSERT_TRUE(absl::HexStringToBytes("3f07", &set_dyanamic_table_capacity)); // Insert one entry into the dynamic table. std::string insert_entry; if (DisableHuffmanEncoding()) { - insert_entry = absl::HexStringToBytes( - "43" // insert without name reference - "666f6f" // Huffman-encoded name "foo" - "03626172"); // value "bar" + ASSERT_TRUE( + absl::HexStringToBytes("43" // insert without name reference + "666f6f" // Huffman-encoded name "foo" + "03626172", // value "bar" + &insert_entry)); } else { - insert_entry = absl::HexStringToBytes( - "62" // insert without name reference - "94e7" // Huffman-encoded name "foo" - "03626172"); // value "bar" + ASSERT_TRUE( + absl::HexStringToBytes("62" // insert without name reference + "94e7" // Huffman-encoded name "foo" + "03626172", // value "bar" + &insert_entry)); } EXPECT_CALL(encoder_stream_sender_delegate_, WriteStreamData( Eq(absl::StrCat(set_dyanamic_table_capacity, insert_entry)))); - EXPECT_EQ(absl::HexStringToBytes("0200" // prefix - "80" // dynamic entry 0 - "40" // reference to dynamic entry 0 name - "0362617a" // with literal value "baz" - "55" // reference to static entry 5 name - "0362617a" // with literal value "baz" - "23626172" // literal name "bar" - "0362617a"), // with literal value "baz" - Encode(header_list)); + std::string expected_output; + ASSERT_TRUE( + absl::HexStringToBytes("0200" // prefix + "80" // dynamic entry 0 + "40" // reference to dynamic entry 0 name + "0362617a" // with literal value "baz" + "55" // reference to static entry 5 name + "0362617a" // with literal value "baz" + "23626172" // literal name "bar" + "0362617a", // with literal value "baz" + &expected_output)); + EXPECT_EQ(expected_output, Encode(header_list)); EXPECT_EQ(insert_entry.size(), encoder_stream_sent_byte_count_); } @@ -394,26 +427,33 @@ header_list1["foo"] = "bar"; // Set Dynamic Table Capacity instruction. - std::string set_dyanamic_table_capacity = absl::HexStringToBytes("3fe11f"); + std::string set_dyanamic_table_capacity; + ASSERT_TRUE(absl::HexStringToBytes("3fe11f", &set_dyanamic_table_capacity)); // Insert one entry into the dynamic table. std::string insert_entry1; if (DisableHuffmanEncoding()) { - insert_entry1 = absl::HexStringToBytes( - "43" // insert without name reference - "666f6f" // Huffman-encoded name "foo" - "03626172"); // value "bar" + ASSERT_TRUE( + absl::HexStringToBytes("43" // insert without name reference + "666f6f" // Huffman-encoded name "foo" + "03626172", // value "bar" + &insert_entry1)); } else { - insert_entry1 = absl::HexStringToBytes( - "62" // insert without name reference - "94e7" // Huffman-encoded name "foo" - "03626172"); // value "bar" + ASSERT_TRUE( + absl::HexStringToBytes("62" // insert without name reference + "94e7" // Huffman-encoded name "foo" + "03626172", // value "bar" + &insert_entry1)); } EXPECT_CALL(encoder_stream_sender_delegate_, WriteStreamData(Eq( absl::StrCat(set_dyanamic_table_capacity, insert_entry1)))); - EXPECT_EQ(absl::HexStringToBytes("0200" // prefix - "80"), // dynamic entry 0 + std::string expected_output; + ASSERT_TRUE( + absl::HexStringToBytes("0200" // prefix + "80", // dynamic entry 0 + &expected_output)); + EXPECT_EQ(expected_output, encoder_.EncodeHeaderList(/* stream_id = */ 1, header_list1, &encoder_stream_sent_byte_count_)); EXPECT_EQ(insert_entry1.size(), encoder_stream_sent_byte_count_); @@ -428,27 +468,29 @@ std::string entries; if (DisableHuffmanEncoding()) { - entries = absl::HexStringToBytes( - "0000" // prefix - "23666f6f" // literal name "foo" - "03626172" // with literal value "bar" - "23666f6f" // literal name "foo" - "0362617a" // with literal value "baz" - "55" // name of static entry 5 - "0362617a" // with literal value "baz" - "23626172" // literal name "bar" - "0362617a"); // with literal value "baz" + ASSERT_TRUE( + absl::HexStringToBytes("0000" // prefix + "23666f6f" // literal name "foo" + "03626172" // with literal value "bar" + "23666f6f" // literal name "foo" + "0362617a" // with literal value "baz" + "55" // name of static entry 5 + "0362617a" // with literal value "baz" + "23626172" // literal name "bar" + "0362617a", // with literal value "baz" + &entries)); } else { - entries = absl::HexStringToBytes( - "0000" // prefix - "2a94e7" // literal name "foo" - "03626172" // with literal value "bar" - "2a94e7" // literal name "foo" - "0362617a" // with literal value "baz" - "55" // name of static entry 5 - "0362617a" // with literal value "baz" - "23626172" // literal name "bar" - "0362617a"); // with literal value "baz" + ASSERT_TRUE( + absl::HexStringToBytes("0000" // prefix + "2a94e7" // literal name "foo" + "03626172" // with literal value "bar" + "2a94e7" // literal name "foo" + "0362617a" // with literal value "baz" + "55" // name of static entry 5 + "0362617a" // with literal value "baz" + "23626172" // literal name "bar" + "0362617a", // with literal value "baz" + &entries)); } EXPECT_EQ(entries, encoder_.EncodeHeaderList(/* stream_id = */ 2, header_list2, @@ -460,19 +502,24 @@ encoder_.OnInsertCountIncrement(1); // Insert three entries into the dynamic table. - std::string insert_entries = absl::HexStringToBytes( - "80" // insert with name reference, dynamic index 0 - "0362617a" // value "baz" - "c5" // insert with name reference, static index 5 - "0362617a" // value "baz" - "43" // insert without name reference - "626172" // name "bar" - "0362617a"); // value "baz" + std::string insert_entries; + ASSERT_TRUE(absl::HexStringToBytes( + "80" // insert with name reference, dynamic index 0 + "0362617a" // value "baz" + "c5" // insert with name reference, static index 5 + "0362617a" // value "baz" + "43" // insert without name reference + "626172" // name "bar" + "0362617a", // value "baz" + &insert_entries)); EXPECT_CALL(encoder_stream_sender_delegate_, WriteStreamData(Eq(insert_entries))); - EXPECT_EQ(absl::HexStringToBytes("0500" // prefix - "83828180"), // dynamic entries + ASSERT_TRUE( + absl::HexStringToBytes("0500" // prefix + "83828180", // dynamic entries + &expected_output)); + EXPECT_EQ(expected_output, encoder_.EncodeHeaderList(/* stream_id = */ 3, header_list2, &encoder_stream_sent_byte_count_)); EXPECT_EQ(insert_entries.size(), encoder_stream_sent_byte_count_); @@ -481,25 +528,27 @@ // reference already acknowledged dynamic entry 0. std::string expected2; if (DisableHuffmanEncoding()) { - expected2 = absl::HexStringToBytes( - "0200" // prefix - "80" // dynamic entry 0 - "23666f6f" // literal name "foo" - "0362617a" // with literal value "baz" - "26636f6f6b6965" // literal name "cookie" - "0362617a" // with literal value "baz" - "23626172" // literal name "bar" - "0362617a"); // with literal value "baz" + ASSERT_TRUE( + absl::HexStringToBytes("0200" // prefix + "80" // dynamic entry 0 + "23666f6f" // literal name "foo" + "0362617a" // with literal value "baz" + "26636f6f6b6965" // literal name "cookie" + "0362617a" // with literal value "baz" + "23626172" // literal name "bar" + "0362617a", // with literal value "baz" + &expected2)); } else { - expected2 = absl::HexStringToBytes( - "0200" // prefix - "80" // dynamic entry 0 - "2a94e7" // literal name "foo" - "0362617a" // with literal value "baz" - "2c21cfd4c5" // literal name "cookie" - "0362617a" // with literal value "baz" - "23626172" // literal name "bar" - "0362617a"); // with literal value "baz" + ASSERT_TRUE( + absl::HexStringToBytes("0200" // prefix + "80" // dynamic entry 0 + "2a94e7" // literal name "foo" + "0362617a" // with literal value "baz" + "2c21cfd4c5" // literal name "cookie" + "0362617a" // with literal value "baz" + "23626172" // literal name "bar" + "0362617a", // with literal value "baz" + &expected2)); } EXPECT_EQ(expected2, encoder_.EncodeHeaderList(/* stream_id = */ 4, header_list2, @@ -512,10 +561,14 @@ // Stream 5 is not allowed to block, but it can reference already acknowledged // dynamic entries 0, 1, and 2. - EXPECT_EQ(absl::HexStringToBytes("0400" // prefix - "828180" // dynamic entries - "23626172" // literal name "bar" - "0362617a"), // with literal value "baz" + std::string expected3; + ASSERT_TRUE( + absl::HexStringToBytes("0400" // prefix + "828180" // dynamic entries + "23626172" // literal name "bar" + "0362617a", // with literal value "baz" + &expected3)); + EXPECT_EQ(expected3, encoder_.EncodeHeaderList(/* stream_id = */ 5, header_list2, &encoder_stream_sent_byte_count_)); EXPECT_EQ(0u, encoder_stream_sent_byte_count_); @@ -524,8 +577,12 @@ // Stream 3 is not blocked any longer. encoder_.OnHeaderAcknowledgement(3); - EXPECT_EQ(absl::HexStringToBytes("0500" // prefix - "83828180"), // dynamic entries + std::string expected4; + ASSERT_TRUE( + absl::HexStringToBytes("0500" // prefix + "83828180", // dynamic entries + &expected4)); + EXPECT_EQ(expected4, encoder_.EncodeHeaderList(/* stream_id = */ 6, header_list2, &encoder_stream_sent_byte_count_)); EXPECT_EQ(0u, encoder_stream_sent_byte_count_); @@ -562,9 +619,12 @@ // dynamic table. EXPECT_CALL(encoder_stream_sender_delegate_, WriteStreamData(_)); - EXPECT_EQ(absl::HexStringToBytes("0b00" // prefix - "89888786858483828180"), // dynamic entries - Encode(header_list1)); + std::string expected_output; + ASSERT_TRUE( + absl::HexStringToBytes("0b00" // prefix + "89888786858483828180", // dynamic entries + &expected_output)); + EXPECT_EQ(expected_output, Encode(header_list1)); // Entry is identical to oldest one, which is draining. It will be // duplicated and referenced. @@ -572,12 +632,15 @@ header_list2["one"] = "foo"; // Duplicate oldest entry. + ASSERT_TRUE(absl::HexStringToBytes("09", &expected_output)); EXPECT_CALL(encoder_stream_sender_delegate_, - WriteStreamData(Eq(absl::HexStringToBytes("09")))); + WriteStreamData(Eq(expected_output))); - EXPECT_EQ(absl::HexStringToBytes("0c00" // prefix - "80"), // most recent dynamic table entry - Encode(header_list2)); + ASSERT_TRUE( + absl::HexStringToBytes("0c00" // prefix + "80", // most recent dynamic table entry + &expected_output)); + EXPECT_EQ(expected_output, Encode(header_list2)); spdy::Http2HeaderBlock header_list3; // Entry is identical to second oldest one, which is draining. There is no @@ -598,7 +661,8 @@ entries += "2374776f" // literal name "two" "03626172"; // literal value "bar" - EXPECT_EQ(absl::HexStringToBytes(entries), Encode(header_list3)); + ASSERT_TRUE(absl::HexStringToBytes(entries, &expected_output)); + EXPECT_EQ(expected_output, Encode(header_list3)); } TEST_P(QpackEncoderTest, DynamicTableCapacityLessThanMaximum) { @@ -629,23 +693,25 @@ // Headers are encoded as string literals. std::string entries; if (DisableHuffmanEncoding()) { - entries = absl::HexStringToBytes( - "0000" // prefix - "23666f6f" // literal name "foo" - "03626172" // with literal value "bar" - "23666f6f" // literal name "foo" - "0362617a" // with literal value "baz" - "55" // name of static entry 5 - "0362617a"); // with literal value "baz" + ASSERT_TRUE( + absl::HexStringToBytes("0000" // prefix + "23666f6f" // literal name "foo" + "03626172" // with literal value "bar" + "23666f6f" // literal name "foo" + "0362617a" // with literal value "baz" + "55" // name of static entry 5 + "0362617a", // with literal value "baz" + &entries)); } else { - entries = absl::HexStringToBytes( - "0000" // prefix - "2a94e7" // literal name "foo" - "03626172" // with literal value "bar" - "2a94e7" // literal name "foo" - "0362617a" // with literal value "baz" - "55" // name of static entry 5 - "0362617a"); // with literal value "baz" + ASSERT_TRUE( + absl::HexStringToBytes("0000" // prefix + "2a94e7" // literal name "foo" + "03626172" // with literal value "bar" + "2a94e7" // literal name "foo" + "0362617a" // with literal value "baz" + "55" // name of static entry 5 + "0362617a", // with literal value "baz" + &entries)); } EXPECT_EQ(entries, Encode(header_list1)); @@ -664,32 +730,37 @@ header_list2["cookie"] = "baz"; // name matches static entry // Set Dynamic Table Capacity instruction. - std::string set_dyanamic_table_capacity = absl::HexStringToBytes("3fe11f"); + std::string set_dyanamic_table_capacity; + ASSERT_TRUE(absl::HexStringToBytes("3fe11f", &set_dyanamic_table_capacity)); // Insert three entries into the dynamic table. - std::string insert_entries; + std::string insert_entries_hex; if (DisableHuffmanEncoding()) { - insert_entries = absl::HexStringToBytes( - "43" // insert without name reference - "666f6f"); // name "foo" + insert_entries_hex = + "43" // insert without name reference + "666f6f"; // name "foo" } else { - insert_entries = absl::HexStringToBytes( - "62" // insert without name reference - "94e7"); // Huffman-encoded name "foo" + insert_entries_hex = + "62" // insert without name reference + "94e7"; // Huffman-encoded name "foo" } - insert_entries += absl::HexStringToBytes( - "03626172" // value "bar" - "80" // insert with name reference, dynamic index 0 - "0362617a" // value "baz" - "c5" // insert with name reference, static index 5 - "0362617a"); // value "baz" + insert_entries_hex += + "03626172" // value "bar" + "80" // insert with name reference, dynamic index 0 + "0362617a" // value "baz" + "c5" // insert with name reference, static index 5 + "0362617a"; // value "baz" + std::string insert_entries; + ASSERT_TRUE(absl::HexStringToBytes(insert_entries_hex, &insert_entries)); EXPECT_CALL(encoder_stream_sender_delegate_, WriteStreamData(Eq( absl::StrCat(set_dyanamic_table_capacity, insert_entries)))); - EXPECT_EQ(absl::HexStringToBytes( - "0400" // prefix - "828180"), // dynamic entries with relative index 0, 1, and 2 - Encode(header_list2)); + std::string expected_output; + ASSERT_TRUE(absl::HexStringToBytes( + "0400" // prefix + "828180", // dynamic entries with relative index 0, 1, and 2 + &expected_output)); + EXPECT_EQ(expected_output, Encode(header_list2)); EXPECT_EQ(insert_entries.size(), encoder_stream_sent_byte_count_); } @@ -708,32 +779,37 @@ header_list1["cookie"] = "baz"; // name matches static entry // Set Dynamic Table Capacity instruction. - std::string set_dyanamic_table_capacity = absl::HexStringToBytes("3fe11f"); + std::string set_dyanamic_table_capacity; + ASSERT_TRUE(absl::HexStringToBytes("3fe11f", &set_dyanamic_table_capacity)); // Insert three entries into the dynamic table. - std::string insert_entries; + std::string insert_entries_hex; if (DisableHuffmanEncoding()) { - insert_entries = absl::HexStringToBytes( - "43" // insert without name reference - "666f6f"); // name "foo" + insert_entries_hex = + "43" // insert without name reference + "666f6f"; // name "foo" } else { - insert_entries = absl::HexStringToBytes( - "62" // insert without name reference - "94e7"); // Huffman-encoded name "foo" + insert_entries_hex = + "62" // insert without name reference + "94e7"; // Huffman-encoded name "foo" } - insert_entries += absl::HexStringToBytes( - "03626172" // value "bar" - "80" // insert with name reference, dynamic index 0 - "0362617a" // value "baz" - "c5" // insert with name reference, static index 5 - "0362617a"); // value "baz" + insert_entries_hex += + "03626172" // value "bar" + "80" // insert with name reference, dynamic index 0 + "0362617a" // value "baz" + "c5" // insert with name reference, static index 5 + "0362617a"; // value "baz" + std::string insert_entries; + ASSERT_TRUE(absl::HexStringToBytes(insert_entries_hex, &insert_entries)); EXPECT_CALL(encoder_stream_sender_delegate_, WriteStreamData(Eq( absl::StrCat(set_dyanamic_table_capacity, insert_entries)))); - EXPECT_EQ(absl::HexStringToBytes( - "0400" // prefix - "828180"), // dynamic entries with relative index 0, 1, and 2 - Encode(header_list1)); + std::string expected_output; + ASSERT_TRUE(absl::HexStringToBytes( + "0400" // prefix + "828180", // dynamic entries with relative index 0, 1, and 2 + &expected_output)); + EXPECT_EQ(expected_output, Encode(header_list1)); EXPECT_EQ(insert_entries.size(), encoder_stream_sent_byte_count_); @@ -751,13 +827,14 @@ // Encoder is not allowed to write on the encoder stream. // No Set Dynamic Table Capacity or Insert instructions are sent. // Headers are encoded as string literals. - EXPECT_EQ( + ASSERT_TRUE( absl::HexStringToBytes("0400" // prefix "82" // dynamic entry with relative index 0 "23626172" // literal name "bar" "0362617a" // with literal value "baz" - "80"), // dynamic entry with relative index 2 - Encode(header_list2)); + "80", // dynamic entry with relative index 2 + &expected_output)); + EXPECT_EQ(expected_output, Encode(header_list2)); EXPECT_EQ(0u, encoder_stream_sent_byte_count_); } @@ -780,29 +857,35 @@ header_list1["foo"] = "bar"; // Set Dynamic Table Capacity instruction. - std::string set_dyanamic_table_capacity = absl::HexStringToBytes("3f09"); + std::string set_dyanamic_table_capacity; + ASSERT_TRUE(absl::HexStringToBytes("3f09", &set_dyanamic_table_capacity)); // Insert one entry into the dynamic table. std::string insert_entries1; if (DisableHuffmanEncoding()) { - insert_entries1 = absl::HexStringToBytes( - "43" // insert without name reference - "666f6f" // Huffman-encoded name "foo" - "03626172"); // value "bar" + ASSERT_TRUE( + absl::HexStringToBytes("43" // insert without name reference + "666f6f" // Huffman-encoded name "foo" + "03626172", // value "bar" + &insert_entries1)); } else { - insert_entries1 = absl::HexStringToBytes( - "62" // insert without name reference - "94e7" // Huffman-encoded name "foo" - "03626172"); // value "bar" + ASSERT_TRUE( + absl::HexStringToBytes("62" // insert without name reference + "94e7" // Huffman-encoded name "foo" + "03626172", // value "bar" + &insert_entries1)); } EXPECT_CALL(encoder_stream_sender_delegate_, WriteStreamData(Eq( absl::StrCat(set_dyanamic_table_capacity, insert_entries1)))); - EXPECT_EQ( + std::string expected_output; + ASSERT_TRUE( absl::HexStringToBytes("0200" // prefix - "80"), // dynamic entry with relative index 0 - encoder_.EncodeHeaderList(/* stream_id = */ 1, header_list1, - &encoder_stream_sent_byte_count_)); + "80", // dynamic entry with relative index 0 + &expected_output)); + EXPECT_EQ(expected_output, + encoder_.EncodeHeaderList(/* stream_id = */ 1, header_list1, + &encoder_stream_sent_byte_count_)); EXPECT_EQ(1u, header_table->inserted_entry_count()); EXPECT_EQ(0u, header_table->dropped_entry_count()); @@ -816,9 +899,12 @@ spdy::Http2HeaderBlock header_list2; header_list2["bar"] = "baz"; - EXPECT_EQ(absl::HexStringToBytes("0000" // prefix - "23626172" // literal name "bar" - "0362617a"), // literal value "baz" + ASSERT_TRUE( + absl::HexStringToBytes("0000" // prefix + "23626172" // literal name "bar" + "0362617a", // literal value "baz" + &expected_output)); + EXPECT_EQ(expected_output, encoder_.EncodeHeaderList(/* stream_id = */ 2, header_list2, &encoder_stream_sent_byte_count_));
diff --git a/quiche/quic/core/qpack/qpack_instruction_decoder_test.cc b/quiche/quic/core/qpack/qpack_instruction_decoder_test.cc index 1a2aa2c..873b3d5 100644 --- a/quiche/quic/core/qpack/qpack_instruction_decoder_test.cc +++ b/quiche/quic/core/qpack/qpack_instruction_decoder_test.cc
@@ -5,6 +5,7 @@ #include "quiche/quic/core/qpack/qpack_instruction_decoder.h" #include <algorithm> +#include <string> #include "absl/strings/escaping.h" #include "absl/strings/string_view.h" @@ -125,15 +126,18 @@ FragmentMode::kOctetByOctet)); TEST_P(QpackInstructionDecoderTest, SBitAndVarint2) { + std::string encoded_data; EXPECT_CALL(delegate_, OnInstructionDecoded(TestInstruction1())); - DecodeInstruction(absl::HexStringToBytes("7f01ff65")); + ASSERT_TRUE(absl::HexStringToBytes("7f01ff65", &encoded_data)); + DecodeInstruction(encoded_data); EXPECT_TRUE(decoder_->s_bit()); EXPECT_EQ(64u, decoder_->varint()); EXPECT_EQ(356u, decoder_->varint2()); EXPECT_CALL(delegate_, OnInstructionDecoded(TestInstruction1())); - DecodeInstruction(absl::HexStringToBytes("05c8")); + ASSERT_TRUE(absl::HexStringToBytes("05c8", &encoded_data)); + DecodeInstruction(encoded_data); EXPECT_FALSE(decoder_->s_bit()); EXPECT_EQ(5u, decoder_->varint()); @@ -141,47 +145,57 @@ } TEST_P(QpackInstructionDecoderTest, NameAndValue) { + std::string encoded_data; EXPECT_CALL(delegate_, OnInstructionDecoded(TestInstruction2())); - DecodeInstruction(absl::HexStringToBytes("83666f6f03626172")); + ASSERT_TRUE(absl::HexStringToBytes("83666f6f03626172", &encoded_data)); + DecodeInstruction(encoded_data); EXPECT_EQ("foo", decoder_->name()); EXPECT_EQ("bar", decoder_->value()); EXPECT_CALL(delegate_, OnInstructionDecoded(TestInstruction2())); - DecodeInstruction(absl::HexStringToBytes("8000")); + ASSERT_TRUE(absl::HexStringToBytes("8000", &encoded_data)); + DecodeInstruction(encoded_data); EXPECT_EQ("", decoder_->name()); EXPECT_EQ("", decoder_->value()); EXPECT_CALL(delegate_, OnInstructionDecoded(TestInstruction2())); - DecodeInstruction(absl::HexStringToBytes("c294e7838c767f")); + ASSERT_TRUE(absl::HexStringToBytes("c294e7838c767f", &encoded_data)); + DecodeInstruction(encoded_data); EXPECT_EQ("foo", decoder_->name()); EXPECT_EQ("bar", decoder_->value()); } TEST_P(QpackInstructionDecoderTest, InvalidHuffmanEncoding) { + std::string encoded_data; EXPECT_CALL(delegate_, OnInstructionDecodingError( QpackInstructionDecoder::ErrorCode::HUFFMAN_ENCODING_ERROR, Eq("Error in Huffman-encoded string."))); - DecodeInstruction(absl::HexStringToBytes("c1ff")); + ASSERT_TRUE(absl::HexStringToBytes("c1ff", &encoded_data)); + DecodeInstruction(encoded_data); } TEST_P(QpackInstructionDecoderTest, InvalidVarintEncoding) { + std::string encoded_data; EXPECT_CALL(delegate_, OnInstructionDecodingError( QpackInstructionDecoder::ErrorCode::INTEGER_TOO_LARGE, Eq("Encoded integer too large."))); - DecodeInstruction(absl::HexStringToBytes("ffffffffffffffffffffff")); + ASSERT_TRUE(absl::HexStringToBytes("ffffffffffffffffffffff", &encoded_data)); + DecodeInstruction(encoded_data); } TEST_P(QpackInstructionDecoderTest, StringLiteralTooLong) { + std::string encoded_data; EXPECT_CALL(delegate_, OnInstructionDecodingError( QpackInstructionDecoder::ErrorCode::STRING_LITERAL_TOO_LONG, Eq("String literal too long."))); - DecodeInstruction(absl::HexStringToBytes("bfffff7f")); + ASSERT_TRUE(absl::HexStringToBytes("bfffff7f", &encoded_data)); + DecodeInstruction(encoded_data); } TEST_P(QpackInstructionDecoderTest, DelegateSignalsError) { @@ -201,8 +215,9 @@ return false; })); - EXPECT_FALSE( - decoder_->Decode(absl::HexStringToBytes("01000200030004000500"))); + std::string encoded_data; + ASSERT_TRUE(absl::HexStringToBytes("01000200030004000500", &encoded_data)); + EXPECT_FALSE(decoder_->Decode(encoded_data)); } // QpackInstructionDecoder must not crash if it is destroyed from a @@ -214,7 +229,9 @@ decoder_.reset(); return false; })); - DecodeInstruction(absl::HexStringToBytes("0100")); + std::string encoded_data; + ASSERT_TRUE(absl::HexStringToBytes("0100", &encoded_data)); + DecodeInstruction(encoded_data); } } // namespace
diff --git a/quiche/quic/core/qpack/qpack_instruction_encoder_test.cc b/quiche/quic/core/qpack/qpack_instruction_encoder_test.cc index 9880d3f..14d8f11 100644 --- a/quiche/quic/core/qpack/qpack_instruction_encoder_test.cc +++ b/quiche/quic/core/qpack/qpack_instruction_encoder_test.cc
@@ -4,6 +4,8 @@ #include "quiche/quic/core/qpack/qpack_instruction_encoder.h" +#include <string> + #include "absl/strings/escaping.h" #include "absl/strings/string_view.h" #include "quiche/quic/platform/api/quic_logging.h" @@ -72,7 +74,9 @@ bool EncodedSegmentMatches(absl::string_view hex_encoded_expected_substring) { auto recently_encoded = absl::string_view(output_).substr(verified_position_); - auto expected = absl::HexStringToBytes(hex_encoded_expected_substring); + std::string expected; + EXPECT_TRUE( + absl::HexStringToBytes(hex_encoded_expected_substring, &expected)); verified_position_ = output_.size(); return recently_encoded == expected; }