diff --git a/CHANGELOG.md b/CHANGELOG.md index 12888672..d822023a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ +* Add tests for file open in append mode. * Fix file open with append/append_existing flag on Windows. -------------------------------------------------------------------------------- diff --git a/test/beast/core/file_test.hpp b/test/beast/core/file_test.hpp index 280bf727..fac2f45b 100644 --- a/test/beast/core/file_test.hpp +++ b/test/beast/core/file_test.hpp @@ -17,7 +17,9 @@ #include #include #include +#include #include +#include #include namespace boost { @@ -100,6 +102,20 @@ test_file() BEAST_EXPECT(! fs::exists(path)); }; + auto const consume_file = + [](fs::path const& path) + { + // no exceptions - failure will result in an empty string + std::ifstream in; + in.open(path.native()); + noskipws(in); + auto s = std::string( + std::istream_iterator(in), + std::istream_iterator()); + in.close(); + return s; + }; + temp_path path; // bad file descriptor @@ -230,7 +246,14 @@ test_file() f.open(path, file_mode::append, ec); BEAST_EXPECT(! ec); BEAST_EXPECT(fs::exists(path)); + static const std::string extra = "the"; + f.write(extra.c_str(), extra.size(), ec); + BEAST_EXPECT(!ec); + f.close(ec); + auto s = consume_file(path); + BEAST_EXPECT(s == "the"); } + { File f; error_code ec; @@ -238,6 +261,12 @@ test_file() f.open(path, file_mode::append, ec); BEAST_EXPECT(! ec); BEAST_EXPECT(fs::exists(path)); + static const std::string extra = " cat"; + f.write(extra.c_str(), extra.size(), ec); + BEAST_EXPECT(!ec); + f.close(ec); + auto s = consume_file(path); + BEAST_EXPECTS(s == "the cat", s); } remove(path); }