mirror of
https://github.com/XRPLF/rippled.git
synced 2026-06-06 18:26:51 +00:00
Agent-Logs-Url: https://github.com/XRPLF/rippled/sessions/ec2fa57d-2d9c-4388-b4e1-90a40f55b5e8 Co-authored-by: mvadari <8029314+mvadari@users.noreply.github.com>
62 lines
1.5 KiB
C++
62 lines
1.5 KiB
C++
#include <test/unit_test/FileDirGuard.h>
|
|
|
|
#include <xrpl/basics/ByteUtilities.h>
|
|
#include <xrpl/basics/FileUtilities.h>
|
|
#include <xrpl/beast/unit_test/suite.h>
|
|
|
|
#include <system_error>
|
|
|
|
namespace xrpl {
|
|
|
|
class FileUtilities_test : public beast::unit_test::suite
|
|
{
|
|
public:
|
|
void
|
|
testGetFileContents()
|
|
{
|
|
using namespace xrpl::detail;
|
|
|
|
constexpr char const* expectedContents = "This file is very short. That's all we need.";
|
|
|
|
FileDirGuard const file(
|
|
*this, "test_file", "test.txt", "This is temporary text that should get overwritten");
|
|
|
|
std::error_code ec;
|
|
auto const path = file.file();
|
|
|
|
writeFileContents(ec, path, expectedContents);
|
|
BEAST_EXPECT(!ec);
|
|
|
|
{
|
|
// Test with no max
|
|
auto const good = getFileContents(ec, path);
|
|
BEAST_EXPECT(!ec);
|
|
BEAST_EXPECT(good == expectedContents);
|
|
}
|
|
|
|
{
|
|
// Test with large max
|
|
auto const good = getFileContents(ec, path, kilobytes(1));
|
|
BEAST_EXPECT(!ec);
|
|
BEAST_EXPECT(good == expectedContents);
|
|
}
|
|
|
|
{
|
|
// Test with small max
|
|
auto const bad = getFileContents(ec, path, 16);
|
|
BEAST_EXPECT(ec && ec.value() == static_cast<int>(std::errc::file_too_large));
|
|
BEAST_EXPECT(bad.empty());
|
|
}
|
|
}
|
|
|
|
void
|
|
run() override
|
|
{
|
|
testGetFileContents();
|
|
}
|
|
};
|
|
|
|
BEAST_DEFINE_TESTSUITE(FileUtilities, basics, xrpl);
|
|
|
|
} // namespace xrpl
|