windows building again
This commit is contained in:
@ -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<const uint8_t *>(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);
|
||||
|
@ -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<uint8_t, 10> 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<const uint8_t*>(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<unsigned int>(data.size()));
|
||||
of.close();
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
|
Reference in New Issue
Block a user