mirror of
https://github.com/boostorg/beast.git
synced 2025-07-29 12:27:44 +02:00
Add tests for file open in append/append_existing mode
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
* Add tests for file open in append mode.
|
||||
* Fix file open with append/append_existing flag on Windows.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
@ -17,7 +17,9 @@
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
#include <boost/filesystem/fstream.hpp>
|
||||
#include <cstdio>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <iterator>
|
||||
#include <type_traits>
|
||||
|
||||
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<char>(in),
|
||||
std::istream_iterator<char>());
|
||||
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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user