basic host FS unittests

This commit is contained in:
2022-08-11 10:10:05 +02:00
parent e796e025b6
commit 8aaabc5d73
6 changed files with 51 additions and 7 deletions

View File

@ -1,17 +1,22 @@
#include <catch2/catch_test_macros.hpp>
#include <filesystem>
#include "fsfw_hal/host/HostFilesystem.h"
#include <filesystem>
TEST_CASE("Host Filesystem", "[hal][host]") {
namespace fs = std::filesystem;
auto hostFs = HostFilesystem();
auto tmpDir = fs::temp_directory_path();
fs::path file0 = tmpDir / "hello.txt";
fs::path file1 = tmpDir / "hello.txt";
REQUIRE_NOTHROW(fs::remove(file0));
REQUIRE_NOTHROW(fs::remove(file1));
SECTION("Create file") {
fs::path file = tmpDir / "hello.txt";
FilesystemParams params(file.c_str());
REQUIRE(hostFs.createFile(params) == result::OK);
CHECK(fs::is_regular_file(file));
REQUIRE(fs::exists(file));
REQUIRE_NOTHROW(fs::remove(file));
}
@ -20,9 +25,38 @@ TEST_CASE("Host Filesystem", "[hal][host]") {
fs::path file = tmpDir / "hello.txt";
FilesystemParams params(file.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));
}
SECTION("Create Directory") {
fs::path dirPath = tmpDir / "test_dir";
FilesystemParams params(dirPath.c_str());
REQUIRE(hostFs.createDirectory(params) == result::OK);
CHECK(fs::is_directory(dirPath));
REQUIRE(fs::exists(dirPath));
REQUIRE_NOTHROW(fs::remove(dirPath));
}
SECTION("Remove Directory") {
fs::path dirPath = tmpDir / "test_dir";
FilesystemParams params(dirPath.c_str());
REQUIRE(hostFs.createDirectory(params) == result::OK);
REQUIRE(fs::exists(dirPath));
REQUIRE(hostFs.removeDirectory(params) == result::OK);
REQUIRE(not fs::exists(dirPath));
}
SECTION("Rename File") {
fs::path file = tmpDir / "hello.txt";
fs::path newFile = tmpDir / "hello2.txt";
FilesystemParams params(file.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));
}
}

View File

@ -64,7 +64,8 @@ ReturnValue_t FilesystemMock::removeDirectory(FilesystemParams params, bool dele
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t FilesystemMock::rename(const char *oldPath, char *newPath, FileSystemArgsIF *args) {
ReturnValue_t FilesystemMock::rename(const char *oldPath, const char *newPath,
FileSystemArgsIF *args) {
renameQueue.push(RenameInfo(oldPath, newPath));
return HasReturnvaluesIF::RETURN_OK;
}

View File

@ -60,7 +60,7 @@ class FilesystemMock : public HasFileSystemIF {
ReturnValue_t removeFile(const char *path, FileSystemArgsIF *args) override;
ReturnValue_t createDirectory(FilesystemParams params, bool createParentDirs) override;
ReturnValue_t removeDirectory(FilesystemParams params, bool deleteRecurively) override;
ReturnValue_t rename(const char *oldPath, char *newPath, FileSystemArgsIF *args) override;
ReturnValue_t rename(const char *oldPath, const char *newPath, FileSystemArgsIF *args) override;
void reset();