1
0
mirror of synced 2024-12-19 02:55:55 +01:00
ImHex/tests/helpers/source/file.cpp

81 lines
1.8 KiB
C++
Raw Normal View History

#include <hex/test/tests.hpp>
2023-03-13 09:25:07 +01:00
#include <wolv/io/file.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";
std::fs::create_directories(FilePath.parent_path());
{
2023-03-13 09:25:07 +01:00
wolv::io::File file(FilePath, wolv::io::File::Mode::Create);
TEST_ASSERT(file.isValid());
file.writeString(FileContent);
}
{
2023-03-13 09:25:07 +01:00
wolv::io::File file(FilePath, wolv::io::File::Mode::Read);
TEST_ASSERT(file.isValid());
TEST_ASSERT(file.readString() == FileContent);
}
{
2023-03-13 09:25:07 +01:00
wolv::io::File file(FilePath, wolv::io::File::Mode::Write);
TEST_ASSERT(file.isValid());
file.remove();
TEST_ASSERT(!file.isValid());
}
{
2023-03-13 09:25:07 +01:00
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());
{
2023-03-13 09:25:07 +01:00
wolv::io::File file(FilePath, wolv::io::File::Mode::Create);
TEST_ASSERT(file.isValid());
file.writeU8String(FileContent);
}
{
2023-03-13 09:25:07 +01:00
wolv::io::File file(FilePath, wolv::io::File::Mode::Read);
TEST_ASSERT(file.isValid());
TEST_ASSERT(file.readU8String() == FileContent);
}
{
2023-03-13 09:25:07 +01:00
wolv::io::File file(FilePath, wolv::io::File::Mode::Write);
TEST_ASSERT(file.isValid());
file.remove();
TEST_ASSERT(!file.isValid());
}
{
2023-03-13 09:25:07 +01:00
wolv::io::File file(FilePath, wolv::io::File::Mode::Read);
if (file.isValid())
TEST_FAIL();
}
TEST_SUCCESS();
};