diff options
author | Anton Samokhvalov <pg83@yandex.ru> | 2022-02-10 16:45:15 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:15 +0300 |
commit | 72cb13b4aff9bc9cf22e49251bc8fd143f82538f (patch) | |
tree | da2c34829458c7d4e74bdfbdf85dff449e9e7fb8 /library/cpp/http/fetch/httpparser_ut.cpp | |
parent | 778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff) | |
download | ydb-72cb13b4aff9bc9cf22e49251bc8fd143f82538f.tar.gz |
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/http/fetch/httpparser_ut.cpp')
-rw-r--r-- | library/cpp/http/fetch/httpparser_ut.cpp | 172 |
1 files changed, 86 insertions, 86 deletions
diff --git a/library/cpp/http/fetch/httpparser_ut.cpp b/library/cpp/http/fetch/httpparser_ut.cpp index 3b3b938e7a..6957eb2f5f 100644 --- a/library/cpp/http/fetch/httpparser_ut.cpp +++ b/library/cpp/http/fetch/httpparser_ut.cpp @@ -2,13 +2,13 @@ #include <library/cpp/testing/unittest/registar.h> -#define ENUM_OUT(arg) \ - case type ::arg: { \ - out << #arg; \ - return; \ - } +#define ENUM_OUT(arg) \ + case type ::arg: { \ + out << #arg; \ + return; \ + } -template <> +template <> void Out<THttpParserBase::States>(IOutputStream& out, THttpParserBase::States st) { using type = THttpParserBase::States; switch (st) { @@ -24,27 +24,27 @@ void Out<THttpParserBase::States>(IOutputStream& out, THttpParserBase::States st } namespace { - class TSomethingLikeFakeCheck; + class TSomethingLikeFakeCheck; - using TTestHttpParser = THttpParser<TSomethingLikeFakeCheck>; + using TTestHttpParser = THttpParser<TSomethingLikeFakeCheck>; - class TSomethingLikeFakeCheck { - TString Body_; + class TSomethingLikeFakeCheck { + TString Body_; - public: - const TString& Body() const { - return Body_; - } + public: + const TString& Body() const { + return Body_; + } - // other functions are not really called by THttpParser - void CheckDocPart(const void* buf, size_t len, THttpHeader* /* header */) { - TString s(static_cast<const char*>(buf), len); - Cout << "State = " << static_cast<TTestHttpParser*>(this)->GetState() << ", CheckDocPart(" << s.Quote() << ")\n"; - Body_ += s; - } - }; + // other functions are not really called by THttpParser + void CheckDocPart(const void* buf, size_t len, THttpHeader* /* header */) { + TString s(static_cast<const char*>(buf), len); + Cout << "State = " << static_cast<TTestHttpParser*>(this)->GetState() << ", CheckDocPart(" << s.Quote() << ")\n"; + Body_ += s; + } + }; -} +} Y_UNIT_TEST_SUITE(TestHttpParser) { Y_UNIT_TEST(TestTrivialRequest) { @@ -73,9 +73,9 @@ Y_UNIT_TEST_SUITE(TestHttpParser) { UNIT_ASSERT_EQUAL(parser.GetState(), parser.hp_eof); UNIT_ASSERT_EQUAL(parser.Body(), "OK"); UNIT_ASSERT_EQUAL(hdr.header_size, strlen( - "HTTP/1.1 200 Ok\r\n" - "Content-Length: 2\r\n" - "\r\n")); + "HTTP/1.1 200 Ok\r\n" + "Content-Length: 2\r\n" + "\r\n")); UNIT_ASSERT_EQUAL(hdr.entity_size, strlen("OK")); } @@ -98,36 +98,36 @@ Y_UNIT_TEST_SUITE(TestHttpParser) { UNIT_ASSERT_EQUAL(parser.GetState(), parser.hp_eof); UNIT_ASSERT_EQUAL(parser.Body(), "OkAllRight"); UNIT_ASSERT_EQUAL(hdr.header_size, strlen( - "HTTP/1.1 200 OK\r\n" - "Transfer-Encoding: chunked\r\n" - "\r\n")); + "HTTP/1.1 200 OK\r\n" + "Transfer-Encoding: chunked\r\n" + "\r\n")); const int off_by_one_err = -1; // XXX: it really looks so UNIT_ASSERT_EQUAL(hdr.entity_size + off_by_one_err, strlen( - "2\r\n" - "Ok\r\n" - "8\r\n" - "AllRight\r\n" - "0\r\n" - "\r\n")); + "2\r\n" + "Ok\r\n" + "8\r\n" + "AllRight\r\n" + "0\r\n" + "\r\n")); } static const TString PipelineClenBlob_{ - "HTTP/1.1 200 Ok\r\n" - "Content-Length: 4\r\n" - "\r\n" - "OK\r\n" - "HTTP/1.1 200 Zz\r\n" - "Content-Length: 4\r\n" - "\r\n" - "ZZ\r\n"}; - - void AssertPipelineClen(TTestHttpParser & parser, const THttpHeader& hdr) { + "HTTP/1.1 200 Ok\r\n" + "Content-Length: 4\r\n" + "\r\n" + "OK\r\n" + "HTTP/1.1 200 Zz\r\n" + "Content-Length: 4\r\n" + "\r\n" + "ZZ\r\n"}; + + void AssertPipelineClen(TTestHttpParser & parser, const THttpHeader& hdr) { UNIT_ASSERT_EQUAL(parser.GetState(), parser.hp_eof); UNIT_ASSERT_EQUAL(4, hdr.content_length); UNIT_ASSERT_EQUAL(hdr.header_size, strlen( - "HTTP/1.1 200 Ok\r\n" - "Content-Length: 4\r\n" - "\r\n")); + "HTTP/1.1 200 Ok\r\n" + "Content-Length: 4\r\n" + "\r\n")); } Y_UNIT_TEST(TestPipelineClenByteByByte) { @@ -154,55 +154,55 @@ Y_UNIT_TEST_SUITE(TestHttpParser) { parser.Parse((void*)blob.data(), blob.size()); AssertPipelineClen(parser, hdr); UNIT_ASSERT_EQUAL(parser.Body(), - "OK\r\n" - "HTTP/1.1 200 Zz\r\n" - "Content-Length: 4\r\n" - "\r\n" - "ZZ\r\n"); + "OK\r\n" + "HTTP/1.1 200 Zz\r\n" + "Content-Length: 4\r\n" + "\r\n" + "ZZ\r\n"); UNIT_ASSERT_EQUAL(hdr.entity_size, strlen( - "OK\r\n" - "HTTP/1.1 200 Zz\r\n" - "Content-Length: 4\r\n" - "\r\n" - "ZZ\r\n")); + "OK\r\n" + "HTTP/1.1 200 Zz\r\n" + "Content-Length: 4\r\n" + "\r\n" + "ZZ\r\n")); } static const TString PipelineChunkedBlob_{ - "HTTP/1.1 200 OK\r\n" - "Transfer-Encoding: chunked\r\n" - "\r\n" - "2\r\n" - "Ok\r\n" - "8\r\n" - "AllRight\r\n" - "0\r\n" - "\r\n" - "HTTP/1.1 200 OK\r\n" - "Transfer-Encoding: chunked\r\n" - "\r\n" - "2\r\n" - "Yo\r\n" - "8\r\n" - "uWin!Iam\r\n" - "0\r\n" - "\r\n"}; - - void AssertPipelineChunked(TTestHttpParser & parser, const THttpHeader& hdr) { + "HTTP/1.1 200 OK\r\n" + "Transfer-Encoding: chunked\r\n" + "\r\n" + "2\r\n" + "Ok\r\n" + "8\r\n" + "AllRight\r\n" + "0\r\n" + "\r\n" + "HTTP/1.1 200 OK\r\n" + "Transfer-Encoding: chunked\r\n" + "\r\n" + "2\r\n" + "Yo\r\n" + "8\r\n" + "uWin!Iam\r\n" + "0\r\n" + "\r\n"}; + + void AssertPipelineChunked(TTestHttpParser & parser, const THttpHeader& hdr) { UNIT_ASSERT_EQUAL(parser.GetState(), parser.hp_eof); UNIT_ASSERT_EQUAL(parser.Body(), "OkAllRight"); UNIT_ASSERT_EQUAL(-1, hdr.content_length); UNIT_ASSERT_EQUAL(hdr.header_size, strlen( - "HTTP/1.1 200 OK\r\n" - "Transfer-Encoding: chunked\r\n" - "\r\n")); + "HTTP/1.1 200 OK\r\n" + "Transfer-Encoding: chunked\r\n" + "\r\n")); const int off_by_one_err = -1; UNIT_ASSERT_EQUAL(hdr.entity_size + off_by_one_err, strlen( - "2\r\n" - "Ok\r\n" - "8\r\n" - "AllRight\r\n" - "0\r\n" - "\r\n")); + "2\r\n" + "Ok\r\n" + "8\r\n" + "AllRight\r\n" + "0\r\n" + "\r\n")); } Y_UNIT_TEST(TestPipelineChunkedByteByByte) { |