2020-12-27 14:20:26 +01:00
|
|
|
#include <fsfw/ipc/MessageQueueIF.h>
|
|
|
|
#include <fsfw/ipc/QueueFactory.h>
|
2020-12-27 14:14:38 +01:00
|
|
|
|
2020-10-20 17:11:23 +02:00
|
|
|
#include <array>
|
2022-02-02 10:29:30 +01:00
|
|
|
#include <catch2/catch_test_macros.hpp>
|
2020-10-20 17:11:23 +02:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
#include "fsfw_tests/unit/CatchDefinitions.h"
|
2020-10-20 17:11:23 +02:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
TEST_CASE("MessageQueue Basic Test", "[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);
|
|
|
|
|
|
|
|
SECTION("Simple Tests") {
|
|
|
|
auto result = testSenderMq->sendMessage(testReceiverMqId, &testMessage);
|
|
|
|
REQUIRE(result == retval::CATCH_OK);
|
|
|
|
MessageQueueMessage recvMessage;
|
|
|
|
result = testReceiverMq->receiveMessage(&recvMessage);
|
|
|
|
REQUIRE(result == retval::CATCH_OK);
|
|
|
|
CHECK(recvMessage.getData()[0] == 42);
|
|
|
|
|
|
|
|
result = testSenderMq->sendMessage(testReceiverMqId, &testMessage);
|
|
|
|
REQUIRE(result == retval::CATCH_OK);
|
|
|
|
MessageQueueId_t senderId = 0;
|
|
|
|
result = testReceiverMq->receiveMessage(&recvMessage, &senderId);
|
|
|
|
REQUIRE(result == retval::CATCH_OK);
|
|
|
|
CHECK(recvMessage.getData()[0] == 42);
|
|
|
|
CHECK(senderId == testSenderMqId);
|
|
|
|
senderId = testReceiverMq->getLastPartner();
|
|
|
|
CHECK(senderId == testSenderMqId);
|
|
|
|
}
|
2020-10-20 17:11:23 +02:00
|
|
|
}
|