1
0
forked from fsfw/fsfw

windows building again

This commit is contained in:
2023-01-26 15:30:23 +01:00
parent e37af4fe70
commit 3e8446ba8b
15 changed files with 167 additions and 97 deletions

View File

@ -6,14 +6,14 @@
ReturnValue_t FilesystemMock::feedFile(const std::string &filename, std::ifstream &file) {
// not multibyte encoding safe!
std::basic_string<std::filesystem::path::value_type> 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<uint8_t> rawData(fileSize);
file.read(reinterpret_cast<char *>(rawData.data()), static_cast<unsigned int>(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<std::filesystem::path::value_type> 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<std::filesystem::path::value_type> 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;

View File

@ -6,6 +6,7 @@
#include <queue>
#include <string>
#include <utility>
#include <filesystem>
#include "fsfw/filesystem.h"
@ -20,13 +21,13 @@
class FilesystemMock : public HasFileSystemIF {
public:
struct FileWriteInfo {
FileWriteInfo(std::basic_string<std::filesystem::path::value_type> 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<std::filesystem::path::value_type> filename;
std::filesystem::path::string_type filename;
size_t offset;
std::vector<uint8_t> data;
};
@ -37,7 +38,7 @@ class FilesystemMock : public HasFileSystemIF {
std::vector<uint8_t> fileRaw;
};
std::map<std::basic_string<std::filesystem::path::value_type>, FileInfo> fileMap;
std::map<std::filesystem::path::string_type, FileInfo> fileMap;
struct DirInfo {
size_t createCallCount = 0;
@ -45,18 +46,17 @@ class FilesystemMock : public HasFileSystemIF {
std::queue<bool> wihParentDir;
std::queue<bool> recursiveDeletion;
};
std::map<std::basic_string<std::filesystem::path::value_type>, DirInfo> dirMap;
std::map<std::filesystem::path::string_type, DirInfo> dirMap;
struct RenameInfo {
RenameInfo(std::basic_string<std::filesystem::path::value_type> oldName,
std::basic_string<std::filesystem::path::value_type> newName)
RenameInfo(const char* oldName, const char *newName)
: oldName(std::move(oldName)), newName(std::move(newName)) {}
std::basic_string<std::filesystem::path::value_type> oldName;
std::basic_string<std::filesystem::path::value_type> newName;
const char *oldName;
const char *newName;
};
std::queue<RenameInfo> renameQueue;
std::basic_string<std::filesystem::path::value_type> 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();