Update and clean up HK and Local Pool Modules
This commit is contained in:
2
unittests/mock/cfdp/CMakeLists.txt
Normal file
2
unittests/mock/cfdp/CMakeLists.txt
Normal file
@ -0,0 +1,2 @@
|
||||
target_sources(${FSFW_TEST_TGT} PRIVATE FaultHandlerMock.cpp UserMock.cpp
|
||||
RemoteConfigTableMock.cpp)
|
42
unittests/mock/cfdp/FaultHandlerMock.cpp
Normal file
42
unittests/mock/cfdp/FaultHandlerMock.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
#include "FaultHandlerMock.h"
|
||||
|
||||
namespace cfdp {
|
||||
|
||||
void FaultHandlerMock::noticeOfSuspensionCb(TransactionId& id, cfdp::ConditionCode code) {
|
||||
auto& info = fhInfoMap.at(cfdp::FaultHandlerCode::NOTICE_OF_SUSPENSION);
|
||||
info.callCount++;
|
||||
info.condCodes.push(code);
|
||||
}
|
||||
|
||||
void FaultHandlerMock::noticeOfCancellationCb(TransactionId& id, cfdp::ConditionCode code) {
|
||||
auto& info = fhInfoMap.at(cfdp::FaultHandlerCode::NOTICE_OF_CANCELLATION);
|
||||
info.callCount++;
|
||||
info.condCodes.push(code);
|
||||
}
|
||||
|
||||
void FaultHandlerMock::abandonCb(TransactionId& id, cfdp::ConditionCode code) {
|
||||
auto& info = fhInfoMap.at(cfdp::FaultHandlerCode::ABANDON_TRANSACTION);
|
||||
info.callCount++;
|
||||
info.condCodes.push(code);
|
||||
}
|
||||
|
||||
void FaultHandlerMock::ignoreCb(TransactionId& id, cfdp::ConditionCode code) {
|
||||
auto& info = fhInfoMap.at(cfdp::FaultHandlerCode::IGNORE_ERROR);
|
||||
info.callCount++;
|
||||
info.condCodes.push(code);
|
||||
}
|
||||
|
||||
FaultHandlerMock::FaultInfo& FaultHandlerMock::getFhInfo(cfdp::FaultHandlerCode 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::FaultHandlerCode, FaultInfo>& pair) {
|
||||
return pair.second.callCount > 0;
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace cfdp
|
37
unittests/mock/cfdp/FaultHandlerMock.h
Normal file
37
unittests/mock/cfdp/FaultHandlerMock.h
Normal 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(TransactionId& id, ConditionCode code) override;
|
||||
void noticeOfCancellationCb(TransactionId& id, ConditionCode code) override;
|
||||
void abandonCb(TransactionId& id, ConditionCode code) override;
|
||||
void ignoreCb(TransactionId& id, ConditionCode code) override;
|
||||
|
||||
FaultInfo& getFhInfo(FaultHandlerCode fhCode);
|
||||
[[nodiscard]] bool faultCbWasCalled() const;
|
||||
void reset();
|
||||
|
||||
private:
|
||||
std::map<cfdp::FaultHandlerCode, FaultInfo> fhInfoMap = {
|
||||
std::pair{cfdp::FaultHandlerCode::IGNORE_ERROR, FaultInfo()},
|
||||
std::pair{cfdp::FaultHandlerCode::NOTICE_OF_CANCELLATION, FaultInfo()},
|
||||
std::pair{cfdp::FaultHandlerCode::NOTICE_OF_SUSPENSION, FaultInfo()},
|
||||
std::pair{cfdp::FaultHandlerCode::ABANDON_TRANSACTION, FaultInfo()}};
|
||||
};
|
||||
|
||||
} // namespace cfdp
|
||||
|
||||
#endif // FSFW_TESTS_FAULTHANDLERMOCK_H
|
15
unittests/mock/cfdp/RemoteConfigTableMock.cpp
Normal file
15
unittests/mock/cfdp/RemoteConfigTableMock.cpp
Normal file
@ -0,0 +1,15 @@
|
||||
#include "RemoteConfigTableMock.h"
|
||||
|
||||
void cfdp::RemoteConfigTableMock::addRemoteConfig(const cfdp::RemoteEntityCfg& cfg) {
|
||||
remoteCfgTable.emplace(cfg.remoteId, cfg);
|
||||
}
|
||||
|
||||
bool cfdp::RemoteConfigTableMock::getRemoteCfg(const cfdp::EntityId& remoteId,
|
||||
cfdp::RemoteEntityCfg** cfg) {
|
||||
auto iter = remoteCfgTable.find(remoteId);
|
||||
if (iter == remoteCfgTable.end()) {
|
||||
return false;
|
||||
}
|
||||
*cfg = &iter->second;
|
||||
return true;
|
||||
}
|
20
unittests/mock/cfdp/RemoteConfigTableMock.h
Normal file
20
unittests/mock/cfdp/RemoteConfigTableMock.h
Normal file
@ -0,0 +1,20 @@
|
||||
#ifndef FSFW_TESTS_CFDP_REMOTCONFIGTABLEMOCK_H
|
||||
#define FSFW_TESTS_CFDP_REMOTCONFIGTABLEMOCK_H
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "fsfw/cfdp/handler/RemoteConfigTableIF.h"
|
||||
|
||||
namespace cfdp {
|
||||
|
||||
class RemoteConfigTableMock : public RemoteConfigTableIF {
|
||||
public:
|
||||
void addRemoteConfig(const RemoteEntityCfg& cfg);
|
||||
bool getRemoteCfg(const cfdp::EntityId& remoteId, cfdp::RemoteEntityCfg** cfg) override;
|
||||
|
||||
std::map<EntityId, RemoteEntityCfg> remoteCfgTable;
|
||||
};
|
||||
|
||||
} // namespace cfdp
|
||||
|
||||
#endif // FSFW_TESTS_CFDP_REMOTCONFIGTABLEMOCK_H
|
36
unittests/mock/cfdp/UserMock.cpp
Normal file
36
unittests/mock/cfdp/UserMock.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
#include "UserMock.h"
|
||||
|
||||
namespace cfdp {
|
||||
|
||||
cfdp::UserMock::UserMock(HasFileSystemIF& vfs) : UserBase(vfs) {}
|
||||
|
||||
void UserMock::transactionIndication(const TransactionId& id) { transactionIndicRecvd.emplace(id); }
|
||||
|
||||
void UserMock::eofSentIndication(const TransactionId& id) { eofSentRecvd.emplace(id); }
|
||||
void UserMock::abandonedIndication(const TransactionId& id, cfdp::ConditionCode code,
|
||||
uint64_t progress) {}
|
||||
|
||||
void UserMock::eofRecvIndication(const TransactionId& id) { eofRecvdRecvd.push(id); }
|
||||
|
||||
void UserMock::transactionFinishedIndication(const TransactionFinishedParams& finishedParams) {
|
||||
finishedRecvd.emplace(finishedParams.id, finishedParams);
|
||||
}
|
||||
|
||||
void UserMock::metadataRecvdIndication(const MetadataRecvdParams& params) {
|
||||
metadataRecvd.emplace(params.id, params);
|
||||
}
|
||||
|
||||
void UserMock::fileSegmentRecvdIndication(const FileSegmentRecvdParams& params) {}
|
||||
void UserMock::reportIndication(const TransactionId& id, StatusReportIF& report) {}
|
||||
void UserMock::suspendedIndication(const TransactionId& id, ConditionCode code) {}
|
||||
void UserMock::resumedIndication(const TransactionId& id, size_t progress) {}
|
||||
void UserMock::faultIndication(const TransactionId& id, cfdp::ConditionCode code, size_t progress) {
|
||||
}
|
||||
|
||||
void UserMock::reset() {
|
||||
std::queue<TransactionId>().swap(eofRecvdRecvd);
|
||||
std::queue<std::pair<TransactionId, cfdp::MetadataRecvdParams>>().swap(metadataRecvd);
|
||||
std::queue<std::pair<TransactionId, cfdp::TransactionFinishedParams>>().swap(finishedRecvd);
|
||||
}
|
||||
|
||||
} // namespace cfdp
|
36
unittests/mock/cfdp/UserMock.h
Normal file
36
unittests/mock/cfdp/UserMock.h
Normal file
@ -0,0 +1,36 @@
|
||||
#ifndef FSFW_TESTS_CFDP_USERMOCK_H
|
||||
#define FSFW_TESTS_CFDP_USERMOCK_H
|
||||
|
||||
#include <queue>
|
||||
|
||||
#include "fsfw/cfdp/handler/UserBase.h"
|
||||
|
||||
namespace cfdp {
|
||||
|
||||
class UserMock : public UserBase {
|
||||
public:
|
||||
explicit UserMock(HasFileSystemIF& vfs);
|
||||
|
||||
void transactionIndication(const TransactionId& id) override;
|
||||
void eofSentIndication(const TransactionId& id) override;
|
||||
void abandonedIndication(const TransactionId& id, ConditionCode code, size_t progress) override;
|
||||
void eofRecvIndication(const TransactionId& id) override;
|
||||
void transactionFinishedIndication(const TransactionFinishedParams& params) override;
|
||||
void metadataRecvdIndication(const MetadataRecvdParams& params) override;
|
||||
void fileSegmentRecvdIndication(const FileSegmentRecvdParams& params) override;
|
||||
void reportIndication(const TransactionId& id, StatusReportIF& report) override;
|
||||
void suspendedIndication(const TransactionId& id, ConditionCode code) override;
|
||||
void resumedIndication(const TransactionId& id, size_t progress) override;
|
||||
void faultIndication(const TransactionId& id, ConditionCode code, size_t progress) override;
|
||||
|
||||
std::queue<TransactionId> transactionIndicRecvd;
|
||||
std::queue<std::pair<TransactionId, MetadataRecvdParams>> metadataRecvd;
|
||||
std::queue<TransactionId> eofRecvdRecvd;
|
||||
std::queue<TransactionId> eofSentRecvd;
|
||||
std::queue<std::pair<TransactionId, TransactionFinishedParams>> finishedRecvd;
|
||||
void reset();
|
||||
};
|
||||
|
||||
} // namespace cfdp
|
||||
|
||||
#endif // FSFW_TESTS_CFDP_USERMOCK_H
|
Reference in New Issue
Block a user