From 0cb15e901eee6ebd1482c2cdfd8ae4f6dfa677b2 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 9 Aug 2022 19:00:47 +0200 Subject: [PATCH] new cfdp mock folder, added additional cfdp mocks --- src/fsfw/cfdp/handler/RemoteConfigTableIF.h | 1 + unittests/cfdp/handler/testDestHandler.cpp | 4 +-- unittests/cfdp/handler/testFaultHandler.cpp | 4 +-- unittests/mocks/CMakeLists.txt | 5 ++-- unittests/mocks/cfdp/CMakeLists.txt | 1 + .../FaultHandlerMock.cpp} | 20 +++++++++------ .../FaultHandlerMock.h} | 23 ++++++++++------- .../mocks/cfdp/RemoteConfigTableMock.cpp | 6 +++++ unittests/mocks/cfdp/RemoteConfigTableMock.h | 15 +++++++++++ unittests/mocks/cfdp/UserMock.cpp | 16 ++++++++++++ unittests/mocks/cfdp/UserMock.h | 25 +++++++++++++++++++ 11 files changed, 97 insertions(+), 23 deletions(-) create mode 100644 unittests/mocks/cfdp/CMakeLists.txt rename unittests/mocks/{CfdpFaultHandlerMock.cpp => cfdp/FaultHandlerMock.cpp} (59%) rename unittests/mocks/{CfdpFaultHandlerMock.h => cfdp/FaultHandlerMock.h} (56%) create mode 100644 unittests/mocks/cfdp/RemoteConfigTableMock.cpp create mode 100644 unittests/mocks/cfdp/RemoteConfigTableMock.h create mode 100644 unittests/mocks/cfdp/UserMock.cpp create mode 100644 unittests/mocks/cfdp/UserMock.h diff --git a/src/fsfw/cfdp/handler/RemoteConfigTableIF.h b/src/fsfw/cfdp/handler/RemoteConfigTableIF.h index c757fe7e..767492d5 100644 --- a/src/fsfw/cfdp/handler/RemoteConfigTableIF.h +++ b/src/fsfw/cfdp/handler/RemoteConfigTableIF.h @@ -6,6 +6,7 @@ namespace cfdp { class RemoteConfigTableIF { + public: virtual ~RemoteConfigTableIF() = default; virtual bool getRemoteCfg(EntityId remoteId, RemoteEntityCfg* cfg) = 0; }; diff --git a/unittests/cfdp/handler/testDestHandler.cpp b/unittests/cfdp/handler/testDestHandler.cpp index 8d971361..d963b6c7 100644 --- a/unittests/cfdp/handler/testDestHandler.cpp +++ b/unittests/cfdp/handler/testDestHandler.cpp @@ -1,12 +1,12 @@ #include #include "fsfw/cfdp.h" -#include "mocks/CfdpFaultHandlerMock.h" +#include "mocks/cfdp/FaultHandlerMock.h" TEST_CASE("CFDP Dest Handler", "[cfdp]") { using namespace cfdp; EntityId localId = EntityId(UnsignedByteField(2)); - auto fhMock = CfdpFaultHandlerMock(); + auto fhMock = FaultHandlerMock(); auto localEntityCfg = LocalEntityCfg(localId, IndicationCfg(), fhMock); // auto destHandler = DestHandler(); diff --git a/unittests/cfdp/handler/testFaultHandler.cpp b/unittests/cfdp/handler/testFaultHandler.cpp index 945e09b8..559744d7 100644 --- a/unittests/cfdp/handler/testFaultHandler.cpp +++ b/unittests/cfdp/handler/testFaultHandler.cpp @@ -1,10 +1,10 @@ #include -#include "mocks/CfdpFaultHandlerMock.h" +#include "mocks/cfdp/FaultHandlerMock.h" TEST_CASE("CFDP Fault Handler", "[cfdp]") { using namespace cfdp; - auto fhMock = CfdpFaultHandlerMock(); + auto fhMock = FaultHandlerMock(); cfdp::FaultHandlerCodes fhCode; SECTION("State") { diff --git a/unittests/mocks/CMakeLists.txt b/unittests/mocks/CMakeLists.txt index 0ee7bf1e..e15f3d71 100644 --- a/unittests/mocks/CMakeLists.txt +++ b/unittests/mocks/CMakeLists.txt @@ -14,5 +14,6 @@ target_sources( PusDistributorMock.cpp CcsdsCheckerMock.cpp AcceptsTcMock.cpp - StorageManagerMock.cpp - CfdpFaultHandlerMock.cpp) + StorageManagerMock.cpp) + +add_subdirectory(cfdp) diff --git a/unittests/mocks/cfdp/CMakeLists.txt b/unittests/mocks/cfdp/CMakeLists.txt new file mode 100644 index 00000000..0fa0890c --- /dev/null +++ b/unittests/mocks/cfdp/CMakeLists.txt @@ -0,0 +1 @@ +target_sources(${FSFW_TEST_TGT} PRIVATE FaultHandlerMock.cpp UserMock.cpp RemoteConfigTableMock.cpp) diff --git a/unittests/mocks/CfdpFaultHandlerMock.cpp b/unittests/mocks/cfdp/FaultHandlerMock.cpp similarity index 59% rename from unittests/mocks/CfdpFaultHandlerMock.cpp rename to unittests/mocks/cfdp/FaultHandlerMock.cpp index 3f7c8896..26bebda5 100644 --- a/unittests/mocks/CfdpFaultHandlerMock.cpp +++ b/unittests/mocks/cfdp/FaultHandlerMock.cpp @@ -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); info.callCount++; 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); info.callCount++; info.condCodes.push(code); } -void CfdpFaultHandlerMock::abandonCb(cfdp::ConditionCode code) { +void FaultHandlerMock::abandonCb(cfdp::ConditionCode code) { auto& info = fhInfoMap.at(cfdp::FaultHandlerCodes::ABANDON_TRANSACTION); info.callCount++; info.condCodes.push(code); } -void CfdpFaultHandlerMock::ignoreCb(cfdp::ConditionCode code) { +void FaultHandlerMock::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) { +FaultHandlerMock::FaultInfo& FaultHandlerMock::getFhInfo(cfdp::FaultHandlerCodes 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(), [](const std::pair& pair) { return pair.second.callCount > 0; }); } + +} // namespace cfdp diff --git a/unittests/mocks/CfdpFaultHandlerMock.h b/unittests/mocks/cfdp/FaultHandlerMock.h similarity index 56% rename from unittests/mocks/CfdpFaultHandlerMock.h rename to unittests/mocks/cfdp/FaultHandlerMock.h index 721cf7e0..a35d3d2b 100644 --- a/unittests/mocks/CfdpFaultHandlerMock.h +++ b/unittests/mocks/cfdp/FaultHandlerMock.h @@ -1,24 +1,26 @@ -#ifndef FSFW_TESTS_CFDPFAULTHANDLERMOCK_H -#define FSFW_TESTS_CFDPFAULTHANDLERMOCK_H +#ifndef FSFW_TESTS_FAULTHANDLERMOCK_H +#define FSFW_TESTS_FAULTHANDLERMOCK_H #include #include #include "fsfw/cfdp/handler/FaultHandlerBase.h" -class CfdpFaultHandlerMock : public cfdp::FaultHandlerBase { +namespace cfdp { + +class FaultHandlerMock : public FaultHandlerBase { public: struct FaultInfo { size_t callCount = 0; std::queue 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; + void noticeOfSuspensionCb(ConditionCode code) override; + void noticeOfCancellationCb(ConditionCode code) override; + void abandonCb(ConditionCode code) override; + void ignoreCb(ConditionCode code) override; - FaultInfo& getFhInfo(cfdp::FaultHandlerCodes fhCode); + FaultInfo& getFhInfo(FaultHandlerCodes fhCode); [[nodiscard]] bool faultCbWasCalled() const; void reset(); @@ -29,4 +31,7 @@ class CfdpFaultHandlerMock : public cfdp::FaultHandlerBase { std::pair{cfdp::FaultHandlerCodes::NOTICE_OF_SUSPENSION, FaultInfo()}, std::pair{cfdp::FaultHandlerCodes::ABANDON_TRANSACTION, FaultInfo()}}; }; -#endif // FSFW_TESTS_CFDPFAULTHANDLERMOCK_H + +} // namespace cfdp + +#endif // FSFW_TESTS_FAULTHANDLERMOCK_H diff --git a/unittests/mocks/cfdp/RemoteConfigTableMock.cpp b/unittests/mocks/cfdp/RemoteConfigTableMock.cpp new file mode 100644 index 00000000..83827a36 --- /dev/null +++ b/unittests/mocks/cfdp/RemoteConfigTableMock.cpp @@ -0,0 +1,6 @@ +#include "RemoteConfigTableMock.h" + +bool cfdp::RemoteConfigTableMock::getRemoteCfg(cfdp::EntityId remoteId, + cfdp::RemoteEntityCfg *cfg) { + return false; +} diff --git a/unittests/mocks/cfdp/RemoteConfigTableMock.h b/unittests/mocks/cfdp/RemoteConfigTableMock.h new file mode 100644 index 00000000..7ac25ba7 --- /dev/null +++ b/unittests/mocks/cfdp/RemoteConfigTableMock.h @@ -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 diff --git a/unittests/mocks/cfdp/UserMock.cpp b/unittests/mocks/cfdp/UserMock.cpp new file mode 100644 index 00000000..c8b3b940 --- /dev/null +++ b/unittests/mocks/cfdp/UserMock.cpp @@ -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() {} + diff --git a/unittests/mocks/cfdp/UserMock.h b/unittests/mocks/cfdp/UserMock.h new file mode 100644 index 00000000..b32e698a --- /dev/null +++ b/unittests/mocks/cfdp/UserMock.h @@ -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