From 806ae9b41af257886101fb266f82f34c0bbfaf02 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 6 Sep 2022 13:16:00 +0200 Subject: [PATCH] check that indication was called --- src/fsfw/cfdp/VarLenFields.h | 2 +- src/fsfw/cfdp/handler/DestHandler.cpp | 2 ++ src/fsfw/cfdp/handler/DestHandler.h | 1 + unittests/cfdp/handler/testDestHandler.cpp | 22 +++++++++++++++------- unittests/mocks/cfdp/UserMock.cpp | 12 +++++++++++- unittests/mocks/cfdp/UserMock.h | 6 ++++++ 6 files changed, 36 insertions(+), 9 deletions(-) diff --git a/src/fsfw/cfdp/VarLenFields.h b/src/fsfw/cfdp/VarLenFields.h index 7f369e0c..03664995 100644 --- a/src/fsfw/cfdp/VarLenFields.h +++ b/src/fsfw/cfdp/VarLenFields.h @@ -78,7 +78,7 @@ struct TransactionId { TransactionId(EntityId entityId, TransactionSeqNum seqNum) : entityId(std::move(entityId)), seqNum(std::move(seqNum)) {} - bool operator==(const TransactionId &other) { + bool operator==(const TransactionId &other) const { return entityId == other.entityId and seqNum == other.seqNum; } diff --git a/src/fsfw/cfdp/handler/DestHandler.cpp b/src/fsfw/cfdp/handler/DestHandler.cpp index ed529cc0..6cda227e 100644 --- a/src/fsfw/cfdp/handler/DestHandler.cpp +++ b/src/fsfw/cfdp/handler/DestHandler.cpp @@ -452,3 +452,5 @@ const cfdp::DestHandler::FsmResult& cfdp::DestHandler::updateFsmRes(uint8_t erro } return fsmRes; } + +const cfdp::TransactionId& cfdp::DestHandler::getTransactionId() const { return tp.transactionId; } diff --git a/src/fsfw/cfdp/handler/DestHandler.h b/src/fsfw/cfdp/handler/DestHandler.h index ba4bcbe3..b1c56721 100644 --- a/src/fsfw/cfdp/handler/DestHandler.h +++ b/src/fsfw/cfdp/handler/DestHandler.h @@ -121,6 +121,7 @@ class DestHandler { [[nodiscard]] CfdpStates getCfdpState() const; [[nodiscard]] TransactionStep getTransactionStep() const; + const TransactionId& getTransactionId() const; private: struct TransactionParams { diff --git a/unittests/cfdp/handler/testDestHandler.cpp b/unittests/cfdp/handler/testDestHandler.cpp index 82f6db45..388f766d 100644 --- a/unittests/cfdp/handler/testDestHandler.cpp +++ b/unittests/cfdp/handler/testDestHandler.cpp @@ -1,8 +1,8 @@ #include #include "fsfw/cfdp.h" -#include "fsfw/cfdp/pdu/MetadataPduCreator.h" #include "fsfw/cfdp/pdu/EofPduCreator.h" +#include "fsfw/cfdp/pdu/MetadataPduCreator.h" #include "mocks/AcceptsTmMock.h" #include "mocks/EventReportingProxyMock.h" #include "mocks/FilesystemMock.h" @@ -20,11 +20,11 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") { MessageQueueMock mqMock(destQueueId); EntityId localId = EntityId(UnsignedByteField(2)); EntityId remoteId = EntityId(UnsignedByteField(3)); - auto fhMock = FaultHandlerMock(); - auto localEntityCfg = LocalEntityCfg(localId, IndicationCfg(), fhMock); - auto fsMock = FilesystemMock(); - auto userMock = UserMock(fsMock); - auto remoteCfgTableMock = RemoteConfigTableMock(); + FaultHandlerMock fhMock; + LocalEntityCfg localEntityCfg(localId, IndicationCfg(), fhMock); + FilesystemMock fsMock; + UserMock userMock(fsMock); + RemoteConfigTableMock remoteCfgTableMock; PacketInfoList<64> packetInfoList; LostSegmentsList<128> lostSegmentsList; DestHandlerParams dp(localEntityCfg, userMock, remoteCfgTableMock, packetInfoList, @@ -74,7 +74,8 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") { REQUIRE(tcStore.getFreeElement(&storeId, metadataCreator.getSerializedSize(), &ptr) == OK); size_t serLen = 0; REQUIRE(metadataCreator.serialize(ptr, serLen, metadataCreator.getSerializedSize()) == OK); - PacketInfo packetInfo(metadataCreator.getPduType(), metadataCreator.getDirectiveCode(), storeId); + PacketInfo packetInfo(metadataCreator.getPduType(), metadataCreator.getDirectiveCode(), + storeId); packetInfoList.push_back(packetInfo); destHandler.performStateMachine(); REQUIRE(res.result == OK); @@ -82,6 +83,13 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") { // Assert that the packet was deleted after handling REQUIRE(not tcStore.hasDataAtId(storeId)); destHandler.performStateMachine(); + REQUIRE(userMock.metadataRecvd.size() == 1); + MetadataRecvdParams& params = userMock.metadataRecvd.back(); + REQUIRE(params.id == destHandler.getTransactionId()); + REQUIRE(params.sourceId.getValue() == 3); + REQUIRE(params.fileSize == 0); + REQUIRE(strcmp(params.destFileName, "hello-cpy.txt") == 0); + REQUIRE(strcmp(params.sourceFileName, "hello.txt") == 0); REQUIRE(fsMock.fileMap.find("hello-cpy.txt") != fsMock.fileMap.end()); REQUIRE(res.result == OK); REQUIRE(res.callStatus == CallStatus::CALL_AFTER_DELAY); diff --git a/unittests/mocks/cfdp/UserMock.cpp b/unittests/mocks/cfdp/UserMock.cpp index 876c2e81..f701a28b 100644 --- a/unittests/mocks/cfdp/UserMock.cpp +++ b/unittests/mocks/cfdp/UserMock.cpp @@ -10,7 +10,12 @@ void UserMock::abandonedIndication(const TransactionId& id, cfdp::ConditionCode uint64_t progress) {} void UserMock::eofRecvIndication(const TransactionId& id) {} void UserMock::transactionFinishedIndication(const TransactionFinishedParams& finishedParams) {} -void UserMock::metadataRecvdIndication(const MetadataRecvdParams& params) {} + +void UserMock::metadataRecvdIndication(const MetadataRecvdParams& params) { + MetadataRecvdParams copy = params; + metadataRecvd.push(copy); +} + void UserMock::fileSegmentRecvdIndication(const FileSegmentRecvdParams& params) {} void UserMock::reportIndication(const TransactionId& id, StatusReportIF& report) {} void UserMock::suspendedIndication(const TransactionId& id, ConditionCode code) {} @@ -18,4 +23,9 @@ void UserMock::resumedIndication(const TransactionId& id, size_t progress) {} void UserMock::faultIndication(const TransactionId& id, cfdp::ConditionCode code, size_t progress) { } +void UserMock::reset() { + auto empty = std::queue(); + metadataRecvd.swap(empty); +} + } // namespace cfdp diff --git a/unittests/mocks/cfdp/UserMock.h b/unittests/mocks/cfdp/UserMock.h index f3a5bfd9..523392bd 100644 --- a/unittests/mocks/cfdp/UserMock.h +++ b/unittests/mocks/cfdp/UserMock.h @@ -1,7 +1,10 @@ #ifndef FSFW_TESTS_CFDP_USERMOCK_H #define FSFW_TESTS_CFDP_USERMOCK_H +#include + #include "fsfw/cfdp/handler/UserBase.h" + namespace cfdp { class UserMock : public UserBase { @@ -19,6 +22,9 @@ class UserMock : public UserBase { 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 metadataRecvd; + void reset(); }; } // namespace cfdp