normal queue sufficient
This commit is contained in:
parent
6d0fa36f8a
commit
935e135f1c
@ -6,11 +6,11 @@
|
|||||||
#include <array>
|
#include <array>
|
||||||
#include <catch2/catch_test_macros.hpp>
|
#include <catch2/catch_test_macros.hpp>
|
||||||
|
|
||||||
#include "mocks/MessageQueueMockBase.h"
|
#include "mocks/MessageQueueMock.h"
|
||||||
|
|
||||||
TEST_CASE("Action Helper", "[ActionHelper]") {
|
TEST_CASE("Action Helper", "[ActionHelper]") {
|
||||||
ActionHelperOwnerMockBase testDhMock;
|
ActionHelperOwnerMockBase testDhMock;
|
||||||
MessageQueueMockBase testMqMock;
|
MessageQueueMock testMqMock;
|
||||||
ActionHelper actionHelper = ActionHelper(&testDhMock, dynamic_cast<MessageQueueIF*>(&testMqMock));
|
ActionHelper actionHelper = ActionHelper(&testDhMock, dynamic_cast<MessageQueueIF*>(&testMqMock));
|
||||||
CommandMessage actionMessage;
|
CommandMessage actionMessage;
|
||||||
ActionId_t testActionId = 777;
|
ActionId_t testActionId = 777;
|
||||||
|
@ -4,6 +4,6 @@ target_sources(${FSFW_TEST_TGT} PRIVATE
|
|||||||
DeviceFdirMock.cpp
|
DeviceFdirMock.cpp
|
||||||
CookieIFMock.cpp
|
CookieIFMock.cpp
|
||||||
ComIFMock.cpp
|
ComIFMock.cpp
|
||||||
MessageQueueMockBase.cpp
|
MessageQueueMock.cpp
|
||||||
InternalErrorReporterMock.cpp
|
InternalErrorReporterMock.cpp
|
||||||
)
|
)
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
#include <fsfw/ipc/QueueFactory.h>
|
#include <fsfw/ipc/QueueFactory.h>
|
||||||
#include <fsfw/objectmanager/SystemObject.h>
|
#include <fsfw/objectmanager/SystemObject.h>
|
||||||
|
|
||||||
#include "../mocks/MessageQueueMockBase.h"
|
#include "../mocks/MessageQueueMock.h"
|
||||||
#include "tests/TestsConfig.h"
|
#include "tests/TestsConfig.h"
|
||||||
|
|
||||||
namespace lpool {
|
namespace lpool {
|
||||||
|
@ -1,21 +1,21 @@
|
|||||||
#include "MessageQueueMockBase.h"
|
#include "MessageQueueMock.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
MessageQueueMockBase::MessageQueueMockBase()
|
MessageQueueMock::MessageQueueMock()
|
||||||
: MessageQueueBase(MessageQueueIF::NO_QUEUE, MessageQueueIF::NO_QUEUE, nullptr) {}
|
: MessageQueueBase(MessageQueueIF::NO_QUEUE, MessageQueueIF::NO_QUEUE, nullptr) {}
|
||||||
|
|
||||||
MessageQueueMockBase::MessageQueueMockBase(MessageQueueId_t queueId)
|
MessageQueueMock::MessageQueueMock(MessageQueueId_t queueId)
|
||||||
: MessageQueueBase(queueId, MessageQueueIF::NO_QUEUE, nullptr) {}
|
: MessageQueueBase(queueId, MessageQueueIF::NO_QUEUE, nullptr) {}
|
||||||
|
|
||||||
bool MessageQueueMockBase::wasMessageSent() const {
|
bool MessageQueueMock::wasMessageSent() const {
|
||||||
return std::any_of(
|
return std::any_of(
|
||||||
sendMap.begin(), sendMap.end(),
|
sendMap.begin(), sendMap.end(),
|
||||||
[](const std::pair<MessageQueueId_t, SendInfo>& pair) { return pair.second.callCount > 0; });
|
[](const std::pair<MessageQueueId_t, SendInfo>& pair) { return pair.second.callCount > 0; });
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t MessageQueueMockBase::numberOfSentMessage() const {
|
size_t MessageQueueMock::numberOfSentMessage() const {
|
||||||
size_t callCount = 0;
|
size_t callCount = 0;
|
||||||
for (auto& destInfo : sendMap) {
|
for (auto& destInfo : sendMap) {
|
||||||
callCount += destInfo.second.callCount;
|
callCount += destInfo.second.callCount;
|
||||||
@ -23,7 +23,7 @@ size_t MessageQueueMockBase::numberOfSentMessage() const {
|
|||||||
return callCount;
|
return callCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t MessageQueueMockBase::numberOfSentMessage(MessageQueueId_t id) const {
|
size_t MessageQueueMock::numberOfSentMessage(MessageQueueId_t id) const {
|
||||||
auto iter = sendMap.find(id);
|
auto iter = sendMap.find(id);
|
||||||
if (iter == sendMap.end()) {
|
if (iter == sendMap.end()) {
|
||||||
return 0;
|
return 0;
|
||||||
@ -31,7 +31,7 @@ size_t MessageQueueMockBase::numberOfSentMessage(MessageQueueId_t id) const {
|
|||||||
return iter->second.callCount;
|
return iter->second.callCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t MessageQueueMockBase::clearLastReceivedMessage(bool clearCmdMsg) {
|
ReturnValue_t MessageQueueMock::clearLastReceivedMessage(bool clearCmdMsg) {
|
||||||
if (receivedMsgs.empty()) {
|
if (receivedMsgs.empty()) {
|
||||||
return MessageQueueIF::EMPTY;
|
return MessageQueueIF::EMPTY;
|
||||||
}
|
}
|
||||||
@ -40,26 +40,24 @@ ReturnValue_t MessageQueueMockBase::clearLastReceivedMessage(bool clearCmdMsg) {
|
|||||||
std::memcpy(message.getBuffer(), receivedMsgs.front().getBuffer(), message.getMessageSize());
|
std::memcpy(message.getBuffer(), receivedMsgs.front().getBuffer(), message.getMessageSize());
|
||||||
message.clearCommandMessage();
|
message.clearCommandMessage();
|
||||||
}
|
}
|
||||||
receivedMsgs.pop_front();
|
receivedMsgs.pop();
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t MessageQueueMockBase::receiveMessage(MessageQueueMessageIF* message) {
|
ReturnValue_t MessageQueueMock::receiveMessage(MessageQueueMessageIF* message) {
|
||||||
if (receivedMsgs.empty()) {
|
if (receivedMsgs.empty()) {
|
||||||
return MessageQueueIF::EMPTY;
|
return MessageQueueIF::EMPTY;
|
||||||
}
|
}
|
||||||
std::memcpy(message->getBuffer(), receivedMsgs.front().getBuffer(), message->getMessageSize());
|
std::memcpy(message->getBuffer(), receivedMsgs.front().getBuffer(), message->getMessageSize());
|
||||||
receivedMsgs.pop_front();
|
receivedMsgs.pop();
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t MessageQueueMockBase::flush(uint32_t* count) {
|
ReturnValue_t MessageQueueMock::flush(uint32_t* count) { return HasReturnvaluesIF::RETURN_FAILED; }
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
|
||||||
}
|
|
||||||
|
|
||||||
ReturnValue_t MessageQueueMockBase::sendMessageFrom(MessageQueueId_t sendTo,
|
ReturnValue_t MessageQueueMock::sendMessageFrom(MessageQueueId_t sendTo,
|
||||||
MessageQueueMessageIF* message,
|
MessageQueueMessageIF* message,
|
||||||
MessageQueueId_t sentFrom, bool ignoreFault) {
|
MessageQueueId_t sentFrom, bool ignoreFault) {
|
||||||
if (message == nullptr) {
|
if (message == nullptr) {
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
@ -71,48 +69,48 @@ ReturnValue_t MessageQueueMockBase::sendMessageFrom(MessageQueueId_t sendTo,
|
|||||||
} else {
|
} else {
|
||||||
iter->second.callCount += 1;
|
iter->second.callCount += 1;
|
||||||
createMsgCopy(messageCopy, *message);
|
createMsgCopy(messageCopy, *message);
|
||||||
iter->second.msgs.push_back(messageCopy);
|
iter->second.msgs.push(messageCopy);
|
||||||
}
|
}
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t MessageQueueMockBase::reply(MessageQueueMessageIF* message) {
|
ReturnValue_t MessageQueueMock::reply(MessageQueueMessageIF* message) {
|
||||||
return sendMessageFrom(MessageQueueIF::NO_QUEUE, message, this->getId(), false);
|
return sendMessageFrom(MessageQueueIF::NO_QUEUE, message, this->getId(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageQueueMockBase::clearMessages(bool clearCommandMessages) {
|
void MessageQueueMock::clearMessages(bool clearCommandMessages) {
|
||||||
if (not clearCommandMessages) {
|
if (not clearCommandMessages) {
|
||||||
sendMap.clear();
|
sendMap.clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (auto& destInfo : sendMap) {
|
for (auto& destInfo : sendMap) {
|
||||||
for (auto& msg : destInfo.second.msgs) {
|
while (!destInfo.second.msgs.empty()) {
|
||||||
CommandMessage message;
|
CommandMessage message;
|
||||||
std::memcpy(message.getBuffer(), destInfo.second.msgs.front().getBuffer(),
|
std::memcpy(message.getBuffer(), destInfo.second.msgs.front().getBuffer(),
|
||||||
message.getMessageSize());
|
message.getMessageSize());
|
||||||
message.clear();
|
message.clear();
|
||||||
destInfo.second.msgs.pop_front();
|
destInfo.second.msgs.pop();
|
||||||
destInfo.second.callCount--;
|
destInfo.second.callCount--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sendMap.clear();
|
sendMap.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageQueueMockBase::addReceivedMessage(MessageQueueMessageIF& msg) {
|
void MessageQueueMock::addReceivedMessage(MessageQueueMessageIF& msg) {
|
||||||
MessageQueueMessage messageCopy;
|
MessageQueueMessage messageCopy;
|
||||||
createMsgCopy(messageCopy, msg);
|
createMsgCopy(messageCopy, msg);
|
||||||
receivedMsgs.push_back(messageCopy);
|
receivedMsgs.push(messageCopy);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageQueueMockBase::createMsgCopy(MessageQueueMessageIF& into, MessageQueueMessageIF& from) {
|
void MessageQueueMock::createMsgCopy(MessageQueueMessageIF& into, MessageQueueMessageIF& from) {
|
||||||
if (from.getMessageSize() > into.getMaximumDataSize()) {
|
if (from.getMessageSize() > into.getMaximumDataSize()) {
|
||||||
throw std::invalid_argument("Passed message does not fit into message copy");
|
throw std::invalid_argument("Passed message does not fit into message copy");
|
||||||
}
|
}
|
||||||
std::memcpy(into.getBuffer(), from.getBuffer(), from.getMaximumDataSize());
|
std::memcpy(into.getBuffer(), from.getBuffer(), from.getMaximumDataSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t MessageQueueMockBase::getNextSentMessage(MessageQueueId_t id,
|
ReturnValue_t MessageQueueMock::getNextSentMessage(MessageQueueId_t id,
|
||||||
MessageQueueMessageIF& message) {
|
MessageQueueMessageIF& message) {
|
||||||
auto iter = sendMap.find(id);
|
auto iter = sendMap.find(id);
|
||||||
if (iter == sendMap.end() or iter->second.callCount == 0) {
|
if (iter == sendMap.end() or iter->second.callCount == 0) {
|
||||||
return MessageQueueIF::EMPTY;
|
return MessageQueueIF::EMPTY;
|
||||||
@ -121,12 +119,11 @@ ReturnValue_t MessageQueueMockBase::getNextSentMessage(MessageQueueId_t id,
|
|||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t MessageQueueMockBase::getNextSentMessage(MessageQueueMessageIF& message) {
|
ReturnValue_t MessageQueueMock::getNextSentMessage(MessageQueueMessageIF& message) {
|
||||||
return getNextSentMessage(MessageQueueBase::getDefaultDestination(), message);
|
return getNextSentMessage(MessageQueueBase::getDefaultDestination(), message);
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t MessageQueueMockBase::clearLastSentMessage(MessageQueueId_t destId,
|
ReturnValue_t MessageQueueMock::clearLastSentMessage(MessageQueueId_t destId, bool clearCmdMsg) {
|
||||||
bool clearCmdMsg) {
|
|
||||||
auto iter = sendMap.find(destId);
|
auto iter = sendMap.find(destId);
|
||||||
if (iter == sendMap.end()) {
|
if (iter == sendMap.end()) {
|
||||||
return MessageQueueIF::EMPTY;
|
return MessageQueueIF::EMPTY;
|
||||||
@ -134,7 +131,7 @@ ReturnValue_t MessageQueueMockBase::clearLastSentMessage(MessageQueueId_t destId
|
|||||||
return clearLastSentMessage(iter, clearCmdMsg);
|
return clearLastSentMessage(iter, clearCmdMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t MessageQueueMockBase::clearLastSentMessage(bool clearCmdMsg) {
|
ReturnValue_t MessageQueueMock::clearLastSentMessage(bool clearCmdMsg) {
|
||||||
auto iter = sendMap.find(getDefaultDestination());
|
auto iter = sendMap.find(getDefaultDestination());
|
||||||
if (iter == sendMap.end()) {
|
if (iter == sendMap.end()) {
|
||||||
return MessageQueueIF::EMPTY;
|
return MessageQueueIF::EMPTY;
|
||||||
@ -144,7 +141,7 @@ ReturnValue_t MessageQueueMockBase::clearLastSentMessage(bool clearCmdMsg) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t MessageQueueMockBase::clearLastSentMessage(
|
ReturnValue_t MessageQueueMock::clearLastSentMessage(
|
||||||
std::map<MessageQueueId_t, SendInfo>::iterator& iter, bool clearCmdMsg) {
|
std::map<MessageQueueId_t, SendInfo>::iterator& iter, bool clearCmdMsg) {
|
||||||
if (clearCmdMsg) {
|
if (clearCmdMsg) {
|
||||||
CommandMessage message;
|
CommandMessage message;
|
||||||
@ -152,11 +149,11 @@ ReturnValue_t MessageQueueMockBase::clearLastSentMessage(
|
|||||||
message.getMessageSize());
|
message.getMessageSize());
|
||||||
message.clear();
|
message.clear();
|
||||||
}
|
}
|
||||||
iter->second.msgs.pop_front();
|
iter->second.msgs.pop();
|
||||||
iter->second.callCount--;
|
iter->second.callCount--;
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
void MessageQueueMockBase::clearEmptyEntries() {
|
void MessageQueueMock::clearEmptyEntries() {
|
||||||
for (auto it = sendMap.cbegin(); it != sendMap.cend();) {
|
for (auto it = sendMap.cbegin(); it != sendMap.cend();) {
|
||||||
if (it->second.callCount == 0) {
|
if (it->second.callCount == 0) {
|
||||||
sendMap.erase(it++);
|
sendMap.erase(it++);
|
@ -14,18 +14,18 @@
|
|||||||
struct SendInfo {
|
struct SendInfo {
|
||||||
explicit SendInfo(MessageQueueMessage& initMsg, unsigned int initCallCnt = 1)
|
explicit SendInfo(MessageQueueMessage& initMsg, unsigned int initCallCnt = 1)
|
||||||
: callCount(initCallCnt) {
|
: callCount(initCallCnt) {
|
||||||
msgs.push_back(initMsg);
|
msgs.push(initMsg);
|
||||||
}
|
}
|
||||||
unsigned int callCount = 0;
|
unsigned int callCount = 0;
|
||||||
std::deque<MessageQueueMessage> msgs;
|
std::queue<MessageQueueMessage> msgs;
|
||||||
};
|
};
|
||||||
|
|
||||||
class MessageQueueMockBase : public MessageQueueBase {
|
class MessageQueueMock : public MessageQueueBase {
|
||||||
public:
|
public:
|
||||||
MessageQueueMockBase();
|
MessageQueueMock();
|
||||||
|
|
||||||
void addReceivedMessage(MessageQueueMessageIF& msg);
|
void addReceivedMessage(MessageQueueMessageIF& msg);
|
||||||
explicit MessageQueueMockBase(MessageQueueId_t queueId);
|
explicit MessageQueueMock(MessageQueueId_t queueId);
|
||||||
|
|
||||||
//! Get next message which was sent to the default destination
|
//! Get next message which was sent to the default destination
|
||||||
ReturnValue_t getNextSentMessage(MessageQueueMessageIF& message);
|
ReturnValue_t getNextSentMessage(MessageQueueMessageIF& message);
|
||||||
@ -52,7 +52,7 @@ class MessageQueueMockBase : public MessageQueueBase {
|
|||||||
private:
|
private:
|
||||||
using SendMap = std::map<MessageQueueId_t, SendInfo>;
|
using SendMap = std::map<MessageQueueId_t, SendInfo>;
|
||||||
SendMap sendMap;
|
SendMap sendMap;
|
||||||
std::deque<MessageQueueMessage> receivedMsgs;
|
std::queue<MessageQueueMessage> receivedMsgs;
|
||||||
|
|
||||||
void clearEmptyEntries();
|
void clearEmptyEntries();
|
||||||
ReturnValue_t receiveMessage(MessageQueueMessageIF* message) override;
|
ReturnValue_t receiveMessage(MessageQueueMessageIF* message) override;
|
@ -1,5 +1,5 @@
|
|||||||
target_sources(${FSFW_TEST_TGT} PRIVATE
|
target_sources(${FSFW_TEST_TGT} PRIVATE
|
||||||
TestMessageQueue.cpp
|
testMq.cpp
|
||||||
TestSemaphore.cpp
|
TestSemaphore.cpp
|
||||||
TestClock.cpp
|
TestClock.cpp
|
||||||
)
|
)
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include "fsfw/tmtcservices/TmSendHelper.h"
|
#include "fsfw/tmtcservices/TmSendHelper.h"
|
||||||
#include "mocks/InternalErrorReporterMock.h"
|
#include "mocks/InternalErrorReporterMock.h"
|
||||||
#include "mocks/MessageQueueMockBase.h"
|
#include "mocks/MessageQueueMock.h"
|
||||||
|
|
||||||
TEST_CASE("TM Send Helper", "[tm-send-helper]") {
|
TEST_CASE("TM Send Helper", "[tm-send-helper]") {
|
||||||
auto errReporter = InternalErrorReporterMock();
|
auto errReporter = InternalErrorReporterMock();
|
||||||
|
Loading…
Reference in New Issue
Block a user