diff --git a/src/fsfw/tmtcservices/TmSendHelper.cpp b/src/fsfw/tmtcservices/TmSendHelper.cpp index f8c76b75..2f57433d 100644 --- a/src/fsfw/tmtcservices/TmSendHelper.cpp +++ b/src/fsfw/tmtcservices/TmSendHelper.cpp @@ -2,8 +2,7 @@ #include "fsfw/ipc/MessageQueueSenderIF.h" -TmSendHelper::TmSendHelper(MessageQueueIF* queue, MessageQueueId_t tmtcMsgDest, - InternalErrorReporterIF *reporter) +TmSendHelper::TmSendHelper(MessageQueueIF* queue, InternalErrorReporterIF *reporter, MessageQueueId_t tmtcMsgDest) : tmtcMsgDest(tmtcMsgDest), queue(queue), errReporter(reporter) {} TmSendHelper::TmSendHelper(MessageQueueIF *queue, InternalErrorReporterIF *reporter) @@ -32,3 +31,8 @@ void TmSendHelper::setInternalErrorReporter(InternalErrorReporterIF *reporter) { errReporter = reporter; } void TmSendHelper::setMsgQueue(MessageQueueIF *queue_) { queue = queue_; } + +ReturnValue_t TmSendHelper::sendPacket(MessageQueueId_t dest, const store_address_t &storeId) { + setMsgDestination(dest); + return sendPacket(storeId); +} diff --git a/src/fsfw/tmtcservices/TmSendHelper.h b/src/fsfw/tmtcservices/TmSendHelper.h index bca0d4a2..7e11daad 100644 --- a/src/fsfw/tmtcservices/TmSendHelper.h +++ b/src/fsfw/tmtcservices/TmSendHelper.h @@ -9,13 +9,15 @@ class TmSendHelper { public: - explicit TmSendHelper(InternalErrorReporterIF* reporter); + TmSendHelper(MessageQueueIF* queue, InternalErrorReporterIF* reporter, MessageQueueId_t tmtcMsgDest); TmSendHelper(MessageQueueIF* queue, InternalErrorReporterIF* reporter); - TmSendHelper(MessageQueueIF* queue, MessageQueueId_t tmtcMsgDest, - InternalErrorReporterIF* reporter); + explicit TmSendHelper(InternalErrorReporterIF* reporter); + + void setMsgQueue(MessageQueueIF* queue); void setMsgDestination(MessageQueueId_t msgDest); void setInternalErrorReporter(InternalErrorReporterIF* reporter); + ReturnValue_t sendPacket(MessageQueueId_t dest, const store_address_t& storeId); ReturnValue_t sendPacket(const store_address_t& storeId); private: diff --git a/unittests/mocks/CMakeLists.txt b/unittests/mocks/CMakeLists.txt index 90448798..04024559 100644 --- a/unittests/mocks/CMakeLists.txt +++ b/unittests/mocks/CMakeLists.txt @@ -5,4 +5,5 @@ target_sources(${FSFW_TEST_TGT} PRIVATE CookieIFMock.cpp ComIFMock.cpp MessageQueueMockBase.cpp + InternalErrorReporterMock.cpp ) diff --git a/unittests/mocks/InternalErrorReporterMock.cpp b/unittests/mocks/InternalErrorReporterMock.cpp new file mode 100644 index 00000000..9988234b --- /dev/null +++ b/unittests/mocks/InternalErrorReporterMock.cpp @@ -0,0 +1,13 @@ +#include "InternalErrorReporterMock.h" + +InternalErrorReporterMock::InternalErrorReporterMock() = default; + +void InternalErrorReporterMock::queueMessageNotSent() { + queueMsgNotSentCallCnt++; +} +void InternalErrorReporterMock::lostTm() { + lostTmCallCnt++; +} +void InternalErrorReporterMock::storeFull() { + storeFullCallCnt++; +} diff --git a/unittests/mocks/InternalErrorReporterMock.h b/unittests/mocks/InternalErrorReporterMock.h index ccc158d0..d2921630 100644 --- a/unittests/mocks/InternalErrorReporterMock.h +++ b/unittests/mocks/InternalErrorReporterMock.h @@ -5,7 +5,14 @@ class InternalErrorReporterMock: public InternalErrorReporterIF { public: + unsigned int queueMsgNotSentCallCnt = 0; + unsigned int lostTmCallCnt = 0; + unsigned int storeFullCallCnt = 0; InternalErrorReporterMock(); + void queueMessageNotSent() override; + void lostTm() override; + void storeFull() override; + private: }; #endif // FSFW_TESTS_INTERNALERRORREPORTERMOCK_H diff --git a/unittests/mocks/MessageQueueMockBase.cpp b/unittests/mocks/MessageQueueMockBase.cpp index 8c577851..63caee26 100644 --- a/unittests/mocks/MessageQueueMockBase.cpp +++ b/unittests/mocks/MessageQueueMockBase.cpp @@ -43,10 +43,13 @@ ReturnValue_t MessageQueueMockBase::flush(uint32_t* count) { ReturnValue_t MessageQueueMockBase::sendMessageFrom(MessageQueueId_t sendTo, MessageQueueMessageIF* message, MessageQueueId_t sentFrom, bool ignoreFault) { - messageSent = true; - messageSentCounter++; - MessageQueueMessage& messageRef = *(dynamic_cast(message)); - messagesSentQueue.push(messageRef); + auto iter = sendMap.find(sendTo); + if (iter == sendMap.end()) { + sendMap.emplace(sendTo, SendInfo(message, 1)); + } else { + iter->second.callCount += 1; + iter->second.msgs.push(message); + } return HasReturnvaluesIF::RETURN_OK; } @@ -55,6 +58,12 @@ ReturnValue_t MessageQueueMockBase::reply(MessageQueueMessageIF* message) { } void MessageQueueMockBase::clearMessages(bool clearCommandMessages) { + for (const auto& destInfo: sendMap) { + if (clearCommandMessages) { + CommandMessage message; + std::memcpy(message.getBuffer(), destInfo.second.msgs.front()->getBuffer(), + message.getMessageSize()); + } while (not messagesSentQueue.empty()) { if (clearCommandMessages) { CommandMessage message; diff --git a/unittests/mocks/MessageQueueMockBase.h b/unittests/mocks/MessageQueueMockBase.h index 4a4b7ce7..e42a0a67 100644 --- a/unittests/mocks/MessageQueueMockBase.h +++ b/unittests/mocks/MessageQueueMockBase.h @@ -3,6 +3,7 @@ #include #include +#include #include "CatchDefinitions.h" #include "fsfw/ipc/CommandMessage.h" @@ -10,14 +11,21 @@ #include "fsfw/ipc/MessageQueueIF.h" #include "fsfw/ipc/MessageQueueMessage.h" +struct SendInfo { + explicit SendInfo(MessageQueueMessageIF* initMsg, unsigned int initCallCnt = 1): callCount(initCallCnt) { + msgs.push(initMsg); + } + unsigned int callCount = 0; + std::queue msgs; +}; + class MessageQueueMockBase : public MessageQueueBase { public: MessageQueueMockBase(); explicit MessageQueueMockBase(MessageQueueId_t queueId); - uint8_t messageSentCounter = 0; - bool messageSent = false; + std::map sendMap; bool wasMessageSent(uint8_t* messageSentCounter_ = nullptr, bool resetCounter = true); @@ -37,7 +45,6 @@ class MessageQueueMockBase : public MessageQueueBase { void clearMessages(bool clearCommandMessages = true); private: - std::queue messagesSentQueue; }; #endif /* FSFW_UNITTEST_TESTS_MOCKS_MESSAGEQUEUEMOCKBASE_H_ */ diff --git a/unittests/tmtcservices/testSendHelper.cpp b/unittests/tmtcservices/testSendHelper.cpp index 84ef0162..6e6fb069 100644 --- a/unittests/tmtcservices/testSendHelper.cpp +++ b/unittests/tmtcservices/testSendHelper.cpp @@ -1,7 +1,15 @@ #include #include "fsfw/tmtcservices/TmSendHelper.h" +#include "mocks/InternalErrorReporterMock.h" +#include "mocks/MessageQueueMockBase.h" TEST_CASE("TM Send Helper", "[tm-send-helper]") { - TmSendHelper sendHelper(nullptr); + auto errReporter = InternalErrorReporterMock(); + auto msgQueue = MessageQueueMockBase(); + TmSendHelper sendHelper(&msgQueue, &errReporter); + + SECTION("State") { + + } } \ No newline at end of file