mirror of
https://github.com/boostorg/beast.git
synced 2025-07-30 04:47:29 +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.
|
* Fix file open with append/append_existing flag on Windows.
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
@ -17,7 +17,9 @@
|
|||||||
#include <boost/filesystem/operations.hpp>
|
#include <boost/filesystem/operations.hpp>
|
||||||
#include <boost/filesystem/fstream.hpp>
|
#include <boost/filesystem/fstream.hpp>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
#include <fstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <iterator>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
namespace boost {
|
namespace boost {
|
||||||
@ -100,6 +102,20 @@ test_file()
|
|||||||
BEAST_EXPECT(! fs::exists(path));
|
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;
|
temp_path path;
|
||||||
|
|
||||||
// bad file descriptor
|
// bad file descriptor
|
||||||
@ -230,7 +246,14 @@ test_file()
|
|||||||
f.open(path, file_mode::append, ec);
|
f.open(path, file_mode::append, ec);
|
||||||
BEAST_EXPECT(! ec);
|
BEAST_EXPECT(! ec);
|
||||||
BEAST_EXPECT(fs::exists(path));
|
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;
|
File f;
|
||||||
error_code ec;
|
error_code ec;
|
||||||
@ -238,6 +261,12 @@ test_file()
|
|||||||
f.open(path, file_mode::append, ec);
|
f.open(path, file_mode::append, ec);
|
||||||
BEAST_EXPECT(! ec);
|
BEAST_EXPECT(! ec);
|
||||||
BEAST_EXPECT(fs::exists(path));
|
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);
|
remove(path);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user