diff options
author | Alexander Fokin <[email protected]> | 2022-02-10 16:45:38 +0300 |
---|---|---|
committer | Daniil Cherednik <[email protected]> | 2022-02-10 16:45:38 +0300 |
commit | bf9e69a933f89af083d895185f01ed65e4d90766 (patch) | |
tree | b2cc84ee7850122e7ccf51d0ea21e4fa7e7a5685 /library/cpp/http/io/chunk_ut.cpp | |
parent | 863a59a65247c24db7cb06789bc5cf79d04da32f (diff) |
Restoring authorship annotation for Alexander Fokin <[email protected]>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/http/io/chunk_ut.cpp')
-rw-r--r-- | library/cpp/http/io/chunk_ut.cpp | 98 |
1 files changed, 49 insertions, 49 deletions
diff --git a/library/cpp/http/io/chunk_ut.cpp b/library/cpp/http/io/chunk_ut.cpp index beaeababd25..da283f85680 100644 --- a/library/cpp/http/io/chunk_ut.cpp +++ b/library/cpp/http/io/chunk_ut.cpp @@ -13,50 +13,50 @@ Y_UNIT_TEST_SUITE(TestChunkedIO) { TString CombString(const TString& s, size_t chunkSize) { TString result; - for (size_t pos = 0; pos < s.size(); pos += 2 * chunkSize) - result += s.substr(pos, chunkSize); - return result; - } - + for (size_t pos = 0; pos < s.size(); pos += 2 * chunkSize) + result += s.substr(pos, chunkSize); + return result; + } + void WriteTestData(IOutputStream * stream, TString * contents) { - contents->clear(); - for (size_t i = 0; i < sizeof(test_data); ++i) { - stream->Write(test_data, i); - contents->append(test_data, i); - } - } - + contents->clear(); + for (size_t i = 0; i < sizeof(test_data); ++i) { + stream->Write(test_data, i); + contents->append(test_data, i); + } + } + void ReadInSmallChunks(IInputStream * stream, TString * contents) { - char buf[11]; - size_t read = 0; - - contents->clear(); - do { - read = stream->Read(buf, sizeof(buf)); - contents->append(buf, read); - } while (read > 0); - } - + char buf[11]; + size_t read = 0; + + contents->clear(); + do { + read = stream->Read(buf, sizeof(buf)); + contents->append(buf, read); + } while (read > 0); + } + void ReadCombed(IInputStream * stream, TString * contents, size_t chunkSize) { Y_ASSERT(chunkSize < 128); - char buf[128]; - - contents->clear(); - while (true) { - size_t read = stream->Load(buf, chunkSize); - contents->append(buf, read); - if (read == 0) - break; - - size_t toSkip = chunkSize; - size_t skipped = 0; - do { - skipped = stream->Skip(toSkip); - toSkip -= skipped; - } while (skipped != 0 && toSkip != 0); - } - } - + char buf[128]; + + contents->clear(); + while (true) { + size_t read = stream->Load(buf, chunkSize); + contents->append(buf, read); + if (read == 0) + break; + + size_t toSkip = chunkSize; + size_t skipped = 0; + do { + skipped = stream->Skip(toSkip); + toSkip -= skipped; + } while (skipped != 0 && toSkip != 0); + } + } + Y_UNIT_TEST(TestChunkedIo) { TTempFile tmpFile(CDATA); TString tmp; @@ -64,17 +64,17 @@ Y_UNIT_TEST_SUITE(TestChunkedIO) { { TUnbufferedFileOutput fo(CDATA); TChunkedOutput co(&fo); - WriteTestData(&co, &tmp); - } + WriteTestData(&co, &tmp); + } - { + { TUnbufferedFileInput fi(CDATA); - TChunkedInput ci(&fi); + TChunkedInput ci(&fi); TString r; - ReadInSmallChunks(&ci, &r); - - UNIT_ASSERT_EQUAL(r, tmp); + ReadInSmallChunks(&ci, &r); + + UNIT_ASSERT_EQUAL(r, tmp); } { @@ -82,9 +82,9 @@ Y_UNIT_TEST_SUITE(TestChunkedIO) { TChunkedInput ci(&fi); TString r; - ReadCombed(&ci, &r, 11); + ReadCombed(&ci, &r, 11); - UNIT_ASSERT_EQUAL(r, CombString(tmp, 11)); + UNIT_ASSERT_EQUAL(r, CombString(tmp, 11)); } } |