11 #include <glog/logging.h> 19 using namespace folly;
26 const std::vector<HPACKHeader>& expectedHeaders,
28 auto cb = std::make_shared<TestStreamingCallback>();
31 HPACK::DecodeError::NONE);
33 auto length = result.
stream->computeChainDataLength();
34 if (expectedError == HPACK::DecodeError::NONE) {
35 cb->headersCompleteCb =
36 [&expectedHeaders, cb] ()
mutable {
37 std::vector<HPACKHeader>
test;
38 for (
size_t i = 0;
i < cb->headers.size();
i += 2) {
39 test.emplace_back(cb->headers[
i].str, cb->headers[
i + 1].str);
41 EXPECT_EQ(cb->error, HPACK::DecodeError::NONE);
53 return memmem(stream->
data(), stream->
length(),
54 expected.data(), expected.length());
68 TEST(QPACKContextTests, StaticOnly) {
71 vector<HPACKHeader> req;
72 req.push_back(
HPACKHeader(
"accept-encoding",
"gzip, deflate"));
73 auto result = encoder.
encode(req, 10, 1);
77 verifyDecode(decoder,
std::move(result), req);
82 TEST(QPACKContextTests, Indexed) {
85 vector<HPACKHeader> req;
88 auto result = encoder.
encode(req, 10, 1);
89 verifyDecode(decoder,
std::move(result), req);
91 result = encoder.
encode(req, 10, 2);
92 verifyDecode(decoder,
std::move(result), req);
95 TEST(QPACKContextTests, NameIndexed) {
98 vector<HPACKHeader> req;
103 auto result = encoder.
encode(req, 10, 1);
104 verifyDecode(decoder,
std::move(result), req);
106 result = encoder.
encode(req, 10, 2);
107 verifyDecode(decoder,
std::move(result), req);
110 TEST(QPACKContextTests, NameIndexedInsert) {
113 vector<HPACKHeader> req;
116 auto result = encoder.
encode(req, 10, 1);
117 verifyDecode(decoder,
std::move(result), req);
121 result = encoder.
encode(req, 10, 2);
123 verifyDecode(decoder,
std::move(result), req);
126 TEST(QPACKContextTests, PostBaseNameIndexedLiteral) {
129 vector<HPACKHeader> req;
133 for (
auto i = 0;
i < 8;
i++) {
134 req.push_back(
HPACKHeader(folly::to<std::string>(
"Blarf",
i),
"0"));
138 req.push_back(
HPACKHeader(
"Blarf7",
"blergblergblerg"));
139 auto result = encoder.
encode(req, 10, 1);
143 verifyDecode(decoder,
std::move(result), req);
147 TEST(QPACKContextTests, Unacknowledged) {
152 vector<HPACKHeader> req;
154 auto result = encoder.
encode(req, 10, 1);
158 verifyDecode(decoder,
std::move(result), req);
161 result = encoder.
encode(req, 10, 2);
163 verifyDecode(decoder,
std::move(result), req);
166 TEST(QPACKContextTests, TestDraining) {
168 vector<HPACKHeader> req;
169 req.push_back(
HPACKHeader(
"accept-encoding",
"gzip,deflate"));
170 auto result = encoder.
encode(req, 0, 1);
175 req.push_back(
HPACKHeader(
"accept-encoding",
"sdch,gzip"));
176 req.push_back(
HPACKHeader(
"accept-encoding",
"gzip,deflate"));
177 result = encoder.
encode(req, 0, 2);
182 TEST(QPACKContextTests, TestDuplicate) {
185 vector<HPACKHeader> req;
187 for (
auto i = 0;
i < 6;
i++) {
188 req.emplace_back(folly::to<string>(
'a' +
i), folly::to<string>(
i));
191 auto result = encoder.
encode(req, 0, 1);
192 verifyDecode(decoder,
std::move(result), req);
194 EXPECT_EQ(headerAck(decoder, encoder, 1), HPACK::DecodeError::NONE);
195 req.erase(req.begin() + 1, req.end());
196 result = encoder.
encode(req, 0, 2);
200 verifyDecode(decoder,
std::move(result), req);
203 TEST(QPACKContextTests, TestTableSizeUpdate) {
206 vector<HPACKHeader> req;
207 req.emplace_back(
"Blarf",
"Blah");
208 req.emplace_back(
"Blarf",
"Blerg");
209 auto result = encoder.
encode(req, 0, 1);
210 verifyDecode(decoder,
std::move(result), req);
212 EXPECT_EQ(headerAck(decoder, encoder, 1), HPACK::DecodeError::NONE);
215 result = encoder.
encode(req, 0, 2);
216 verifyDecode(decoder,
std::move(result), req);
218 EXPECT_EQ(headerAck(decoder, encoder, 2), HPACK::DecodeError::NONE);
221 result = encoder.
encode(req, 0, 3);
223 verifyDecode(decoder,
std::move(result), req);
228 TEST(QPACKContextTests, TestAcks) {
233 EXPECT_EQ(headerAck(decoder, encoder, 1), HPACK::DecodeError::INVALID_ACK);
235 vector<HPACKHeader> req;
236 req.emplace_back(
"Blarf",
"BlahBlahBlah");
237 auto result = encoder.
encode(req, 0, 1);
238 verifyDecode(decoder,
std::move(result), req);
240 req.emplace_back(
"accept-encoding",
"gzip, deflate");
241 result = encoder.
encode(req, 0, 1);
242 verifyDecode(decoder,
std::move(result), req);
244 req.emplace_back(
"Blarf",
"BlahBlahBlah");
245 result = encoder.
encode(req, 0, 1);
246 verifyDecode(decoder,
std::move(result), req);
249 result = encoder.
encode(req, 0, 2);
252 verifyDecode(decoder,
std::move(result), req);
256 req.emplace_back(
"Foo",
"BlahBlahBlahBlah!");
257 result = encoder.
encode(req, 0, 3);
260 verifyDecode(decoder,
std::move(result), req);
261 EXPECT_EQ(headerAck(decoder, encoder, 3), HPACK::DecodeError::NONE);
265 EXPECT_EQ(headerAck(decoder, encoder, 2), HPACK::DecodeError::NONE);
266 EXPECT_EQ(cancelStream(decoder, encoder, 1), HPACK::DecodeError::NONE);
269 result = encoder.
encode(req, 0, 2);
271 EXPECT_GT(result.control->computeChainDataLength(), 1);
272 EXPECT_EQ(result.stream->computeChainDataLength(), 3);
273 EXPECT_FALSE(stringInOutput(result.stream.get(),
"foo"));
274 verifyDecode(decoder,
std::move(result), req);
277 TEST(QPACKContextTests, TestImplicitAcks) {
282 vector<HPACKHeader> req;
283 req.emplace_back(
"Blarf",
"Blah");
284 auto result = encoder.
encode(req, 0, 1);
285 verifyDecode(decoder,
std::move(result), req);
286 req.emplace_back(
"Foo",
"Blah");
287 result = encoder.
encode(req, 0, 2);
288 verifyDecode(decoder,
std::move(result), req);
292 req.emplace_back(
"Bar",
"Binky");
293 result = encoder.
encode(req, 0, 3);
296 req.emplace_back(
"Blarf",
"Blah");
297 req.emplace_back(
"Foo",
"Blah");
298 result = encoder.
encode(req, 0, 4);
300 verifyDecode(decoder,
std::move(result), req);
307 TEST(QPACKContextTests, TestDecodeQueue) {
311 vector<HPACKHeader> req1;
312 req1.emplace_back(
"Blarf",
"Blah");
313 auto result1 = encoder.
encode(req1, 0, 1);
315 vector<HPACKHeader> req2;
316 req2.emplace_back(
"Blarf",
"Blerg");
317 auto result2 = encoder.
encode(req2, 0, 2);
318 verifyDecode(decoder,
std::move(result2), req2);
319 verifyDecode(decoder,
std::move(result1), req1);
322 TEST(QPACKContextTests, TestDecodeQueueDelete) {
326 auto decoder = std::make_unique<QPACKDecoder>(100);
328 vector<HPACKHeader> req1;
329 req1.emplace_back(
"Blarf",
"Blah");
330 auto result1 = encoder.
encode(req1, 0, 1);
332 vector<HPACKHeader> req2;
333 req2.emplace_back(
"Blarf",
"Blerg");
334 auto result2 = encoder.
encode(req2, 0, 2);
338 auto cb1 = std::make_unique<TestStreamingCallback>();
339 auto rawCb1 = cb1.get();
340 auto rawDecoder = decoder.get();
341 cb1->headersCompleteCb = [decoder=
std::move(decoder)] ()
mutable {
345 auto length = result1.stream->computeChainDataLength();
349 auto cb2 = std::make_unique<TestStreamingCallback>();
350 length = result2.stream->computeChainDataLength();
351 rawDecoder->decodeStreaming(2,
std::move(result2.stream), length, cb2.get());
355 HPACK::DecodeError::NONE);
358 EXPECT_EQ(cb2->error, HPACK::DecodeError::NONE);
362 TEST(QPACKContextTests, TestDecodeMaxUncompressed) {
367 vector<HPACKHeader> req;
368 req.emplace_back(
"Blarf",
"Blah");
369 auto result = encoder.
encode(req, 0, 1);
370 verifyDecode(decoder,
std::move(result), req,
371 HPACK::DecodeError::HEADERS_TOO_LARGE);
374 TEST(QPACKContextTests, TestDecoderStreamChunked) {
378 vector<HPACKHeader> req;
379 for (
auto i = 0;
i < 128;
i++) {
380 req.emplace_back(
"a", folly::to<string>(
i));
382 auto result = encoder.
encode(req, 0, 1);
384 HPACK::DecodeError::NONE);
386 EXPECT_EQ(ack->computeChainDataLength(), 2);
387 auto ackPart = ack->clone();
391 HPACK::DecodeError::NONE);
393 HPACK::DecodeError::NONE);
398 TEST(QPACKContextTests, TestDecodePartialControl) {
402 vector<HPACKHeader> req;
403 req.emplace_back(
"abcdeabcdeabcdeabcdeabcdeabcdeabcde",
404 "vwxyzvwxyzvwxyzvwxyzvwxyzvwxyzvwxyz");
405 auto result = encoder.
encode(req, 0, 1);
407 while (!
c.isAtEnd()) {
408 std::unique_ptr<folly::IOBuf> buf;
411 HPACK::DecodeError::NONE);
419 auto cb = std::make_unique<TestStreamingCallback>();
426 TEST(QPACKContextTests, DecodeErrors) {
496 HPACK::DecodeError::NONE);
503 HPACK::DecodeError::INVALID_INDEX);
521 HPACK::DecodeError::INTEGER_OVERFLOW);
526 HPACK::DecodeError::INTEGER_OVERFLOW);
531 HPACK::DecodeError::INTEGER_OVERFLOW);
534 TEST(QPACKContextTests, TestEvictedNameReference) {
538 vector<HPACKHeader> req;
539 req.push_back(
HPACKHeader(
"x-accept-encoding",
"foobarfoobar"));
540 auto result = encoder.
encode(req, 0, 1);
543 result.
stream->computeChainDataLength(),
nullptr);
546 req.push_back(
HPACKHeader(
"x-accept-encoding",
"barfoobarfoo"));
547 result = encoder.
encode(req, 0, 2);
552 result.
stream->computeChainDataLength(), &cb);
void setMaxUncompressed(uint64_t maxUncompressed)
std::unique_ptr< folly::IOBuf > encodeTableStateSync()
HPACK::DecodeError decodeEncoderStream(std::unique_ptr< folly::IOBuf > buf)
static std::unique_ptr< IOBuf > create(std::size_t capacity)
void setMaxVulnerable(uint32_t maxVulnerable)
const QPACKHeaderTable & getTable() const
#define EXPECT_EQ(val1, val2)
static uint64_t test(std::string name, bool fc_, bool dedicated_, bool tc_, bool syncops_, uint64_t base)
constexpr detail::Map< Move > move
const uint8_t * data() const
—— Concurrent Priority Queue Implementation ——
HPACK::DecodeError onHeaderAck(uint64_t streamId, bool all)
std::unique_ptr< IOBuf > clone() const
HPACK::DecodeError decodeDecoderStream(std::unique_ptr< folly::IOBuf > buf)
void setHeaderTableSize(uint32_t size)
EncodeResult encode(const std::vector< HPACKHeader > &headers, uint32_t headroom, uint64_t streamId)
const HPACKHeader & getHeader(bool isStatic, uint32_t index, uint32_t base, bool aboveBase)
void decodeStreaming(uint64_t streamId, std::unique_ptr< folly::IOBuf > block, uint32_t totalBytes, HPACK::StreamingCallback *streamingCb)
std::size_t length() const
uint32_t getHeadersStored() const
std::size_t computeChainDataLength() const
#define EXPECT_TRUE(condition)
void setMaxBlocking(uint32_t maxBlocking)
HPACK::DecodeError onTableStateSync(uint32_t inserts)
std::unique_ptr< folly::IOBuf > encodeHeaderAck(uint64_t streamId) const
#define EXPECT_FALSE(condition)
void trimEnd(std::size_t amount)
TEST(SequencedExecutor, CPUThreadPoolExecutor)
std::unique_ptr< folly::IOBuf > encodeCancelStream(uint64_t streamId)
void checkQError(QPACKDecoder &decoder, std::unique_ptr< IOBuf > buf, const HPACK::DecodeError err)
void append(std::size_t amount)
#define EXPECT_GT(val1, val2)