diff --git a/src/fsfw/filesystem/HasFileSystemIF.h b/src/fsfw/filesystem/HasFileSystemIF.h index 8eef6f22d..6f7112ad4 100644 --- a/src/fsfw/filesystem/HasFileSystemIF.h +++ b/src/fsfw/filesystem/HasFileSystemIF.h @@ -2,7 +2,6 @@ #define FSFW_MEMORY_HASFILESYSTEMIF_H_ #include -#include #include "FileSystemArgsIF.h" #include "fsfw/ipc/MessageQueueIF.h" @@ -11,17 +10,16 @@ #include "fsfw/returnvalues/returnvalue.h" struct FilesystemParams { - explicit FilesystemParams(const std::filesystem::path::value_type* path) : path(path) {} + explicit FilesystemParams(const char* path) : path(path) {} - const std::filesystem::path::value_type* path; + const char* path; FileSystemArgsIF* args = nullptr; }; struct FileOpParams { - FileOpParams(const std::filesystem::path::value_type* path, size_t size) - : fsParams(path), size(size) {} + FileOpParams(const char* path, size_t size) : fsParams(path), size(size) {} - [[nodiscard]] const std::filesystem::path::value_type* path() const { return fsParams.path; } + [[nodiscard]] const char* path() const { return fsParams.path; } [[nodiscard]] FileSystemArgsIF* args() const { return fsParams.args; } @@ -141,11 +139,8 @@ class HasFileSystemIF { * @param args Any other arguments which an implementation might require * @return */ - virtual ReturnValue_t removeFile(const std::filesystem::path::value_type* path, - FileSystemArgsIF* args) = 0; - virtual ReturnValue_t removeFile(const std::filesystem::path::value_type* path) { - return removeFile(path, nullptr); - } + virtual ReturnValue_t removeFile(const char* path, FileSystemArgsIF* args) = 0; + virtual ReturnValue_t removeFile(const char* path) { return removeFile(path, nullptr); } /** * @brief Generic function to create a directory @@ -170,12 +165,10 @@ class HasFileSystemIF { return removeDirectory(params, false); } - virtual ReturnValue_t rename(const std::filesystem::path::value_type* oldPath, - const std::filesystem::path::value_type* newPath) { + virtual ReturnValue_t rename(const char* oldPath, const char* newPath) { return rename(oldPath, newPath, nullptr); } - virtual ReturnValue_t rename(const std::filesystem::path::value_type* oldPath, - const std::filesystem::path::value_type* newPath, + virtual ReturnValue_t rename(const char* oldPath, const char* newPath, FileSystemArgsIF* args) = 0; }; diff --git a/src/fsfw/osal/Endiness.h b/src/fsfw/osal/Endiness.h index 29118c3fc..b5d35f459 100644 --- a/src/fsfw/osal/Endiness.h +++ b/src/fsfw/osal/Endiness.h @@ -24,8 +24,11 @@ #else #ifdef WIN32 -#include +// Thanks, windows +// clang-format off #include +#include +// clang-format on #if REG_DWORD == REG_DWORD_LITTLE_ENDIAN #define BYTE_ORDER_SYSTEM LITTLE_ENDIAN #else diff --git a/src/fsfw/osal/common/TcpTmTcServer.cpp b/src/fsfw/osal/common/TcpTmTcServer.cpp index 7dd72c2cc..35e65ece8 100644 --- a/src/fsfw/osal/common/TcpTmTcServer.cpp +++ b/src/fsfw/osal/common/TcpTmTcServer.cpp @@ -16,7 +16,6 @@ #ifdef PLATFORM_WIN #include -#include typedef SSIZE_T ssize_t; #elif defined(PLATFORM_UNIX) #include diff --git a/src/fsfw/osal/windows/winTaskHelpers.h b/src/fsfw/osal/windows/winTaskHelpers.h index 892f3c419..9e00a1dae 100644 --- a/src/fsfw/osal/windows/winTaskHelpers.h +++ b/src/fsfw/osal/windows/winTaskHelpers.h @@ -5,8 +5,11 @@ #ifdef _WIN32 -#include +// Thanks, windows +// clang-format off #include +#include +// clang-format on namespace tasks { diff --git a/src/fsfw/timemanager/CMakeLists.txt b/src/fsfw/timemanager/CMakeLists.txt index 7e38cc6ac..b4a90f2ae 100644 --- a/src/fsfw/timemanager/CMakeLists.txt +++ b/src/fsfw/timemanager/CMakeLists.txt @@ -1,4 +1,4 @@ target_sources( ${LIB_FSFW_NAME} PRIVATE CCSDSTime.cpp Countdown.cpp Stopwatch.cpp TimeMessage.cpp - CdsShortTimeStamper.cpp ClockCommon.cpp) + CdsShortTimeStamper.cpp ClockCommon.cpp boost_timegm.cpp) diff --git a/src/fsfw/timemanager/ClockCommon.cpp b/src/fsfw/timemanager/ClockCommon.cpp index ec09d0714..7a3cddac1 100644 --- a/src/fsfw/timemanager/ClockCommon.cpp +++ b/src/fsfw/timemanager/ClockCommon.cpp @@ -1,6 +1,8 @@ #include #include +#include "boost_timegm.h" + #include "fsfw/ipc/MutexGuard.h" #include "fsfw/timemanager/Clock.h" @@ -56,8 +58,9 @@ ReturnValue_t Clock::getLeapSeconds(uint16_t* leapSeconds_) { ReturnValue_t Clock::convertTimevalToTimeOfDay(const timeval* from, TimeOfDay_t* to) { struct tm time_tm; // WINDOWS does not provide gmtime_r, but gmtime_s -#ifdef PLATFORM_WIN - errno_t result = gmtime_s(&time_tm, &from->tv_sec); +#ifdef _MSC_VER + time_t seconds = from->tv_sec; + errno_t result = gmtime_s(&time_tm, &seconds); if (result != 0) { return returnvalue::FAILED; } @@ -92,28 +95,11 @@ ReturnValue_t Clock::convertTimeOfDayToTimeval(const TimeOfDay_t* from, timeval* time_tm.tm_isdst = 0; - // Windows: - // time_t seconds = _mkgmtime(&time_tm); - // Glibc: - // time_t seconds = timegm(&time_tm); - // Portable (?) - char* tz; - tz = getenv("TZ"); - setenv("TZ", "", 1); - tzset(); - time_t seconds = mktime(&time_tm); - if (tz) - setenv("TZ", tz, 1); - else - unsetenv("TZ"); - tzset(); + time_t seconds = internal_timegm(&time_tm); + to->tv_sec = seconds; to->tv_usec = from->usecond; - if (seconds == (time_t)-1) { - return returnvalue::FAILED; - } - return returnvalue::OK; } diff --git a/src/fsfw/timemanager/TimeReaderIF.h b/src/fsfw/timemanager/TimeReaderIF.h index 9273779d0..3f8c696a6 100644 --- a/src/fsfw/timemanager/TimeReaderIF.h +++ b/src/fsfw/timemanager/TimeReaderIF.h @@ -1,7 +1,7 @@ #ifndef FSFW_TIMEMANAGER_TIMEREADERIF_H #define FSFW_TIMEMANAGER_TIMEREADERIF_H -#include +#include #include #include @@ -10,8 +10,8 @@ #ifdef PLATFORM_WIN // wtf? Required for timeval! -#include #include +#include #endif #include "TimeStampIF.h" diff --git a/src/fsfw/timemanager/boost_timegm.cpp b/src/fsfw/timemanager/boost_timegm.cpp new file mode 100644 index 000000000..c987a6e90 --- /dev/null +++ b/src/fsfw/timemanager/boost_timegm.cpp @@ -0,0 +1,69 @@ +// (C) Copyright Howard Hinnant +// (C) Copyright 2010-2011 Vicente J. Botet Escriba +// Use, modification and distribution are subject to the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt). + +//===-------------------------- locale ------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// This code was adapted by Vicente from Howard Hinnant's experimental work +// on chrono i/o to Boost and some functions from libc++/locale to emulate the missing +// time_get::get() + + +#include "boost_timegm.h" + +#include + + +int32_t is_leap(int32_t year) { + if (year % 400 == 0) return 1; + if (year % 100 == 0) return 0; + if (year % 4 == 0) return 1; + return 0; +} +int32_t days_from_0(int32_t year) { + year--; + return 365 * year + (year / 400) - (year / 100) + (year / 4); +} +int32_t days_from_1970(int32_t year) { + static const int32_t days_from_0_to_1970 = days_from_0(1970); + return days_from_0(year) - days_from_0_to_1970; +} +int32_t days_from_1jan(int32_t year, int32_t month, int32_t day) { + static const int32_t days[2][12] = {{0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}, + {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335}}; + + return days[is_leap(year)][month - 1] + day - 1; +} + + +time_t internal_timegm(std::tm const *t) { + int year = t->tm_year + 1900; + int month = t->tm_mon; + if (month > 11) { + year += month / 12; + month %= 12; + } else if (month < 0) { + int years_diff = (-month + 11) / 12; + year -= years_diff; + month += 12 * years_diff; + } + month++; + int day = t->tm_mday; + int day_of_year = days_from_1jan(year, month, day); + int days_since_epoch = days_from_1970(year) + day_of_year; + + time_t seconds_in_day = 3600 * 24; + time_t result = + seconds_in_day * days_since_epoch + 3600 * t->tm_hour + 60 * t->tm_min + t->tm_sec; + + return result; +} \ No newline at end of file diff --git a/src/fsfw/timemanager/boost_timegm.h b/src/fsfw/timemanager/boost_timegm.h new file mode 100644 index 000000000..6e65ab937 --- /dev/null +++ b/src/fsfw/timemanager/boost_timegm.h @@ -0,0 +1,5 @@ +#include + + + +time_t internal_timegm(std::tm const *t); \ No newline at end of file diff --git a/src/fsfw_hal/host/HostFilesystem.cpp b/src/fsfw_hal/host/HostFilesystem.cpp index 7840d9984..a271fe5ff 100644 --- a/src/fsfw_hal/host/HostFilesystem.cpp +++ b/src/fsfw_hal/host/HostFilesystem.cpp @@ -69,7 +69,7 @@ ReturnValue_t HostFilesystem::createFile(FilesystemParams params, const uint8_t return returnvalue::OK; } -ReturnValue_t HostFilesystem::removeFile(const std::filesystem::path::value_type *path_, +ReturnValue_t HostFilesystem::removeFile(const char *path_, FileSystemArgsIF *args) { if (path_ == nullptr) { return returnvalue::FAILED; @@ -133,8 +133,7 @@ ReturnValue_t HostFilesystem::removeDirectory(FilesystemParams params, bool dele return HasFileSystemIF::GENERIC_DIR_ERROR; } -ReturnValue_t HostFilesystem::rename(const std::filesystem::path::value_type *oldPath_, - const std::filesystem::path::value_type *newPath_, +ReturnValue_t HostFilesystem::rename(const char *oldPath_, const char *newPath_, FileSystemArgsIF *args) { if (oldPath_ == nullptr or newPath_ == nullptr) { return returnvalue::FAILED; diff --git a/src/fsfw_hal/host/HostFilesystem.h b/src/fsfw_hal/host/HostFilesystem.h index 2fa38b14d..57b9f5b09 100644 --- a/src/fsfw_hal/host/HostFilesystem.h +++ b/src/fsfw_hal/host/HostFilesystem.h @@ -15,12 +15,11 @@ class HostFilesystem : public HasFileSystemIF { ReturnValue_t readFromFile(FileOpParams fileOpInfo, uint8_t **buffer, size_t &readSize, size_t maxSize) override; ReturnValue_t createFile(FilesystemParams params, const uint8_t *data, size_t size) override; - ReturnValue_t removeFile(const std::filesystem::path::value_type *path, + 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 std::filesystem::path::value_type *oldPath, - const std::filesystem::path::value_type *newPath, + ReturnValue_t rename(const char *oldPath, const char *newPath, FileSystemArgsIF *args) override; std::error_code errorCode; diff --git a/unittests/hal/testFsMock.cpp b/unittests/hal/testFsMock.cpp index 2ebcd231b..bd15fb59e 100644 --- a/unittests/hal/testFsMock.cpp +++ b/unittests/hal/testFsMock.cpp @@ -11,7 +11,9 @@ TEST_CASE("Filesystem Mock", "[mocks]") { SECTION("Create File") { FilesystemParams params("hello.txt"); CHECK(fsMock.createFile(params) == returnvalue::OK); - auto iter = fsMock.fileMap.find("hello.txt"); + std::string filename_c("hello.txt"); + std::filesystem::path::string_type filename(filename_c.cbegin(), filename_c.cend()); + auto iter = fsMock.fileMap.find(filename); REQUIRE(iter != fsMock.fileMap.end()); FilesystemMock::FileInfo &stats = iter->second; CHECK(stats.fileSegQueue.empty()); @@ -23,7 +25,9 @@ TEST_CASE("Filesystem Mock", "[mocks]") { FileOpParams params("hello.txt", testData.size()); CHECK(fsMock.writeToFile(params, reinterpret_cast(testData.data())) == returnvalue::OK); - auto iter = fsMock.fileMap.find("hello.txt"); + std::string filename_c("hello.txt"); + std::filesystem::path::string_type filename(filename_c.cbegin(), filename_c.cend()); + auto iter = fsMock.fileMap.find(filename); REQUIRE(iter != fsMock.fileMap.end()); FilesystemMock::FileInfo &stats = iter->second; CHECK(not stats.fileSegQueue.empty()); @@ -40,7 +44,9 @@ TEST_CASE("Filesystem Mock", "[mocks]") { FilesystemParams params("hello"); CHECK(fsMock.createDirectory(params) == returnvalue::OK); REQUIRE(not fsMock.dirMap.empty()); - auto iter = fsMock.dirMap.find("hello"); + std::string filename_c("hello"); + std::filesystem::path::string_type filename(filename_c.cbegin(), filename_c.cend()); + auto iter = fsMock.dirMap.find(filename); REQUIRE(iter != fsMock.dirMap.end()); auto &dirInfo = iter->second; CHECK(dirInfo.createCallCount == 1); diff --git a/unittests/hal/testHostFilesystem.cpp b/unittests/hal/testHostFilesystem.cpp index 96d810764..e011eaa65 100644 --- a/unittests/hal/testHostFilesystem.cpp +++ b/unittests/hal/testHostFilesystem.cpp @@ -26,30 +26,30 @@ TEST_CASE("Host Filesystem", "[hal][host]") { REQUIRE_NOTHROW(fs::remove_all(dir0)); SECTION("Create file") { - FilesystemParams params(file0.c_str()); + FilesystemParams params(file0.string().c_str()); REQUIRE(hostFs.createFile(params) == returnvalue::OK); CHECK(fs::is_regular_file(file0)); REQUIRE(fs::exists(file0)); } SECTION("Remove File") { - FilesystemParams params(file0.c_str()); + FilesystemParams params(file0.string().c_str()); REQUIRE(hostFs.createFile(params) == returnvalue::OK); CHECK(fs::is_regular_file(file0)); REQUIRE(fs::exists(file0)); - REQUIRE(hostFs.removeFile(file0.c_str()) == returnvalue::OK); + REQUIRE(hostFs.removeFile(file0.string().c_str()) == returnvalue::OK); REQUIRE(not fs::exists(file0)); } SECTION("Create Directory") { - FilesystemParams params(dir0.c_str()); + FilesystemParams params(dir0.string().c_str()); REQUIRE(hostFs.createDirectory(params) == returnvalue::OK); CHECK(fs::is_directory(dir0)); REQUIRE(fs::exists(dir0)); } SECTION("Remove Directory") { - FilesystemParams params(dir0.c_str()); + FilesystemParams params(dir0.string().c_str()); REQUIRE(hostFs.createDirectory(params) == returnvalue::OK); REQUIRE(fs::exists(dir0)); REQUIRE(hostFs.removeDirectory(params) == returnvalue::OK); @@ -57,16 +57,16 @@ TEST_CASE("Host Filesystem", "[hal][host]") { } SECTION("Rename File") { - FilesystemParams params(file0.c_str()); + FilesystemParams params(file0.string().c_str()); REQUIRE(hostFs.createFile(params) == returnvalue::OK); CHECK(fs::is_regular_file(file0)); REQUIRE(fs::exists(file0)); - REQUIRE(hostFs.rename(file0.c_str(), file1.c_str()) == returnvalue::OK); + REQUIRE(hostFs.rename(file0.string().c_str(), file1.string().c_str()) == returnvalue::OK); } SECTION("Write To File") { std::string data = "hello world!"; - FileOpParams params(file0.c_str(), data.size()); + FileOpParams params(file0.string().c_str(), data.size()); REQUIRE(hostFs.createFile(params.fsParams) == returnvalue::OK); CHECK(fs::is_regular_file(file0)); REQUIRE(fs::exists(file0)); @@ -88,7 +88,7 @@ TEST_CASE("Host Filesystem", "[hal][host]") { for (uint8_t& byte : randData) { byte = distU8(rng); } - FileOpParams params(file0.c_str(), randData.size() - 256); + FileOpParams params(file0.string().c_str(), randData.size() - 256); REQUIRE(hostFs.createFile(params.fsParams) == returnvalue::OK); CHECK(fs::is_regular_file(file0)); REQUIRE(fs::exists(file0)); @@ -107,7 +107,7 @@ TEST_CASE("Host Filesystem", "[hal][host]") { SECTION("Read From File") { std::string data = "hello world!"; - FileOpParams params(file0.c_str(), data.size()); + FileOpParams params(file0.string().c_str(), data.size()); REQUIRE(hostFs.createFile(params.fsParams) == returnvalue::OK); CHECK(fs::is_regular_file(file0)); ofstream of(file0); @@ -138,35 +138,35 @@ TEST_CASE("Host Filesystem", "[hal][host]") { } SECTION("Create File but already exists") { - FilesystemParams params(file0.c_str()); + FilesystemParams params(file0.string().c_str()); REQUIRE(hostFs.createFile(params) == returnvalue::OK); REQUIRE(hostFs.createFile(params) == HasFileSystemIF::FILE_ALREADY_EXISTS); } SECTION("Remove File but does not exist") { - REQUIRE(hostFs.removeFile(file0.c_str()) == HasFileSystemIF::FILE_DOES_NOT_EXIST); + REQUIRE(hostFs.removeFile(file0.string().c_str()) == HasFileSystemIF::FILE_DOES_NOT_EXIST); } SECTION("Create Directory but already exists") { - FileOpParams params(file0.c_str(), 12); + FileOpParams params(file0.string().c_str(), 12); REQUIRE(hostFs.createDirectory(params.fsParams) == returnvalue::OK); REQUIRE(hostFs.createDirectory(params.fsParams) == HasFileSystemIF::DIRECTORY_ALREADY_EXISTS); } SECTION("Remove Directory but does not exist") { - FilesystemParams params(dir0.c_str()); + FilesystemParams params(dir0.string().c_str()); REQUIRE(hostFs.removeDirectory(params) == HasFileSystemIF::DIRECTORY_DOES_NOT_EXIST); } SECTION("Remove Directory but is file") { ofstream of(file0); - FilesystemParams params(file0.c_str()); + FilesystemParams params(file0.string().c_str()); REQUIRE(hostFs.removeDirectory(params) == HasFileSystemIF::NOT_A_DIRECTORY); } SECTION("Read from file but does not exist") { std::string data = "hello world!"; - FileOpParams params(file0.c_str(), data.size()); + FileOpParams params(file0.string().c_str(), data.size()); std::array readBuf{}; uint8_t* readPtr = readBuf.data(); size_t readSize = 0; @@ -176,39 +176,41 @@ TEST_CASE("Host Filesystem", "[hal][host]") { SECTION("Write to file but does not exist") { std::string data = "hello world!"; - FileOpParams params(file0.c_str(), data.size()); + FileOpParams params(file0.string().c_str(), data.size()); CHECK(hostFs.writeToFile(params, reinterpret_cast(data.c_str())) == HasFileSystemIF::FILE_DOES_NOT_EXIST); } SECTION("Remove recursively") { - fs::create_directory(dir0.c_str()); + fs::create_directory(dir0.string().c_str()); ofstream of(fileInDir0); CHECK(fs::is_directory(dir0)); CHECK(fs::is_regular_file(fileInDir0)); - REQUIRE(hostFs.removeDirectory(FilesystemParams(dir0.c_str()), true) == returnvalue::OK); + REQUIRE(hostFs.removeDirectory(FilesystemParams(dir0.string().c_str()), true) == + returnvalue::OK); CHECK(not fs::is_directory(dir0)); CHECK(not fs::is_regular_file(fileInDir0)); } SECTION("Non-Recursive Removal Fails") { - fs::create_directory(dir0.c_str()); + fs::create_directory(dir0.string().c_str()); ofstream of(fileInDir0); CHECK(fs::is_directory(dir0)); CHECK(fs::is_regular_file(fileInDir0)); - REQUIRE(hostFs.removeDirectory(FilesystemParams(dir0.c_str())) == + REQUIRE(hostFs.removeDirectory(FilesystemParams(dir0.string().c_str())) == HasFileSystemIF::DIRECTORY_NOT_EMPTY); } SECTION("Create directory with parent directory") { - CHECK(hostFs.createDirectory(FilesystemParams(dirWithParent.c_str()), true) == returnvalue::OK); + CHECK(hostFs.createDirectory(FilesystemParams(dirWithParent.string().c_str()), true) == + returnvalue::OK); CHECK(fs::is_directory(dir0)); CHECK(fs::is_directory(dirWithParent)); } SECTION("Read but provided buffer too small") { std::string data = "hello world!"; - FileOpParams params(file0.c_str(), data.size()); + FileOpParams params(file0.string().c_str(), data.size()); ofstream of(file0); of.write(data.c_str(), static_cast(data.size())); of.close(); diff --git a/unittests/mocks/FilesystemMock.cpp b/unittests/mocks/FilesystemMock.cpp index c2f63e14b..8039d6d08 100644 --- a/unittests/mocks/FilesystemMock.cpp +++ b/unittests/mocks/FilesystemMock.cpp @@ -6,14 +6,14 @@ ReturnValue_t FilesystemMock::feedFile(const std::string &filename, std::ifstream &file) { // not multibyte encoding safe! - std::basic_string native_filename(filename.begin(), + std::filesystem::path::string_type native_filename(filename.begin(), filename.end()); if (not std::filesystem::exists(native_filename)) { return returnvalue::FAILED; } size_t fileSize = std::filesystem::file_size(native_filename); - FileOpParams params(native_filename.c_str(), fileSize); + FileOpParams params(filename.c_str(), fileSize); std::vector rawData(fileSize); file.read(reinterpret_cast(rawData.data()), static_cast(rawData.size())); createOrAddToFile(params, rawData.data()); @@ -27,7 +27,8 @@ ReturnValue_t FilesystemMock::writeToFile(FileOpParams params, const uint8_t *da ReturnValue_t FilesystemMock::readFromFile(FileOpParams params, uint8_t **buffer, size_t &readSize, size_t maxSize) { - std::basic_string filename(params.path()); + std::string filename_c(params.fsParams.path); + std::filesystem::path::string_type filename(filename_c.cbegin(), filename_c.cend()); auto iter = fileMap.find(filename); if (iter == fileMap.end()) { return HasFileSystemIF::FILE_DOES_NOT_EXIST; @@ -57,9 +58,10 @@ ReturnValue_t FilesystemMock::createFile(FilesystemParams params, const uint8_t return returnvalue::OK; } -ReturnValue_t FilesystemMock::removeFile(const std::filesystem::path::value_type *path, +ReturnValue_t FilesystemMock::removeFile(const char *path, FileSystemArgsIF *args) { - std::basic_string filename(path); + std::string filename_c(path); + std::filesystem::path::string_type filename(filename_c.cbegin(), filename_c.cend()); auto iter = fileMap.find(filename); if (iter == fileMap.end()) { @@ -71,28 +73,31 @@ ReturnValue_t FilesystemMock::removeFile(const std::filesystem::path::value_type } ReturnValue_t FilesystemMock::createDirectory(FilesystemParams params, bool createParentDirs) { - auto dirPath = params.path; + std::string dirPath_c(params.path); + std::filesystem::path::string_type dirPath(dirPath_c.cbegin(), dirPath_c.cend()); dirMap[dirPath].createCallCount++; dirMap[dirPath].wihParentDir.push(createParentDirs); return returnvalue::OK; } ReturnValue_t FilesystemMock::removeDirectory(FilesystemParams params, bool deleteRecurively) { - auto dirPath = params.path; + std::string dirPath_c(params.path); + std::filesystem::path::string_type dirPath(dirPath_c.cbegin(), dirPath_c.cend()); dirMap[dirPath].delCallCount++; dirMap[dirPath].recursiveDeletion.push(deleteRecurively); return returnvalue::OK; } -ReturnValue_t FilesystemMock::rename(const std::filesystem::path::value_type *oldPath, - const std::filesystem::path::value_type *newPath, +ReturnValue_t FilesystemMock::rename(const char *oldPath, + const char *newPath, FileSystemArgsIF *args) { renameQueue.push(RenameInfo(oldPath, newPath)); return returnvalue::OK; } void FilesystemMock::createOrAddToFile(FileOpParams params, const uint8_t *data) { - auto filename(params.path()); + std::string filename_c(params.fsParams.path); + std::filesystem::path::string_type filename(filename_c.cbegin(), filename_c.cend()); auto iter = fileMap.find(filename); if (iter == fileMap.end()) { FileSegmentQueue queue; @@ -133,7 +138,8 @@ void FilesystemMock::reset() { } bool FilesystemMock::fileExists(FilesystemParams params) { - auto filename(params.path); + std::string filename_c(params.path); + std::filesystem::path::string_type filename(filename_c.cbegin(), filename_c.cend()); auto iter = fileMap.find(filename); if (iter == fileMap.end()) { return false; diff --git a/unittests/mocks/FilesystemMock.h b/unittests/mocks/FilesystemMock.h index b603d7dc5..db1f96770 100644 --- a/unittests/mocks/FilesystemMock.h +++ b/unittests/mocks/FilesystemMock.h @@ -6,6 +6,7 @@ #include #include #include +#include #include "fsfw/filesystem.h" @@ -20,13 +21,13 @@ class FilesystemMock : public HasFileSystemIF { public: struct FileWriteInfo { - FileWriteInfo(std::basic_string filename, size_t offset, + FileWriteInfo(std::filesystem::path::string_type filename, size_t offset, const uint8_t *data, size_t len) : offset(offset) { this->filename = filename; this->data.insert(this->data.end(), data, data + len); } - std::basic_string filename; + std::filesystem::path::string_type filename; size_t offset; std::vector data; }; @@ -37,7 +38,7 @@ class FilesystemMock : public HasFileSystemIF { std::vector fileRaw; }; - std::map, FileInfo> fileMap; + std::map fileMap; struct DirInfo { size_t createCallCount = 0; @@ -45,18 +46,17 @@ class FilesystemMock : public HasFileSystemIF { std::queue wihParentDir; std::queue recursiveDeletion; }; - std::map, DirInfo> dirMap; + std::map dirMap; struct RenameInfo { - RenameInfo(std::basic_string oldName, - std::basic_string newName) + RenameInfo(const char* oldName, const char *newName) : oldName(std::move(oldName)), newName(std::move(newName)) {} - std::basic_string oldName; - std::basic_string newName; + const char *oldName; + const char *newName; }; std::queue renameQueue; - std::basic_string truncateCalledOnFile; + const char* truncateCalledOnFile; ReturnValue_t feedFile(const std::string &filename, std::ifstream &file); bool fileExists(FilesystemParams params) override; @@ -66,12 +66,12 @@ class FilesystemMock : public HasFileSystemIF { ReturnValue_t readFromFile(FileOpParams params, uint8_t **buffer, size_t &readSize, size_t maxSize) override; ReturnValue_t createFile(FilesystemParams params, const uint8_t *data, size_t size) override; - ReturnValue_t removeFile(const std::filesystem::path::value_type *path, + 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 std::filesystem::path::value_type *oldPath, - const std::filesystem::path::value_type *newPath, + ReturnValue_t rename(const char *oldPath, + const char *newPath, FileSystemArgsIF *args) override; void reset();