new cfdp mock folder, added additional cfdp mocks

This commit is contained in:
2022-08-09 19:00:47 +02:00
parent d45108e3c2
commit 0cb15e901e
11 changed files with 97 additions and 23 deletions

View File

@ -0,0 +1 @@
target_sources(${FSFW_TEST_TGT} PRIVATE FaultHandlerMock.cpp UserMock.cpp RemoteConfigTableMock.cpp)

View File

@ -0,0 +1,42 @@
#include "FaultHandlerMock.h"
namespace cfdp {
void FaultHandlerMock::noticeOfSuspensionCb(cfdp::ConditionCode code) {
auto& info = fhInfoMap.at(cfdp::FaultHandlerCodes::NOTICE_OF_SUSPENSION);
info.callCount++;
info.condCodes.push(code);
}
void FaultHandlerMock::noticeOfCancellationCb(cfdp::ConditionCode code) {
auto& info = fhInfoMap.at(cfdp::FaultHandlerCodes::NOTICE_OF_CANCELLATION);
info.callCount++;
info.condCodes.push(code);
}
void FaultHandlerMock::abandonCb(cfdp::ConditionCode code) {
auto& info = fhInfoMap.at(cfdp::FaultHandlerCodes::ABANDON_TRANSACTION);
info.callCount++;
info.condCodes.push(code);
}
void FaultHandlerMock::ignoreCb(cfdp::ConditionCode code) {
auto& info = fhInfoMap.at(cfdp::FaultHandlerCodes::IGNORE_ERROR);
info.callCount++;
info.condCodes.push(code);
}
FaultHandlerMock::FaultInfo& FaultHandlerMock::getFhInfo(cfdp::FaultHandlerCodes fhCode) {
return fhInfoMap.at(fhCode);
}
void FaultHandlerMock::reset() { fhInfoMap.clear(); }
bool FaultHandlerMock::faultCbWasCalled() const {
return std::any_of(fhInfoMap.begin(), fhInfoMap.end(),
[](const std::pair<cfdp::FaultHandlerCodes, FaultInfo>& pair) {
return pair.second.callCount > 0;
});
}
} // namespace cfdp

View File

@ -0,0 +1,37 @@
#ifndef FSFW_TESTS_FAULTHANDLERMOCK_H
#define FSFW_TESTS_FAULTHANDLERMOCK_H
#include <map>
#include <queue>
#include "fsfw/cfdp/handler/FaultHandlerBase.h"
namespace cfdp {
class FaultHandlerMock : public FaultHandlerBase {
public:
struct FaultInfo {
size_t callCount = 0;
std::queue<cfdp::ConditionCode> condCodes;
};
void noticeOfSuspensionCb(ConditionCode code) override;
void noticeOfCancellationCb(ConditionCode code) override;
void abandonCb(ConditionCode code) override;
void ignoreCb(ConditionCode code) override;
FaultInfo& getFhInfo(FaultHandlerCodes fhCode);
[[nodiscard]] bool faultCbWasCalled() const;
void reset();
private:
std::map<cfdp::FaultHandlerCodes, FaultInfo> fhInfoMap = {
std::pair{cfdp::FaultHandlerCodes::IGNORE_ERROR, FaultInfo()},
std::pair{cfdp::FaultHandlerCodes::NOTICE_OF_CANCELLATION, FaultInfo()},
std::pair{cfdp::FaultHandlerCodes::NOTICE_OF_SUSPENSION, FaultInfo()},
std::pair{cfdp::FaultHandlerCodes::ABANDON_TRANSACTION, FaultInfo()}};
};
} // namespace cfdp
#endif // FSFW_TESTS_FAULTHANDLERMOCK_H

View File

@ -0,0 +1,6 @@
#include "RemoteConfigTableMock.h"
bool cfdp::RemoteConfigTableMock::getRemoteCfg(cfdp::EntityId remoteId,
cfdp::RemoteEntityCfg *cfg) {
return false;
}

View File

@ -0,0 +1,15 @@
#ifndef FSFW_TESTS_CFDP_REMOTCONFIGTABLEMOCK_H
#define FSFW_TESTS_CFDP_REMOTCONFIGTABLEMOCK_H
#include "fsfw/cfdp/handler/RemoteConfigTableIF.h"
namespace cfdp {
class RemoteConfigTableMock: public RemoteConfigTableIF {
public:
bool getRemoteCfg(EntityId remoteId, RemoteEntityCfg *cfg) override;
};
}
#endif // FSFW_TESTS_CFDP_REMOTCONFIGTABLEMOCK_H

View File

@ -0,0 +1,16 @@
#include "UserMock.h"
cfdp::UserMock::UserMock(HasFileSystemIF& vfs) : UserBase(vfs) {}
void cfdp::UserMock::transactionIndication(cfdp::TransactionId id) {}
void cfdp::UserMock::eofSentIndication(cfdp::TransactionId id) {}
void cfdp::UserMock::abandonedIndication(cfdp::TransactionId id, cfdp::ConditionCode code,
uint64_t progress) {}
void cfdp::UserMock::eofRecvIndication(cfdp::TransactionId id) {}
void cfdp::UserMock::transactionFinishedIndication() {}
void cfdp::UserMock::metadataRecvdIndication() {}
void cfdp::UserMock::fileSegmentRecvdIndication() {}
void cfdp::UserMock::reportIndication() {}
void cfdp::UserMock::suspendedIndication() {}
void cfdp::UserMock::resumedIndication() {}

View File

@ -0,0 +1,25 @@
#ifndef FSFW_TESTS_CFDP_USERMOCK_H
#define FSFW_TESTS_CFDP_USERMOCK_H
#include "fsfw/cfdp/handler/UserBase.h"
namespace cfdp {
class UserMock: public UserBase {
explicit UserMock(HasFileSystemIF& vfs);
public:
void transactionIndication(TransactionId id) override;
void eofSentIndication(TransactionId id) override;
void abandonedIndication(TransactionId id, ConditionCode code, uint64_t progress) override;
void eofRecvIndication(TransactionId id) override;
void transactionFinishedIndication() override;
void metadataRecvdIndication() override;
void fileSegmentRecvdIndication() override;
void reportIndication() override;
void suspendedIndication() override;
void resumedIndication() override;
};
}
#endif // FSFW_TESTS_CFDP_USERMOCK_H