continued host FS test
This commit is contained in:
@ -8,55 +8,66 @@ TEST_CASE("Host Filesystem", "[hal][host]") {
|
||||
auto hostFs = HostFilesystem();
|
||||
auto tmpDir = fs::temp_directory_path();
|
||||
fs::path file0 = tmpDir / "hello.txt";
|
||||
fs::path file1 = tmpDir / "hello.txt";
|
||||
fs::path file1 = tmpDir / "hello2.txt";
|
||||
fs::path dir0 = tmpDir / "test_dir";
|
||||
REQUIRE_NOTHROW(fs::remove(file0));
|
||||
REQUIRE_NOTHROW(fs::remove(file1));
|
||||
REQUIRE_NOTHROW(fs::remove(dir0));
|
||||
|
||||
SECTION("Create file") {
|
||||
fs::path file = tmpDir / "hello.txt";
|
||||
FilesystemParams params(file.c_str());
|
||||
FilesystemParams params(file0.c_str());
|
||||
REQUIRE(hostFs.createFile(params) == result::OK);
|
||||
CHECK(fs::is_regular_file(file));
|
||||
REQUIRE(fs::exists(file));
|
||||
REQUIRE_NOTHROW(fs::remove(file));
|
||||
CHECK(fs::is_regular_file(file0));
|
||||
REQUIRE(fs::exists(file0));
|
||||
REQUIRE_NOTHROW(fs::remove(file0));
|
||||
}
|
||||
|
||||
SECTION("Remove File") {
|
||||
fs::path file = tmpDir / "hello.txt";
|
||||
FilesystemParams params(file.c_str());
|
||||
FilesystemParams params(file0.c_str());
|
||||
REQUIRE(hostFs.createFile(params) == result::OK);
|
||||
CHECK(fs::is_regular_file(file));
|
||||
REQUIRE(fs::exists(file));
|
||||
REQUIRE(hostFs.removeFile(file.c_str()) == result::OK);
|
||||
REQUIRE(not fs::exists(file));
|
||||
CHECK(fs::is_regular_file(file0));
|
||||
REQUIRE(fs::exists(file0));
|
||||
REQUIRE(hostFs.removeFile(file0.c_str()) == result::OK);
|
||||
REQUIRE(not fs::exists(file0));
|
||||
}
|
||||
|
||||
SECTION("Create Directory") {
|
||||
fs::path dirPath = tmpDir / "test_dir";
|
||||
FilesystemParams params(dirPath.c_str());
|
||||
FilesystemParams params(dir0.c_str());
|
||||
REQUIRE(hostFs.createDirectory(params) == result::OK);
|
||||
CHECK(fs::is_directory(dirPath));
|
||||
REQUIRE(fs::exists(dirPath));
|
||||
REQUIRE_NOTHROW(fs::remove(dirPath));
|
||||
CHECK(fs::is_directory(dir0));
|
||||
REQUIRE(fs::exists(dir0));
|
||||
REQUIRE_NOTHROW(fs::remove(dir0));
|
||||
}
|
||||
|
||||
SECTION("Remove Directory") {
|
||||
fs::path dirPath = tmpDir / "test_dir";
|
||||
FilesystemParams params(dirPath.c_str());
|
||||
FilesystemParams params(dir0.c_str());
|
||||
REQUIRE(hostFs.createDirectory(params) == result::OK);
|
||||
REQUIRE(fs::exists(dirPath));
|
||||
REQUIRE(fs::exists(dir0));
|
||||
REQUIRE(hostFs.removeDirectory(params) == result::OK);
|
||||
REQUIRE(not fs::exists(dirPath));
|
||||
REQUIRE(not fs::exists(dir0));
|
||||
}
|
||||
|
||||
SECTION("Rename File") {
|
||||
fs::path file = tmpDir / "hello.txt";
|
||||
fs::path newFile = tmpDir / "hello2.txt";
|
||||
FilesystemParams params(file.c_str());
|
||||
FilesystemParams params(file0.c_str());
|
||||
REQUIRE(hostFs.createFile(params) == result::OK);
|
||||
CHECK(fs::is_regular_file(file));
|
||||
REQUIRE(fs::exists(file));
|
||||
REQUIRE(hostFs.rename(file.c_str(), newFile.c_str()) == result::OK);
|
||||
REQUIRE_NOTHROW(fs::remove(newFile));
|
||||
CHECK(fs::is_regular_file(file0));
|
||||
REQUIRE(fs::exists(file0));
|
||||
REQUIRE(hostFs.rename(file0.c_str(), file1.c_str()) == result::OK);
|
||||
REQUIRE_NOTHROW(fs::remove(file1));
|
||||
}
|
||||
|
||||
SECTION("Write To File") {
|
||||
std::string data = "hello world!";
|
||||
FileOpParams params(file0.c_str(), data.size());
|
||||
REQUIRE(hostFs.createFile(params.fsParams) == result::OK);
|
||||
CHECK(fs::is_regular_file(file0));
|
||||
REQUIRE(fs::exists(file0));
|
||||
hostFs.writeToFile(params, reinterpret_cast<const uint8_t*>(data.c_str()));
|
||||
// TODO: Read back file and verify content
|
||||
REQUIRE_NOTHROW(fs::remove(file1));
|
||||
}
|
||||
|
||||
REQUIRE_NOTHROW(fs::remove(file0));
|
||||
REQUIRE_NOTHROW(fs::remove(file1));
|
||||
REQUIRE_NOTHROW(fs::remove(dir0));
|
||||
}
|
Reference in New Issue
Block a user