2021-01-10 12:53:01 +01:00
|
|
|
#ifndef FSFW_UNITTEST_TESTS_MOCKS_MESSAGEQUEUEMOCKBASE_H_
|
|
|
|
#define FSFW_UNITTEST_TESTS_MOCKS_MESSAGEQUEUEMOCKBASE_H_
|
|
|
|
|
|
|
|
#include <fsfw/ipc/MessageQueueIF.h>
|
|
|
|
#include <fsfw/ipc/MessageQueueMessage.h>
|
|
|
|
#include <unittest/core/CatchDefinitions.h>
|
|
|
|
#include <cstring>
|
|
|
|
|
2021-01-10 13:58:33 +01:00
|
|
|
#include <queue>
|
2021-01-10 12:53:01 +01:00
|
|
|
|
|
|
|
class MessageQueueMockBase: public MessageQueueIF {
|
|
|
|
public:
|
2021-01-10 13:58:33 +01:00
|
|
|
MessageQueueId_t myQueueId = tconst::testQueueId;
|
|
|
|
uint8_t messageSentCounter = 0;
|
2021-01-10 12:53:01 +01:00
|
|
|
bool defaultDestSet = false;
|
|
|
|
bool messageSent = false;
|
|
|
|
|
|
|
|
|
2021-01-10 13:58:33 +01:00
|
|
|
bool wasMessageSent(uint8_t* messageSentCounter = nullptr,
|
|
|
|
bool resetCounter = true) {
|
2021-01-10 12:53:01 +01:00
|
|
|
bool tempMessageSent = messageSent;
|
|
|
|
messageSent = false;
|
2021-01-10 13:58:33 +01:00
|
|
|
if(messageSentCounter != nullptr) {
|
|
|
|
*messageSentCounter = this->messageSentCounter;
|
|
|
|
}
|
|
|
|
if(resetCounter) {
|
|
|
|
this->messageSentCounter = 0;
|
|
|
|
}
|
2021-01-10 12:53:01 +01:00
|
|
|
return tempMessageSent;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ReturnValue_t reply( MessageQueueMessageIF* message ) {
|
2021-01-10 13:58:33 +01:00
|
|
|
//messageSent = true;
|
|
|
|
//lastMessage = *(dynamic_cast<MessageQueueMessage*>(message));
|
|
|
|
return sendMessage(myQueueId, message);
|
2021-01-10 12:53:01 +01:00
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
|
|
|
};
|
|
|
|
virtual ReturnValue_t receiveMessage(MessageQueueMessageIF* message,
|
|
|
|
MessageQueueId_t *receivedFrom) {
|
2021-01-10 13:58:33 +01:00
|
|
|
return receiveMessage(message);
|
2021-01-10 12:53:01 +01:00
|
|
|
}
|
|
|
|
virtual ReturnValue_t receiveMessage(MessageQueueMessageIF* message) {
|
2021-01-10 13:58:33 +01:00
|
|
|
std::memcpy(message->getBuffer(), messagesSentQueue.front().getBuffer(),
|
2021-01-10 12:53:01 +01:00
|
|
|
message->getMessageSize());
|
2021-01-10 13:58:33 +01:00
|
|
|
messagesSentQueue.pop();
|
2021-01-10 12:53:01 +01:00
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
|
|
|
}
|
|
|
|
virtual ReturnValue_t flush(uint32_t* count) {
|
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
|
|
|
}
|
|
|
|
virtual MessageQueueId_t getLastPartner() const {
|
2021-01-10 13:58:33 +01:00
|
|
|
return myQueueId;
|
2021-01-10 12:53:01 +01:00
|
|
|
}
|
|
|
|
virtual MessageQueueId_t getId() const {
|
2021-01-10 13:58:33 +01:00
|
|
|
return myQueueId;
|
2021-01-10 12:53:01 +01:00
|
|
|
}
|
|
|
|
virtual ReturnValue_t sendMessageFrom( MessageQueueId_t sendTo,
|
|
|
|
MessageQueueMessageIF* message, MessageQueueId_t sentFrom,
|
|
|
|
bool ignoreFault = false ) {
|
2021-01-10 13:58:33 +01:00
|
|
|
//messageSent = true;
|
|
|
|
//lastMessage = *(dynamic_cast<MessageQueueMessage*>(message));
|
|
|
|
//return HasReturnvaluesIF::RETURN_OK;
|
|
|
|
return sendMessage(sendTo, message);
|
2021-01-10 12:53:01 +01:00
|
|
|
}
|
|
|
|
virtual ReturnValue_t sendToDefaultFrom( MessageQueueMessageIF* message,
|
|
|
|
MessageQueueId_t sentFrom, bool ignoreFault = false ) {
|
2021-01-10 13:58:33 +01:00
|
|
|
//messageSent = true;
|
|
|
|
//lastMessage = *(dynamic_cast<MessageQueueMessage*>(message));
|
|
|
|
//return HasReturnvaluesIF::RETURN_OK;
|
|
|
|
return sendMessage(myQueueId, message);
|
2021-01-10 12:53:01 +01:00
|
|
|
}
|
|
|
|
virtual ReturnValue_t sendToDefault( MessageQueueMessageIF* message ) {
|
2021-01-10 13:58:33 +01:00
|
|
|
//messageSent = true;
|
|
|
|
//lastMessage = *(dynamic_cast<MessageQueueMessage*>(message));
|
|
|
|
return sendMessage(myQueueId, message);
|
|
|
|
}
|
|
|
|
virtual ReturnValue_t sendMessage( MessageQueueId_t sendTo,
|
|
|
|
MessageQueueMessageIF* message, bool ignoreFault = false ) override {
|
2021-01-10 12:53:01 +01:00
|
|
|
messageSent = true;
|
2021-01-10 13:58:33 +01:00
|
|
|
messageSentCounter++;
|
|
|
|
MessageQueueMessage& messageRef = *(
|
|
|
|
dynamic_cast<MessageQueueMessage*>(message));
|
|
|
|
messagesSentQueue.push(messageRef);
|
2021-01-10 12:53:01 +01:00
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
|
|
|
}
|
|
|
|
virtual void setDefaultDestination(MessageQueueId_t defaultDestination) {
|
|
|
|
myQueueId = defaultDestination;
|
|
|
|
defaultDestSet = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual MessageQueueId_t getDefaultDestination() const {
|
|
|
|
return myQueueId;
|
|
|
|
}
|
|
|
|
virtual bool isDefaultDestinationSet() const {
|
|
|
|
return defaultDestSet;
|
|
|
|
}
|
|
|
|
|
2021-01-10 13:58:33 +01:00
|
|
|
void clearMessages() {
|
|
|
|
while(not messagesSentQueue.empty()) {
|
|
|
|
messagesSentQueue.pop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::queue<MessageQueueMessage> messagesSentQueue;
|
|
|
|
//MessageQueueMessage lastMessage;
|
2021-01-10 12:53:01 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* FSFW_UNITTEST_TESTS_MOCKS_MESSAGEQUEUEMOCKBASE_H_ */
|