add CFDP fault handler mock
This commit is contained in:
parent
eccb629ba8
commit
dba3f9960e
@ -1,19 +1,21 @@
|
||||
#include "FaultHandlerBase.h"
|
||||
|
||||
CfdpFaultHandlerBase::CfdpFaultHandlerBase() = default;
|
||||
namespace cfdp {
|
||||
|
||||
bool CfdpFaultHandlerBase::getFaultHandler(
|
||||
cfdp::ConditionCode code, cfdp::FaultHandlerCodes& handler) const {
|
||||
FaultHandlerBase::FaultHandlerBase() = default;
|
||||
FaultHandlerBase::~FaultHandlerBase() = default;
|
||||
|
||||
bool FaultHandlerBase::getFaultHandler(cfdp::ConditionCode code,
|
||||
cfdp::FaultHandlerCodes& handler) const {
|
||||
auto iter = faultHandlerMap.find(code);
|
||||
if(iter == faultHandlerMap.end()) {
|
||||
if (iter == faultHandlerMap.end()) {
|
||||
return false;
|
||||
}
|
||||
handler = iter->second;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CfdpFaultHandlerBase::setFaultHandler(cfdp::ConditionCode code,
|
||||
cfdp::FaultHandlerCodes handler) {
|
||||
bool FaultHandlerBase::setFaultHandler(cfdp::ConditionCode code, cfdp::FaultHandlerCodes handler) {
|
||||
if (not faultHandlerMap.contains(code)) {
|
||||
return false;
|
||||
}
|
||||
@ -21,21 +23,20 @@ bool CfdpFaultHandlerBase::setFaultHandler(cfdp::ConditionCode code,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CfdpFaultHandlerBase::faultCallback(cfdp::ConditionCode code) {
|
||||
bool FaultHandlerBase::faultCallback(cfdp::ConditionCode code) {
|
||||
if (not faultHandlerMap.contains(code)) {
|
||||
return false;
|
||||
}
|
||||
cfdp::FaultHandlerCodes fh = faultHandlerMap[code];
|
||||
if (fh == cfdp::FaultHandlerCodes::IGNORE_ERROR) {
|
||||
ignoreCb(code);
|
||||
} else if(fh == cfdp::FaultHandlerCodes::ABANDON_TRANSACTION) {
|
||||
} else if (fh == cfdp::FaultHandlerCodes::ABANDON_TRANSACTION) {
|
||||
abandonCb(code);
|
||||
} else if(fh == cfdp::FaultHandlerCodes::NOTICE_OF_CANCELLATION) {
|
||||
} else if (fh == cfdp::FaultHandlerCodes::NOTICE_OF_CANCELLATION) {
|
||||
noticeOfCancellationCb(code);
|
||||
} else {
|
||||
noticeOfSuspensionCb(code);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
CfdpFaultHandlerBase::~CfdpFaultHandlerBase() = default;
|
||||
} // namespace cfdp
|
||||
|
@ -5,10 +5,12 @@
|
||||
|
||||
#include "definitions.h"
|
||||
|
||||
class CfdpFaultHandlerBase {
|
||||
namespace cfdp {
|
||||
|
||||
class FaultHandlerBase {
|
||||
public:
|
||||
virtual ~CfdpFaultHandlerBase();
|
||||
CfdpFaultHandlerBase();
|
||||
virtual ~FaultHandlerBase();
|
||||
FaultHandlerBase();
|
||||
|
||||
/**
|
||||
* Get the fault handler code for the given condition code
|
||||
@ -46,4 +48,6 @@ class CfdpFaultHandlerBase {
|
||||
cfdp::FaultHandlerCodes::IGNORE_ERROR}};
|
||||
};
|
||||
|
||||
} // namespace cfdp
|
||||
|
||||
#endif // FSFW_CFDP_FAULTHANDLERBASE_H
|
||||
|
@ -15,5 +15,4 @@ struct LocalEntityCfg {
|
||||
IndicationCfg indicCfg;
|
||||
};
|
||||
|
||||
|
||||
#endif // FSFW_CFDP_MIB_H
|
||||
|
@ -1,8 +1,8 @@
|
||||
#ifndef FSFW_SRC_FSFW_CFDP_PDU_PDUCONFIG_H_
|
||||
#define FSFW_SRC_FSFW_CFDP_PDU_PDUCONFIG_H_
|
||||
|
||||
#include "fsfw/cfdp/definitions.h"
|
||||
#include "VarLenField.h"
|
||||
#include "fsfw/cfdp/definitions.h"
|
||||
|
||||
namespace cfdp {
|
||||
|
||||
@ -22,7 +22,7 @@ struct TransactionSeqNum : public VarLenField {
|
||||
TransactionSeqNum(cfdp::WidthInBytes width, size_t seqNum) : VarLenField(width, seqNum) {}
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace cfdp
|
||||
|
||||
class PduConfig {
|
||||
public:
|
||||
|
@ -1,17 +1,5 @@
|
||||
target_sources(
|
||||
${FSFW_TEST_TGT}
|
||||
PRIVATE testCfdp.cpp
|
||||
testTlvsLvs.cpp
|
||||
testAckPdu.cpp
|
||||
testEofPdu.cpp
|
||||
testNakPdu.cpp
|
||||
testFinishedPdu.cpp
|
||||
testPromptPdu.cpp
|
||||
testKeepAlivePdu.cpp
|
||||
testMetadataPdu.cpp
|
||||
testFileData.cpp
|
||||
testCfdpHeader.cpp
|
||||
testFileDirective.cpp
|
||||
testDistributor.cpp
|
||||
testDestHandler.cpp
|
||||
testSourceHandler.cpp)
|
||||
target_sources(${FSFW_TEST_TGT} PRIVATE testCfdp.cpp testTlvsLvs.cpp
|
||||
testSourceHandler.cpp)
|
||||
|
||||
add_subdirectory(handler)
|
||||
add_subdirectory(pdu)
|
||||
|
1
unittests/cfdp/handler/CMakeLists.txt
Normal file
1
unittests/cfdp/handler/CMakeLists.txt
Normal file
@ -0,0 +1 @@
|
||||
target_sources(${FSFW_TEST_TGT} PRIVATE testDistributor.cpp testDestHandler.cpp)
|
13
unittests/cfdp/pdu/CMakeLists.txt
Normal file
13
unittests/cfdp/pdu/CMakeLists.txt
Normal file
@ -0,0 +1,13 @@
|
||||
target_sources(
|
||||
${FSFW_TEST_TGT}
|
||||
PRIVATE testAckPdu.cpp
|
||||
testAckPdu.cpp
|
||||
testEofPdu.cpp
|
||||
testNakPdu.cpp
|
||||
testFinishedPdu.cpp
|
||||
testPromptPdu.cpp
|
||||
testKeepAlivePdu.cpp
|
||||
testMetadataPdu.cpp
|
||||
testFileData.cpp
|
||||
testCfdpHeader.cpp
|
||||
testFileDirective.cpp)
|
@ -1,5 +1,3 @@
|
||||
#include <fsfw/cfdp/tlv/MessageToUserTlv.h>
|
||||
|
||||
#include <array>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <iostream>
|
||||
@ -7,6 +5,7 @@
|
||||
#include "fsfw/cfdp/pdu/MetadataPduCreator.h"
|
||||
#include "fsfw/cfdp/pdu/MetadataPduReader.h"
|
||||
#include "fsfw/cfdp/tlv/FilestoreResponseTlv.h"
|
||||
#include "fsfw/cfdp/tlv/MessageToUserTlv.h"
|
||||
#include "fsfw/globalfunctions/arrayprinter.h"
|
||||
|
||||
TEST_CASE("Metadata PDU", "[cfdp][pdu]") {
|
@ -14,4 +14,5 @@ target_sources(
|
||||
PusDistributorMock.cpp
|
||||
CcsdsCheckerMock.cpp
|
||||
AcceptsTcMock.cpp
|
||||
StorageManagerMock.cpp)
|
||||
StorageManagerMock.cpp
|
||||
CfdpFaultHandlerMock.cpp)
|
||||
|
38
unittests/mocks/CfdpFaultHandlerMock.cpp
Normal file
38
unittests/mocks/CfdpFaultHandlerMock.cpp
Normal 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;
|
||||
});
|
||||
}
|
32
unittests/mocks/CfdpFaultHandlerMock.h
Normal file
32
unittests/mocks/CfdpFaultHandlerMock.h
Normal 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
|
Loading…
Reference in New Issue
Block a user