82 lines
1.9 KiB
C++
82 lines
1.9 KiB
C++
#include <hex/test/tests.hpp>
|
|
|
|
#include <wolv/io/file.hpp>
|
|
#include <hex/helpers/fs.hpp>
|
|
|
|
using namespace std::literals::string_literals;
|
|
|
|
TEST_SEQUENCE("FileAccess") {
|
|
const auto FilePath = std::fs::current_path() / "file.txt";
|
|
const auto FileContent = "Hello World";
|
|
|
|
std::fs::create_directories(FilePath.parent_path());
|
|
|
|
{
|
|
wolv::io::File file(FilePath, wolv::io::File::Mode::Create);
|
|
TEST_ASSERT(file.isValid());
|
|
|
|
file.write(FileContent);
|
|
}
|
|
|
|
{
|
|
wolv::io::File file(FilePath, wolv::io::File::Mode::Read);
|
|
TEST_ASSERT(file.isValid());
|
|
|
|
TEST_ASSERT(file.readString() == FileContent);
|
|
}
|
|
|
|
{
|
|
wolv::io::File file(FilePath, wolv::io::File::Mode::Write);
|
|
TEST_ASSERT(file.isValid());
|
|
|
|
|
|
file.remove();
|
|
TEST_ASSERT(!file.isValid());
|
|
}
|
|
|
|
{
|
|
wolv::io::File file(FilePath, wolv::io::File::Mode::Read);
|
|
if (file.isValid())
|
|
TEST_FAIL();
|
|
}
|
|
|
|
TEST_SUCCESS();
|
|
};
|
|
|
|
TEST_SEQUENCE("UTF-8 Path") {
|
|
const auto FilePath = std::fs::current_path() / u8"读写汉字" / u8"привет.txt";
|
|
const auto FileContent = u8"שלום עולם";
|
|
|
|
std::fs::create_directories(FilePath.parent_path());
|
|
|
|
{
|
|
wolv::io::File file(FilePath, wolv::io::File::Mode::Create);
|
|
TEST_ASSERT(file.isValid());
|
|
|
|
file.write(FileContent);
|
|
}
|
|
|
|
{
|
|
wolv::io::File file(FilePath, wolv::io::File::Mode::Read);
|
|
TEST_ASSERT(file.isValid());
|
|
|
|
TEST_ASSERT(file.readU8String() == FileContent);
|
|
}
|
|
|
|
{
|
|
wolv::io::File file(FilePath, wolv::io::File::Mode::Write);
|
|
TEST_ASSERT(file.isValid());
|
|
|
|
|
|
file.remove();
|
|
TEST_ASSERT(!file.isValid());
|
|
}
|
|
|
|
{
|
|
wolv::io::File file(FilePath, wolv::io::File::Mode::Read);
|
|
if (file.isValid())
|
|
TEST_FAIL();
|
|
}
|
|
|
|
TEST_SUCCESS();
|
|
}; |