diff options
author | gotmanov <gotmanov@yandex-team.ru> | 2022-02-10 16:49:26 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:26 +0300 |
commit | 243edeedfd2c5152b5c7812e0af471e1bb0232e8 (patch) | |
tree | 7efbef4b4e045bcee8833f7fc22a639fa0ff06aa /util/stream/input_ut.cpp | |
parent | 56c39b3cf908e7202b1f7551a1653681e8015607 (diff) | |
download | ydb-243edeedfd2c5152b5c7812e0af471e1bb0232e8.tar.gz |
Restoring authorship annotation for <gotmanov@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util/stream/input_ut.cpp')
-rw-r--r-- | util/stream/input_ut.cpp | 76 |
1 files changed, 38 insertions, 38 deletions
diff --git a/util/stream/input_ut.cpp b/util/stream/input_ut.cpp index 4a93f5458e..3e22e1f3b9 100644 --- a/util/stream/input_ut.cpp +++ b/util/stream/input_ut.cpp @@ -3,44 +3,44 @@ #include <library/cpp/testing/unittest/registar.h> -#include <util/system/file.h> +#include <util/system/file.h> #include <util/system/yassert.h> #ifdef _win_ #include <io.h> #endif -class TMockStdIn { -public: - TMockStdIn() +class TMockStdIn { +public: + TMockStdIn() : StdInCopy_(dup(0)) { } - ~TMockStdIn() { + ~TMockStdIn() { close(StdInCopy_); - } - - template <typename FuncType> + } + + template <typename FuncType> void ForInput(const TStringBuf text, const FuncType& func) { - TFile tempFile(TFile::Temporary("input_ut")); + TFile tempFile(TFile::Temporary("input_ut")); tempFile.Write(text.data(), text.size()); - tempFile.FlushData(); - tempFile.Seek(0, sSet); - - TFileHandle tempFh(tempFile.GetHandle()); + tempFile.FlushData(); + tempFile.Seek(0, sSet); + + TFileHandle tempFh(tempFile.GetHandle()); tempFh.Duplicate2Posix(0); - tempFh.Release(); - - func(); - Cin.ReadAll(); + tempFh.Release(); + + func(); + Cin.ReadAll(); dup2(StdInCopy_, 0); clearerr(stdin); - } + } -private: +private: int StdInCopy_; -}; - +}; + class TNoInput: public IInputStream { public: TNoInput(ui64 size) @@ -130,28 +130,28 @@ Y_UNIT_TEST_SUITE(TInputTest) { UNIT_ASSERT_VALUES_EQUAL(in.ReadLine(t), 0); UNIT_ASSERT_VALUES_EQUAL(t, "333"); } - + Y_UNIT_TEST(TestStdInReadTo) { - std::pair<std::pair<TStringBuf, char>, TStringBuf> testPairs[] = { - {{"", '\n'}, ""}, - {{"\n", '\n'}, ""}, - {{"\n\t", '\t'}, "\n"}, - {{"\t\n", '\n'}, "\t"}, + std::pair<std::pair<TStringBuf, char>, TStringBuf> testPairs[] = { + {{"", '\n'}, ""}, + {{"\n", '\n'}, ""}, + {{"\n\t", '\t'}, "\n"}, + {{"\t\n", '\n'}, "\t"}, {{"a\tb\n", '\t'}, "a"}}; - - TMockStdIn stdIn; - - for (const auto& testPair : testPairs) { - const TStringBuf text = testPair.first.first; - const char delim = testPair.first.second; - const TStringBuf expectedValue = testPair.second; - - stdIn.ForInput(text, + + TMockStdIn stdIn; + + for (const auto& testPair : testPairs) { + const TStringBuf text = testPair.first.first; + const char delim = testPair.first.second; + const TStringBuf expectedValue = testPair.second; + + stdIn.ForInput(text, [=] { TString value; Cin.ReadTo(value, delim); UNIT_ASSERT_VALUES_EQUAL(value, expectedValue); }); - } - } + } + } } |