1
0
forked from fsfw/fsfw

add CFDP fault handler mock

This commit is contained in:
2022-08-09 14:55:08 +02:00
parent eccb629ba8
commit dba3f9960e
22 changed files with 113 additions and 37 deletions

View File

@ -14,4 +14,5 @@ target_sources(
PusDistributorMock.cpp
CcsdsCheckerMock.cpp
AcceptsTcMock.cpp
StorageManagerMock.cpp)
StorageManagerMock.cpp
CfdpFaultHandlerMock.cpp)

View File

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

View File

@ -0,0 +1,32 @@
#ifndef FSFW_TESTS_CFDPFAULTHANDLERMOCK_H
#define FSFW_TESTS_CFDPFAULTHANDLERMOCK_H
#include <map>
#include <queue>
#include "fsfw/cfdp/FaultHandlerBase.h"
class CfdpFaultHandlerMock : public cfdp::FaultHandlerBase {
public:
struct FaultInfo {
size_t callCount = 0;
std::queue<cfdp::ConditionCode> condCodes;
};
void noticeOfSuspensionCb(cfdp::ConditionCode code) override;
void noticeOfCancellationCb(cfdp::ConditionCode code) override;
void abandonCb(cfdp::ConditionCode code) override;
void ignoreCb(cfdp::ConditionCode code) override;
FaultInfo& getFhInfo(cfdp::FaultHandlerCodes fhCode);
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()}};
};
#endif // FSFW_TESTS_CFDPFAULTHANDLERMOCK_H