| 22 | |
| 23 | template <typename FuncType> |
| 24 | void ForInput(const TStringBuf text, const FuncType& func) { |
| 25 | TFile tempFile(TFile::Temporary("input_ut")); |
| 26 | tempFile.Write(text.data(), text.size()); |
| 27 | tempFile.FlushData(); |
| 28 | tempFile.Seek(0, sSet); |
| 29 | |
| 30 | TFileHandle tempFh(tempFile.GetHandle()); |
| 31 | tempFh.Duplicate2Posix(0); |
| 32 | tempFh.Release(); |
| 33 | |
| 34 | func(); |
| 35 | Cin.ReadAll(); |
| 36 | dup2(StdInCopy_, 0); |
| 37 | clearerr(stdin); |
| 38 | } |
| 39 | |
| 40 | private: |
| 41 | int StdInCopy_; |