new cfdp mock folder, added additional cfdp mocks
fsfw/fsfw/pipeline/pr-development This commit looks good Details

This commit is contained in:
Robin Müller 2022-08-09 19:00:47 +02:00
parent d45108e3c2
commit 0cb15e901e
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
11 changed files with 97 additions and 23 deletions

View File

@ -6,6 +6,7 @@
namespace cfdp { namespace cfdp {
class RemoteConfigTableIF { class RemoteConfigTableIF {
public:
virtual ~RemoteConfigTableIF() = default; virtual ~RemoteConfigTableIF() = default;
virtual bool getRemoteCfg(EntityId remoteId, RemoteEntityCfg* cfg) = 0; virtual bool getRemoteCfg(EntityId remoteId, RemoteEntityCfg* cfg) = 0;
}; };

View File

@ -1,12 +1,12 @@
#include <catch2/catch_test_macros.hpp> #include <catch2/catch_test_macros.hpp>
#include "fsfw/cfdp.h" #include "fsfw/cfdp.h"
#include "mocks/CfdpFaultHandlerMock.h" #include "mocks/cfdp/FaultHandlerMock.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 = CfdpFaultHandlerMock(); auto fhMock = FaultHandlerMock();
auto localEntityCfg = LocalEntityCfg(localId, IndicationCfg(), fhMock); auto localEntityCfg = LocalEntityCfg(localId, IndicationCfg(), fhMock);
// auto destHandler = DestHandler(); // auto destHandler = DestHandler();

View File

@ -1,10 +1,10 @@
#include <catch2/catch_test_macros.hpp> #include <catch2/catch_test_macros.hpp>
#include "mocks/CfdpFaultHandlerMock.h" #include "mocks/cfdp/FaultHandlerMock.h"
TEST_CASE("CFDP Fault Handler", "[cfdp]") { TEST_CASE("CFDP Fault Handler", "[cfdp]") {
using namespace cfdp; using namespace cfdp;
auto fhMock = CfdpFaultHandlerMock(); auto fhMock = FaultHandlerMock();
cfdp::FaultHandlerCodes fhCode; cfdp::FaultHandlerCodes fhCode;
SECTION("State") { SECTION("State") {

View File

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

View File

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

View File

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

View File

@ -1,24 +1,26 @@
#ifndef FSFW_TESTS_CFDPFAULTHANDLERMOCK_H #ifndef FSFW_TESTS_FAULTHANDLERMOCK_H
#define FSFW_TESTS_CFDPFAULTHANDLERMOCK_H #define FSFW_TESTS_FAULTHANDLERMOCK_H
#include <map> #include <map>
#include <queue> #include <queue>
#include "fsfw/cfdp/handler/FaultHandlerBase.h" #include "fsfw/cfdp/handler/FaultHandlerBase.h"
class CfdpFaultHandlerMock : public cfdp::FaultHandlerBase { namespace cfdp {
class FaultHandlerMock : public FaultHandlerBase {
public: public:
struct FaultInfo { struct FaultInfo {
size_t callCount = 0; size_t callCount = 0;
std::queue<cfdp::ConditionCode> condCodes; std::queue<cfdp::ConditionCode> condCodes;
}; };
void noticeOfSuspensionCb(cfdp::ConditionCode code) override; void noticeOfSuspensionCb(ConditionCode code) override;
void noticeOfCancellationCb(cfdp::ConditionCode code) override; void noticeOfCancellationCb(ConditionCode code) override;
void abandonCb(cfdp::ConditionCode code) override; void abandonCb(ConditionCode code) override;
void ignoreCb(cfdp::ConditionCode code) override; void ignoreCb(ConditionCode code) override;
FaultInfo& getFhInfo(cfdp::FaultHandlerCodes fhCode); FaultInfo& getFhInfo(FaultHandlerCodes fhCode);
[[nodiscard]] bool faultCbWasCalled() const; [[nodiscard]] bool faultCbWasCalled() const;
void reset(); void reset();
@ -29,4 +31,7 @@ class CfdpFaultHandlerMock : public cfdp::FaultHandlerBase {
std::pair{cfdp::FaultHandlerCodes::NOTICE_OF_SUSPENSION, FaultInfo()}, std::pair{cfdp::FaultHandlerCodes::NOTICE_OF_SUSPENSION, FaultInfo()},
std::pair{cfdp::FaultHandlerCodes::ABANDON_TRANSACTION, FaultInfo()}}; std::pair{cfdp::FaultHandlerCodes::ABANDON_TRANSACTION, FaultInfo()}};
}; };
#endif // FSFW_TESTS_CFDPFAULTHANDLERMOCK_H
} // 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