2022-01-29 17:14:15 +01:00
|
|
|
#include <hex/test/tests.hpp>
|
|
|
|
|
|
|
|
#include <hex/helpers/file.hpp>
|
2022-03-04 11:36:37 +01:00
|
|
|
#include <hex/helpers/fs.hpp>
|
2022-01-29 17:14:15 +01:00
|
|
|
|
|
|
|
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";
|
2022-01-29 17:14:15 +01:00
|
|
|
const auto FileContent = "Hello World";
|
|
|
|
|
|
|
|
{
|
2022-03-04 14:34:37 +01:00
|
|
|
hex::fs::File file(FilePath, hex::fs::File::Mode::Create);
|
2022-01-29 17:14:15 +01:00
|
|
|
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);
|
2022-01-29 17:14:15 +01:00
|
|
|
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);
|
2022-01-29 17:14:15 +01:00
|
|
|
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);
|
2022-01-29 17:14:15 +01:00
|
|
|
if (file.isValid())
|
|
|
|
TEST_FAIL();
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_SUCCESS();
|
|
|
|
};
|