1
0
mirror of synced 2024-11-27 17:10:51 +01:00
ImHex/tests/helpers/source/file.cpp

42 lines
939 B
C++
Raw Normal View History

#include <hex/test/tests.hpp>
#include <hex/helpers/file.hpp>
#include <hex/helpers/fs.hpp>
using namespace std::literals::string_literals;
TEST_SEQUENCE("FileAccess") {
2022-03-04 14:34:37 +01:00
const auto FilePath = std::fs::current_path() / "file.txt";
const auto FileContent = "Hello World";
{
2022-03-04 14:34:37 +01:00
hex::fs::File file(FilePath, hex::fs::File::Mode::Create);
TEST_ASSERT(file.isValid());
file.write(FileContent);
}
{
2022-03-04 14:34:37 +01:00
hex::fs::File file(FilePath, hex::fs::File::Mode::Read);
TEST_ASSERT(file.isValid());
TEST_ASSERT(file.readString() == FileContent);
}
{
2022-03-04 14:34:37 +01:00
hex::fs::File file(FilePath, hex::fs::File::Mode::Write);
TEST_ASSERT(file.isValid());
file.remove();
TEST_ASSERT(!file.isValid());
}
{
2022-03-04 14:34:37 +01:00
hex::fs::File file(FilePath, hex::fs::File::Mode::Read);
if (file.isValid())
TEST_FAIL();
}
TEST_SUCCESS();
};