2021-10-07 13:24:46 +02:00
|
|
|
#include "testMq.h"
|
2020-12-01 16:50:02 +01:00
|
|
|
|
2020-12-27 15:15:51 +01:00
|
|
|
#include <fsfw/ipc/MessageQueueIF.h>
|
|
|
|
#include <fsfw/ipc/QueueFactory.h>
|
2020-10-20 17:11:23 +02:00
|
|
|
|
|
|
|
#include <array>
|
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
#include "fsfw_tests/internal/UnittDefinitions.h"
|
|
|
|
|
2020-10-20 17:11:23 +02:00
|
|
|
void testmq::testMq() {
|
2022-02-02 10:29:30 +01:00
|
|
|
std::string id = "[testMq]";
|
|
|
|
MessageQueueIF* testSenderMq = QueueFactory::instance()->createMessageQueue(1);
|
|
|
|
MessageQueueId_t testSenderMqId = testSenderMq->getId();
|
|
|
|
|
|
|
|
MessageQueueIF* testReceiverMq = QueueFactory::instance()->createMessageQueue(1);
|
|
|
|
MessageQueueId_t testReceiverMqId = testReceiverMq->getId();
|
|
|
|
std::array<uint8_t, 20> testData{0};
|
|
|
|
testData[0] = 42;
|
|
|
|
MessageQueueMessage testMessage(testData.data(), 1);
|
|
|
|
testSenderMq->setDefaultDestination(testReceiverMqId);
|
|
|
|
|
|
|
|
auto result = testSenderMq->sendMessage(testReceiverMqId, &testMessage);
|
2022-08-15 20:28:16 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-02-02 10:29:30 +01:00
|
|
|
unitt::put_error(id);
|
|
|
|
}
|
|
|
|
MessageQueueMessage recvMessage;
|
|
|
|
result = testReceiverMq->receiveMessage(&recvMessage);
|
2022-08-15 20:28:16 +02:00
|
|
|
if (result != returnvalue::OK or recvMessage.getData()[0] != 42) {
|
2022-02-02 10:29:30 +01:00
|
|
|
unitt::put_error(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
result = testSenderMq->sendMessage(testReceiverMqId, &testMessage);
|
2022-08-15 20:28:16 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-02-02 10:29:30 +01:00
|
|
|
unitt::put_error(id);
|
|
|
|
}
|
|
|
|
MessageQueueId_t senderId = 0;
|
|
|
|
result = testReceiverMq->receiveMessage(&recvMessage, &senderId);
|
2022-08-15 20:28:16 +02:00
|
|
|
if (result != returnvalue::OK or recvMessage.getData()[0] != 42) {
|
2022-02-02 10:29:30 +01:00
|
|
|
unitt::put_error(id);
|
|
|
|
}
|
|
|
|
if (senderId != testSenderMqId) {
|
|
|
|
unitt::put_error(id);
|
|
|
|
}
|
|
|
|
senderId = testReceiverMq->getLastPartner();
|
|
|
|
if (senderId != testSenderMqId) {
|
|
|
|
unitt::put_error(id);
|
|
|
|
}
|
2020-10-20 17:11:23 +02:00
|
|
|
}
|