add FS mock and improve HasFilesystemIF
This commit is contained in:
parent
3e1fd15613
commit
28c8248f26
@ -1,6 +1,3 @@
|
|||||||
#include "UserBase.h"
|
#include "UserBase.h"
|
||||||
|
|
||||||
#include <array>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
cfdp::UserBase::UserBase(HasFileSystemIF& vfs) : vfs(vfs) {}
|
cfdp::UserBase::UserBase(HasFileSystemIF& vfs) : vfs(vfs) {}
|
||||||
|
@ -4,10 +4,25 @@
|
|||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
|
||||||
#include "FileSystemArgsIF.h"
|
#include "FileSystemArgsIF.h"
|
||||||
|
#include "fsfw/ipc/MessageQueueIF.h"
|
||||||
#include "fsfw/ipc/messageQueueDefinitions.h"
|
#include "fsfw/ipc/messageQueueDefinitions.h"
|
||||||
#include "fsfw/returnvalues/FwClassIds.h"
|
#include "fsfw/returnvalues/FwClassIds.h"
|
||||||
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
|
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
|
||||||
|
|
||||||
|
struct FilesystemParams {
|
||||||
|
explicit FilesystemParams(const char* path) : path(path) {}
|
||||||
|
|
||||||
|
const char* path;
|
||||||
|
FileSystemArgsIF* args = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct FileOpParams : public FilesystemParams {
|
||||||
|
FileOpParams(const char* path, size_t size) : FilesystemParams(path), size(size) {}
|
||||||
|
|
||||||
|
size_t size;
|
||||||
|
size_t offset = 0;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Generic interface for objects which expose a file system to enable
|
* @brief Generic interface for objects which expose a file system to enable
|
||||||
* message based file handling.
|
* message based file handling.
|
||||||
@ -37,30 +52,47 @@ class HasFileSystemIF {
|
|||||||
//! [EXPORT] : P1: Sequence number missing
|
//! [EXPORT] : P1: Sequence number missing
|
||||||
static constexpr ReturnValue_t SEQUENCE_PACKET_MISSING_READ = MAKE_RETURN_CODE(16);
|
static constexpr ReturnValue_t SEQUENCE_PACKET_MISSING_READ = MAKE_RETURN_CODE(16);
|
||||||
|
|
||||||
virtual ~HasFileSystemIF() {}
|
virtual ~HasFileSystemIF() = default;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to get the MessageQueueId_t of the implementing object
|
* Function to get the MessageQueueId_t of the implementing object
|
||||||
* @return MessageQueueId_t of the object
|
* @return MessageQueueId_t of the object
|
||||||
*/
|
*/
|
||||||
virtual MessageQueueId_t getCommandQueue() const = 0;
|
[[nodiscard]] virtual MessageQueueId_t getCommandQueue() const {
|
||||||
|
return MessageQueueIF::NO_QUEUE;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Generic function to append to file.
|
* @brief Generic function to append to file.
|
||||||
* @param dirname Directory of the file
|
* @param fileOpInfo General information: File name, size to write, offset, additional arguments
|
||||||
* @param filename The filename of the file
|
|
||||||
* @param data The data to write to the file
|
* @param data The data to write to the file
|
||||||
* @param size The size of the data to write
|
|
||||||
* @param packetNumber Current packet number. Can be used to verify that
|
|
||||||
* there are no missing packets.
|
|
||||||
* @param args Any other arguments which an implementation might require.
|
|
||||||
* @param bytesWritten Actual bytes written to file
|
|
||||||
* For large files the write procedure must be split in multiple calls
|
|
||||||
* to writeToFile
|
|
||||||
*/
|
*/
|
||||||
virtual ReturnValue_t appendToFile(const char* repositoryPath, const char* filename,
|
virtual ReturnValue_t writeToFile(FileOpParams params, const uint8_t* data) = 0;
|
||||||
const uint8_t* data, size_t size, uint16_t packetNumber,
|
|
||||||
FileSystemArgsIF* args = nullptr) = 0;
|
/**
|
||||||
|
* @brief Generic function to read from a file. This variant takes a pointer to a buffer and
|
||||||
|
* performs pointer arithmetic by incrementing the pointer by the read size
|
||||||
|
* @param fileOpInfo General information: File name, size to write, offset, additional arguments
|
||||||
|
* @param buffer [in/out] Data will be read into the provided buffer, and the pointer will be
|
||||||
|
* incremented by the read length
|
||||||
|
* @param readSize [out] Will be incremented by the read length
|
||||||
|
* @param maxSize Maximum size of the provided buffer
|
||||||
|
* @param args
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
virtual ReturnValue_t readFromFile(FileOpParams fileOpInfo, uint8_t** buffer, size_t& readSize,
|
||||||
|
size_t maxSize) = 0;
|
||||||
|
/**
|
||||||
|
* Variant of the @readFromFile which does not perform pointer arithmetic.
|
||||||
|
* @param fileOpInfo General information: File name, size to write, offset, additional arguments
|
||||||
|
* @param buf
|
||||||
|
* @param maxSize
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
virtual ReturnValue_t readFromFile(FileOpParams fileOpInfo, uint8_t* buf, size_t maxSize) {
|
||||||
|
size_t dummy = 0;
|
||||||
|
return readFromFile(fileOpInfo, &buf, dummy, maxSize);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Generic function to create a new file.
|
* @brief Generic function to create a new file.
|
||||||
@ -71,9 +103,10 @@ class HasFileSystemIF {
|
|||||||
* @param args Any other arguments which an implementation might require
|
* @param args Any other arguments which an implementation might require
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
virtual ReturnValue_t createFile(const char* repositoryPath, const char* filename,
|
virtual ReturnValue_t createFile(FilesystemParams params) {
|
||||||
const uint8_t* data = nullptr, size_t size = 0,
|
return createFile(params, nullptr, 0);
|
||||||
FileSystemArgsIF* args = nullptr) = 0;
|
}
|
||||||
|
virtual ReturnValue_t createFile(FilesystemParams params, const uint8_t* data, size_t size) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Generic function to delete a file.
|
* @brief Generic function to delete a file.
|
||||||
@ -82,8 +115,8 @@ class HasFileSystemIF {
|
|||||||
* @param args Any other arguments which an implementation might require
|
* @param args Any other arguments which an implementation might require
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
virtual ReturnValue_t removeFile(const char* repositoryPath, const char* filename,
|
virtual ReturnValue_t removeFile(const char* path, FileSystemArgsIF* args) = 0;
|
||||||
FileSystemArgsIF* args = nullptr) = 0;
|
virtual ReturnValue_t removeFile(const char* path) { return removeFile(path, nullptr); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Generic function to create a directory
|
* @brief Generic function to create a directory
|
||||||
@ -93,21 +126,22 @@ class HasFileSystemIF {
|
|||||||
* @param args Any other arguments which an implementation might require
|
* @param args Any other arguments which an implementation might require
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
virtual ReturnValue_t createDirectory(const char* repositoryPath, const char* dirname,
|
virtual ReturnValue_t createDirectory(FilesystemParams params, bool createParentDirs) = 0;
|
||||||
bool createParentDirs,
|
|
||||||
FileSystemArgsIF* args = nullptr) = 0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Generic function to remove a directory
|
* @brief Generic function to remove a directory
|
||||||
* @param repositoryPath
|
* @param repositoryPath
|
||||||
* @param args Any other arguments which an implementation might require
|
* @param args Any other arguments which an implementation might require
|
||||||
*/
|
*/
|
||||||
virtual ReturnValue_t removeDirectory(const char* repositoryPath, const char* dirname,
|
virtual ReturnValue_t removeDirectory(FilesystemParams params, bool deleteRecurively) = 0;
|
||||||
bool deleteRecurively = false,
|
virtual ReturnValue_t removeDirectory(FilesystemParams params) {
|
||||||
FileSystemArgsIF* args = nullptr) = 0;
|
return removeDirectory(params, false);
|
||||||
|
}
|
||||||
|
|
||||||
virtual ReturnValue_t renameFile(const char* repositoryPath, const char* oldFilename,
|
virtual ReturnValue_t renameFile(const char* oldPath, char* newPath) {
|
||||||
const char* newFilename, FileSystemArgsIF* args = nullptr) = 0;
|
return renameFile(oldPath, newPath, nullptr);
|
||||||
|
}
|
||||||
|
virtual ReturnValue_t renameFile(const char* oldPath, char* newPath, FileSystemArgsIF* args) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* FSFW_MEMORY_HASFILESYSTEMIF_H_ */
|
#endif /* FSFW_MEMORY_HASFILESYSTEMIF_H_ */
|
||||||
|
@ -2,12 +2,13 @@
|
|||||||
|
|
||||||
#include "fsfw/cfdp.h"
|
#include "fsfw/cfdp.h"
|
||||||
#include "mocks/cfdp/FaultHandlerMock.h"
|
#include "mocks/cfdp/FaultHandlerMock.h"
|
||||||
|
#include "mocks/cfdp/UserMock.h"
|
||||||
TEST_CASE("CFDP Dest Handler", "[cfdp]") {
|
TEST_CASE("CFDP Dest Handler", "[cfdp]") {
|
||||||
using namespace cfdp;
|
using namespace cfdp;
|
||||||
EntityId localId = EntityId(UnsignedByteField<uint16_t>(2));
|
EntityId localId = EntityId(UnsignedByteField<uint16_t>(2));
|
||||||
auto fhMock = FaultHandlerMock();
|
auto fhMock = FaultHandlerMock();
|
||||||
auto localEntityCfg = LocalEntityCfg(localId, IndicationCfg(), fhMock);
|
auto localEntityCfg = LocalEntityCfg(localId, IndicationCfg(), fhMock);
|
||||||
|
// auto userMock = UserMock();
|
||||||
|
|
||||||
SECTION("State") {}
|
SECTION("State") {}
|
||||||
}
|
}
|
@ -14,6 +14,7 @@ target_sources(
|
|||||||
PusDistributorMock.cpp
|
PusDistributorMock.cpp
|
||||||
CcsdsCheckerMock.cpp
|
CcsdsCheckerMock.cpp
|
||||||
AcceptsTcMock.cpp
|
AcceptsTcMock.cpp
|
||||||
StorageManagerMock.cpp)
|
StorageManagerMock.cpp
|
||||||
|
FilesystemMock.cpp)
|
||||||
|
|
||||||
add_subdirectory(cfdp)
|
add_subdirectory(cfdp)
|
||||||
|
22
unittests/mocks/FilesystemMock.cpp
Normal file
22
unittests/mocks/FilesystemMock.cpp
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#include "FilesystemMock.h"
|
||||||
|
|
||||||
|
ReturnValue_t FilesystemMock::writeToFile(FileOpParams params, const uint8_t *data) { return 0; }
|
||||||
|
ReturnValue_t FilesystemMock::readFromFile(FileOpParams fileOpInfo, uint8_t **buffer,
|
||||||
|
size_t &readSize, size_t maxSize) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
ReturnValue_t FilesystemMock::createFile(FilesystemParams params, const uint8_t *data,
|
||||||
|
size_t size) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
ReturnValue_t FilesystemMock::removeFile(const char *path, FileSystemArgsIF *args) { return 0; }
|
||||||
|
ReturnValue_t FilesystemMock::createDirectory(FilesystemParams params, bool createParentDirs) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
ReturnValue_t FilesystemMock::removeDirectory(FilesystemParams params, bool deleteRecurively) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
ReturnValue_t FilesystemMock::renameFile(const char *oldPath, char *newPath,
|
||||||
|
FileSystemArgsIF *args) {
|
||||||
|
return 0;
|
||||||
|
}
|
19
unittests/mocks/FilesystemMock.h
Normal file
19
unittests/mocks/FilesystemMock.h
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#ifndef FSFW_MOCKS_FILESYSTEMMOCK_H
|
||||||
|
#define FSFW_MOCKS_FILESYSTEMMOCK_H
|
||||||
|
|
||||||
|
#include "fsfw/filesystem.h"
|
||||||
|
|
||||||
|
class FilesystemMock : public HasFileSystemIF {
|
||||||
|
public:
|
||||||
|
MessageQueueId_t getCommandQueue() const override;
|
||||||
|
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;
|
||||||
|
ReturnValue_t createFile(FilesystemParams params, const uint8_t *data, size_t size) override;
|
||||||
|
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 renameFile(const char *oldPath, char *newPath, FileSystemArgsIF *args) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // FSFW_MOCKS_FILESYSTEMMOCK_H
|
Loading…
Reference in New Issue
Block a user