this should do the job

This commit is contained in:
Robin Müller 2022-08-10 15:03:53 +02:00
parent ea6e5d9971
commit 3df1161560
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
3 changed files with 50 additions and 2 deletions

View File

@ -3,6 +3,7 @@
#include "fsfw/cfdp.h"
#include "mocks/cfdp/FaultHandlerMock.h"
#include "mocks/cfdp/UserMock.h"
TEST_CASE("CFDP Dest Handler", "[cfdp]") {
using namespace cfdp;
EntityId localId = EntityId(UnsignedByteField<uint16_t>(2));

View File

@ -1,6 +1,31 @@
#include "FilesystemMock.h"
ReturnValue_t FilesystemMock::writeToFile(FileOpParams params, const uint8_t *data) { return 0; }
ReturnValue_t FilesystemMock::writeToFile(FileOpParams params, const uint8_t *data) {
std::string filename(params.path);
auto iter = fileMap.find(filename);
if (iter == fileMap.end()) {
FileSegmentQueue queue;
queue.push(FileWriteInfo(filename, params.offset, data, params.size));
FileInfo info;
info.fileSegQueue = queue;
info.fileRaw.insert(info.fileRaw.end(), data, data + params.size);
fileMap.emplace(filename, info);
} else {
FileInfo& info = iter->second;
info.fileSegQueue.push(FileWriteInfo(filename, params.offset, data, params.size));
// Easiest case: append data to the end
if(params.offset == info.fileRaw.size()) {
info.fileRaw.insert(info.fileRaw.end(), data, data + params.size);
} else {
size_t totalNewLen = params.offset + params.size;
if(totalNewLen > info.fileRaw.size()) {
info.fileRaw.resize(params.offset + params.size);
}
std::copy(data, data + params.size, info.fileRaw.begin() + static_cast<unsigned int>(params.offset));
}
}
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t FilesystemMock::readFromFile(FileOpParams fileOpInfo, uint8_t **buffer,
size_t &readSize, size_t maxSize) {
return 0;

View File

@ -1,11 +1,33 @@
#ifndef FSFW_MOCKS_FILESYSTEMMOCK_H
#define FSFW_MOCKS_FILESYSTEMMOCK_H
#include <queue>
#include <string>
#include <map>
#include <utility>
#include "fsfw/filesystem.h"
class FilesystemMock : public HasFileSystemIF {
public:
MessageQueueId_t getCommandQueue() const override;
struct FileWriteInfo {
FileWriteInfo(std::string filename, size_t offset, const uint8_t* data, size_t len)
: filename(std::move(filename)), offset(offset) {
this->data.insert(this->data.end(), data, data + len);
}
std::string filename;
size_t offset;
std::vector<uint8_t> data;
};
using FileSegmentQueue = std::queue<FileWriteInfo>;
struct FileInfo {
FileSegmentQueue fileSegQueue;
std::vector<uint8_t> fileRaw;
};
std::map<std::string, FileInfo> fileMap;
ReturnValue_t writeToFile(FileOpParams params, const uint8_t *data) override;
ReturnValue_t readFromFile(FileOpParams fileOpInfo, uint8_t **buffer, size_t &readSize,
size_t maxSize) override;