| 15 | #include <gtest/gtest.h> |
| 16 | |
| 17 | TEST(FileUtils, StreamIO) { |
| 18 | std::string s{"Hello world"}; |
| 19 | std::string s2; |
| 20 | std::filesystem::path tmpdir = std::filesystem::temp_directory_path(); |
| 21 | std::filesystem::path filepath = tmpdir / std::filesystem::u8path("ななひら.txt"); |
| 22 | |
| 23 | { |
| 24 | std::ofstream ofs = treelite::detail::OpenFileForWriteAsStream(filepath); |
| 25 | ofs.write(s.data(), s.length()); |
| 26 | } |
| 27 | { |
| 28 | std::ifstream ifs = treelite::detail::OpenFileForReadAsStream(filepath); |
| 29 | s2.resize(s.length()); |
| 30 | ifs.read(s2.data(), s.length()); |
| 31 | ASSERT_EQ(s, s2); |
| 32 | } |
| 33 | |
| 34 | std::filesystem::remove(filepath); |
| 35 | } |
| 36 | |
| 37 | TEST(FileUtils, OpenFileForReadAsFilePtr) { |
| 38 | std::string s{"Hello world"}; |
nothing calls this directly
no test coverage detected