From e796e025b6d5fca1adc2ad81752aa290dc926a3f Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 11 Aug 2022 09:59:14 +0200 Subject: [PATCH] continue host fs unittests --- src/fsfw_hal/host/HostFilesystem.h | 3 ++- unittests/hal/testHostFilesystem.cpp | 25 ++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/fsfw_hal/host/HostFilesystem.h b/src/fsfw_hal/host/HostFilesystem.h index 01e37f08..4dda3ff7 100644 --- a/src/fsfw_hal/host/HostFilesystem.h +++ b/src/fsfw_hal/host/HostFilesystem.h @@ -18,7 +18,8 @@ class HostFilesystem : public HasFileSystemIF { ReturnValue_t rename(const char *oldPath, char *newPath, FileSystemArgsIF *args) override; std::error_code errorCode; - + using HasFileSystemIF::createFile; + using HasFileSystemIF::removeFile; private: }; #endif // FSFW_HAL_HOSTFILESYSTEM_H diff --git a/unittests/hal/testHostFilesystem.cpp b/unittests/hal/testHostFilesystem.cpp index 19af1c6b..a7166b01 100644 --- a/unittests/hal/testHostFilesystem.cpp +++ b/unittests/hal/testHostFilesystem.cpp @@ -1,5 +1,28 @@ #include #include "fsfw_hal/host/HostFilesystem.h" +#include -TEST_CASE("Host Filesystem", "[hal][host]") { auto hostFs = HostFilesystem(); } \ No newline at end of file +TEST_CASE("Host Filesystem", "[hal][host]") { + namespace fs = std::filesystem; + auto hostFs = HostFilesystem(); + auto tmpDir = fs::temp_directory_path(); + + SECTION("Create file") { + fs::path file = tmpDir / "hello.txt"; + FilesystemParams params(file.c_str()); + REQUIRE(hostFs.createFile(params) == result::OK); + REQUIRE(fs::exists(file)); + REQUIRE_NOTHROW(fs::remove(file)); + } + + SECTION("Remove File") { + fs::path file = tmpDir / "hello.txt"; + FilesystemParams params(file.c_str()); + REQUIRE(hostFs.createFile(params) == result::OK); + REQUIRE(fs::exists(file)); + REQUIRE(hostFs.removeFile(file.c_str()) == result::OK); + REQUIRE(not fs::exists(file)); + } + +} \ No newline at end of file