xrpld
Loading...
Searching...
No Matches
FileUtilities_test.cpp
1#include <test/unit_test/FileDirGuard.h>
2
3#include <xrpl/basics/ByteUtilities.h>
4#include <xrpl/basics/FileUtilities.h>
5#include <xrpl/beast/unit_test/suite.h>
6
7#include <boost/system/detail/errc.hpp>
8#include <boost/system/detail/error_code.hpp>
9
10namespace xrpl {
11
13{
14public:
15 void
17 {
18 using namespace xrpl::detail;
19 using namespace boost::system;
20
21 static constexpr char const* kExpectedContents =
22 "This file is very short. That's all we need.";
23
24 FileDirGuard const file(
25 *this, "test_file", "test.txt", "This is temporary text that should get overwritten");
26
27 error_code ec;
28 auto const path = file.file();
29
30 writeFileContents(ec, path, kExpectedContents);
31 BEAST_EXPECT(!ec);
32
33 {
34 // Test with no max
35 auto const good = getFileContents(ec, path);
36 BEAST_EXPECT(!ec);
37 BEAST_EXPECT(good == kExpectedContents);
38 }
39
40 {
41 // Test with large max
42 auto const good = getFileContents(ec, path, kilobytes(1));
43 BEAST_EXPECT(!ec);
44 BEAST_EXPECT(good == kExpectedContents);
45 }
46
47 {
48 // Test with small max
49 auto const bad = getFileContents(ec, path, 16);
50 BEAST_EXPECT(ec && ec.value() == boost::system::errc::file_too_large);
51 BEAST_EXPECT(bad.empty());
52 }
53 }
54
55 void
56 run() override
57 {
59 }
60};
61
62BEAST_DEFINE_TESTSUITE(FileUtilities, basics, xrpl);
63
64} // namespace xrpl
A testsuite class.
Definition suite.h:50
void run() override
Runs the suite.
Write a file in a directory and remove when done.
path const & file() const
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
std::string getFileContents(boost::system::error_code &ec, boost::filesystem::path const &sourcePath, std::optional< std::size_t > maxSize=std::nullopt)
void writeFileContents(boost::system::error_code &ec, boost::filesystem::path const &destPath, std::string const &contents)
constexpr auto kilobytes(T value) noexcept
BEAST_DEFINE_TESTSUITE(AccountTxPaging, app, xrpl)