2020-12-13 21:58:54 +01:00
|
|
|
#include "../../ipc/MessageQueueIF.h"
|
|
|
|
#include "../../ipc/QueueFactory.h"
|
|
|
|
#include <catch.hpp>
|
2020-10-20 17:12:56 +02:00
|
|
|
#include <array>
|
2020-12-13 21:58:54 +01:00
|
|
|
#include "../../core/CatchDefinitions.h"
|
2020-10-20 17:12:56 +02: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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|