2022-01-29 17:14:15 +01:00
|
|
|
#include <hex/test/tests.hpp>
|
|
|
|
|
2023-03-13 09:25:07 +01:00
|
|
|
#include <wolv/io/file.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-07-02 10:05:25 +02:00
|
|
|
std::fs::create_directories(FilePath.parent_path());
|
|
|
|
|
2022-01-29 17:14:15 +01:00
|
|
|
{
|
2023-03-13 09:25:07 +01:00
|
|
|
wolv::io::File file(FilePath, wolv::io::File::Mode::Create);
|
2022-01-29 17:14:15 +01:00
|
|
|
TEST_ASSERT(file.isValid());
|
|
|
|
|
2023-03-23 11:23:07 +01:00
|
|
|
file.writeString(FileContent);
|
2022-01-29 17:14:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2023-03-13 09:25:07 +01:00
|
|
|
wolv::io::File file(FilePath, wolv::io::File::Mode::Read);
|
2022-01-29 17:14:15 +01:00
|
|
|
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);
|
2022-01-29 17:14:15 +01:00
|
|
|
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);
|
2022-01-29 17:14:15 +01:00
|
|
|
if (file.isValid())
|
|
|
|
TEST_FAIL();
|
|
|
|
}
|
|
|
|
|
2022-07-02 10:05:25 +02:00
|
|
|
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);
|
2022-07-02 10:05:25 +02:00
|
|
|
TEST_ASSERT(file.isValid());
|
|
|
|
|
2023-03-23 11:23:07 +01:00
|
|
|
file.writeU8String(FileContent);
|
2022-07-02 10:05:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2023-03-13 09:25:07 +01:00
|
|
|
wolv::io::File file(FilePath, wolv::io::File::Mode::Read);
|
2022-07-02 10:05:25 +02:00
|
|
|
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);
|
2022-07-02 10:05:25 +02:00
|
|
|
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);
|
2022-07-02 10:05:25 +02:00
|
|
|
if (file.isValid())
|
|
|
|
TEST_FAIL();
|
|
|
|
}
|
|
|
|
|
2022-01-29 17:14:15 +01:00
|
|
|
TEST_SUCCESS();
|
|
|
|
};
|