MCPcopy Create free account
hub / github.com/arvidn/libtorrent / test_collapse_chunks

Function test_collapse_chunks

test/test_http_parser.cpp:632–665  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

630
631namespace {
632std::string test_collapse_chunks(std::string chunked_input, bool const expect_error = false)
633{
634 http_parser parser;
635
636 std::string input = "HTTP/1.1 200 OK\r\n"
637 "Transfer-Encoding: chunked\r\n"
638 "Content-Type: text/plain\r\n"
639 "\r\n";
640
641 input += chunked_input;
642
643 bool error = false;
644 int payload = 0;
645 int protocol = 0;
646 std::tie(payload, protocol) = parser.incoming(input, error);
647
648 TEST_CHECK(protocol > 0);
649 TEST_CHECK(payload > 0);
650 if (expect_error)
651 {
652 TEST_CHECK(std::size_t(protocol + payload) <= input.size());
653 }
654 else
655 {
656 TEST_EQUAL(std::size_t(protocol + payload), input.size());
657 TEST_CHECK(parser.finished());
658 }
659
660 std::vector<char> mutable_buffer;
661 span<char const> body = parser.get_body();
662 std::copy(body.begin(), body.end(), std::back_inserter(mutable_buffer));
663 body = parser.collapse_chunk_headers(mutable_buffer);
664 return std::string(body.data(), std::size_t(body.size()));
665}
666}
667
668TORRENT_TEST(chunked_encoding)

Callers 1

TORRENT_TESTFunction · 0.85

Calls 8

get_bodyMethod · 0.80
incomingMethod · 0.45
sizeMethod · 0.45
finishedMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected