diff --git a/inc/Services/EventActionService.hpp b/inc/Services/EventActionService.hpp index aeeae0d63a90ca1780c5327f98d7323fb2a205b7..e645175b994e032fe8b4fffc87a0694cbdaf7a45 100644 --- a/inc/Services/EventActionService.hpp +++ b/inc/Services/EventActionService.hpp @@ -73,32 +73,32 @@ public: * event-action definition will be added per TC packet. That means there will be just an * application ID, an event definition ID and the TC request. */ - void addEventActionDefinitions(Message message); + void addEventActionDefinitions(Message& message); /** * TC[19,2] delete event-action definitions */ - void deleteEventActionDefinitions(Message message); + void deleteEventActionDefinitions(Message& message); /** * TC[19,3] delete all event-action definitions */ - void deleteAllEventActionDefinitions(Message message); + void deleteAllEventActionDefinitions(Message& message); /** * TC[19,4] enable event-action definitions */ - void enableEventActionDefinitions(Message message); + void enableEventActionDefinitions(Message& message); /** * TC[19,5] disable event-action definitions */ - void disableEventActionDefinitions(Message message); + void disableEventActionDefinitions(Message& message); /** * TC[19,6] report the status of each event-action definition */ - void requestEventActionDefinitionStatus(Message message); + void requestEventActionDefinitionStatus(Message& message); /** * TM[19,7] event-action status report @@ -108,12 +108,12 @@ public: /** * TC[19,8] enable the event-action function */ - void enableEventActionFunction(Message message); + void enableEventActionFunction(Message& message); /** * TC[19,9] disable the event-actioni function */ - void disableEventActionFunction(Message message); + void disableEventActionFunction(Message& message); /** * Setter for event-action function status diff --git a/src/Services/EventActionService.cpp b/src/Services/EventActionService.cpp index 56b067147600979d024d4b8e0c83037ccc1afea8..3a76e858aa7cabd99a00fd18199480c3c9e487a4 100644 --- a/src/Services/EventActionService.cpp +++ b/src/Services/EventActionService.cpp @@ -2,14 +2,14 @@ #include "Message.hpp" #include "MessageParser.hpp" -void EventActionService::addEventActionDefinitions(Message message) { +void EventActionService::addEventActionDefinitions(Message& message) { // TC[19,1] if (message.messageType == 1 && message.packetType == Message::TC && message.serviceType == 19) { uint16_t applicationID = message.readEnum16(); uint16_t eventDefinitionID = message.readEnum16(); - if (eventActionDefinitionMap.find(eventDefinitionID) != eventActionDefinitionMap.end()) { + if (eventActionDefinitionMap.find(eventDefinitionID) == eventActionDefinitionMap.end()) { EventActionDefinition temp; temp.enabled = true; temp.applicationId = applicationID; @@ -30,7 +30,7 @@ void EventActionService::addEventActionDefinitions(Message message) { } } -void EventActionService::deleteEventActionDefinitions(Message message) { +void EventActionService::deleteEventActionDefinitions(Message& message) { // TC[19,2] if (message.messageType == 2 && message.packetType == Message::TC && message.serviceType == 19) { @@ -43,7 +43,7 @@ void EventActionService::deleteEventActionDefinitions(Message message) { } } -void EventActionService::deleteAllEventActionDefinitions(Message message) { +void EventActionService::deleteAllEventActionDefinitions(Message& message) { // TC[19,3] if (message.messageType == 3 && message.packetType == Message::TC && message.serviceType == 19) { @@ -52,7 +52,7 @@ void EventActionService::deleteAllEventActionDefinitions(Message message) { } } -void EventActionService::enableEventActionDefinitions(Message message) { +void EventActionService::enableEventActionDefinitions(Message& message) { // TC[19,4] if (message.messageType == 4 && message.packetType == Message::TC && message.serviceType == 19) { @@ -76,7 +76,7 @@ void EventActionService::enableEventActionDefinitions(Message message) { } } -void EventActionService::disableEventActionDefinitions(Message message) { +void EventActionService::disableEventActionDefinitions(Message& message) { // TC[19,5] if (message.messageType == 5 && message.packetType == Message::TC && message.serviceType == 19) { @@ -100,7 +100,7 @@ void EventActionService::disableEventActionDefinitions(Message message) { } } -void EventActionService::requestEventActionDefinitionStatus(Message message) { +void EventActionService::requestEventActionDefinitionStatus(Message& message) { // TC[19,6] if (message.messageType == 6 && message.packetType == Message::TC && message.serviceType == 19) { @@ -121,7 +121,7 @@ void EventActionService::eventActionStatusReport() { storeMessage(report); } -void EventActionService::enableEventActionFunction(Message message) { +void EventActionService::enableEventActionFunction(Message& message) { // TC[19,8] if (message.messageType == 8 && message.packetType == Message::TC && message.serviceType == 19) { @@ -129,7 +129,7 @@ void EventActionService::enableEventActionFunction(Message message) { } } -void EventActionService::disableEventActionFunction(Message message) { +void EventActionService::disableEventActionFunction(Message& message) { // TC[19,9] if (message.messageType == 9 && message.packetType == Message::TC && message.serviceType == 19) { diff --git a/test/Services/EventActionService.cpp b/test/Services/EventActionService.cpp index 964e8826e64404a08c7c6c544f85c0e69408fa56..843421b918631f5d2219907a7cbed5f1f3603245 100644 --- a/test/Services/EventActionService.cpp +++ b/test/Services/EventActionService.cpp @@ -3,6 +3,7 @@ #include <Message.hpp> #include "ServiceTests.hpp" #include <etl/String.hpp> +#include <etl/map.h> #include <cstring> #include <iostream> #include <ServicePool.hpp> @@ -18,14 +19,11 @@ TEST_CASE("Add event-action definitions TC[19,1]", "[service][st09]") { message.appendString(data); eventActionService.addEventActionDefinitions(message); - CHECK(eventActionService.eventActionDefinitionArray[0].empty == 0); - CHECK(eventActionService.eventActionDefinitionArray[0].applicationId == 0); - CHECK(eventActionService.eventActionDefinitionArray[0].eventDefinitionID == 2); - CHECK(eventActionService.eventActionDefinitionArray[0].enabled == 1); - CHECK(message.readEnum16() == 0); - CHECK(message.readEnum16() == 2); - message.readString(checkstring, 3); - CHECK(eventActionService.eventActionDefinitionArray[0].request.compare(data) == 0); + + CHECK(eventActionService.eventActionDefinitionMap[2].applicationId == 0); + CHECK(eventActionService.eventActionDefinitionMap[2].eventDefinitionID == 2); + CHECK(eventActionService.eventActionDefinitionMap[2].enabled == 1); + CHECK(eventActionService.eventActionDefinitionMap[2].request.compare(data) == 0); Message message2(19, 1, Message::TC, 0); message2.appendEnum16(1); @@ -34,14 +32,10 @@ TEST_CASE("Add event-action definitions TC[19,1]", "[service][st09]") { message2.appendString(data); eventActionService.addEventActionDefinitions(message2); - CHECK(eventActionService.eventActionDefinitionArray[1].empty == 0); - CHECK(eventActionService.eventActionDefinitionArray[1].applicationId == 1); - CHECK(eventActionService.eventActionDefinitionArray[1].eventDefinitionID == 3); - CHECK(eventActionService.eventActionDefinitionArray[1].enabled == 1); - - CHECK(message2.readEnum16() == 1); - CHECK(message2.readEnum16() == 3); - CHECK(eventActionService.eventActionDefinitionArray[1].request.compare(data) == 0); + CHECK(eventActionService.eventActionDefinitionMap[3].applicationId == 1); + CHECK(eventActionService.eventActionDefinitionMap[3].eventDefinitionID == 3); + CHECK(eventActionService.eventActionDefinitionMap[3].enabled == 1); + CHECK(eventActionService.eventActionDefinitionMap[3].request.compare(data) == 0); } TEST_CASE("Delete event-action definitions TC[19,2]", "[service][st09]") { @@ -84,35 +78,30 @@ TEST_CASE("Delete event-action definitions TC[19,2]", "[service][st09]") { message.appendEnum16(2); eventActionService.deleteEventActionDefinitions(message); - CHECK(eventActionService.eventActionDefinitionArray[0].empty == 0); - CHECK(eventActionService.eventActionDefinitionArray[0].applicationId == 1); - CHECK(eventActionService.eventActionDefinitionArray[0].eventDefinitionID == 0); - CHECK(eventActionService.eventActionDefinitionArray[0].request.compare("0") == 0); - CHECK(eventActionService.eventActionDefinitionArray[0].enabled == 1); + CHECK(eventActionService.eventActionDefinitionMap[0].applicationId == 1); + CHECK(eventActionService.eventActionDefinitionMap[0].eventDefinitionID == 0); + CHECK(eventActionService.eventActionDefinitionMap[0].request.compare("0") == 0); + CHECK(eventActionService.eventActionDefinitionMap[0].enabled == 1); - CHECK(eventActionService.eventActionDefinitionArray[1].empty == 0); - CHECK(eventActionService.eventActionDefinitionArray[1].applicationId == 1); - CHECK(eventActionService.eventActionDefinitionArray[1].eventDefinitionID == 1); - CHECK(eventActionService.eventActionDefinitionArray[1].request.compare("1") == 0); - CHECK(eventActionService.eventActionDefinitionArray[1].enabled == 1); + CHECK(eventActionService.eventActionDefinitionMap[1].applicationId == 1); + CHECK(eventActionService.eventActionDefinitionMap[1].eventDefinitionID == 1); + CHECK(eventActionService.eventActionDefinitionMap[1].request.compare("1") == 0); + CHECK(eventActionService.eventActionDefinitionMap[1].enabled == 1); - CHECK(eventActionService.eventActionDefinitionArray[2].empty == 1); - CHECK(eventActionService.eventActionDefinitionArray[2].applicationId == 0); - CHECK(eventActionService.eventActionDefinitionArray[2].eventDefinitionID == 65535); - CHECK(eventActionService.eventActionDefinitionArray[2].request.compare("") == 0); - CHECK(eventActionService.eventActionDefinitionArray[2].enabled == 0); + CHECK(eventActionService.eventActionDefinitionMap[2].applicationId == 0); + CHECK(eventActionService.eventActionDefinitionMap[2].eventDefinitionID == 65535); + CHECK(eventActionService.eventActionDefinitionMap[2].request.compare("") == 0); + CHECK(eventActionService.eventActionDefinitionMap[2].enabled == 0); - CHECK(eventActionService.eventActionDefinitionArray[3].empty == 0); - CHECK(eventActionService.eventActionDefinitionArray[3].applicationId == 1); - CHECK(eventActionService.eventActionDefinitionArray[3].eventDefinitionID == 3); - CHECK(eventActionService.eventActionDefinitionArray[3].request.compare("3") == 0); - CHECK(eventActionService.eventActionDefinitionArray[3].enabled == 1); + CHECK(eventActionService.eventActionDefinitionMap[3].applicationId == 1); + CHECK(eventActionService.eventActionDefinitionMap[3].eventDefinitionID == 3); + CHECK(eventActionService.eventActionDefinitionMap[3].request.compare("3") == 0); + CHECK(eventActionService.eventActionDefinitionMap[3].enabled == 1); - CHECK(eventActionService.eventActionDefinitionArray[4].empty == 1); - CHECK(eventActionService.eventActionDefinitionArray[4].applicationId == 0); - CHECK(eventActionService.eventActionDefinitionArray[4].eventDefinitionID == 65535); - CHECK(eventActionService.eventActionDefinitionArray[4].request.compare("") == 0); - CHECK(eventActionService.eventActionDefinitionArray[4].enabled == 0); + CHECK(eventActionService.eventActionDefinitionMap[4].applicationId == 0); + CHECK(eventActionService.eventActionDefinitionMap[4].eventDefinitionID == 65535); + CHECK(eventActionService.eventActionDefinitionMap[4].request.compare("") == 0); + CHECK(eventActionService.eventActionDefinitionMap[4].enabled == 0); } @@ -152,10 +141,9 @@ TEST_CASE("Delete all event-action definitions TC[19,3]", "[service][st09]") { eventActionService.deleteAllEventActionDefinitions(message); for (int i = 0; i < 256; i++){ - CHECK(eventActionService.eventActionDefinitionArray[i].empty == 1); - CHECK(eventActionService.eventActionDefinitionArray[i].applicationId == 0); - CHECK(eventActionService.eventActionDefinitionArray[i].eventDefinitionID == 65535); - CHECK(eventActionService.eventActionDefinitionArray[i].request.compare("") == 0); + CHECK(eventActionService.eventActionDefinitionMap[i].applicationId == 0); + CHECK(eventActionService.eventActionDefinitionMap[i].eventDefinitionID == 65535); + CHECK(eventActionService.eventActionDefinitionMap[i].request.compare("") == 0); } } @@ -179,8 +167,8 @@ TEST_CASE("Enable event-action definitions TC[19,4]", "[service][st09]") { message2.appendEnum16(1); message2.appendEnum16(1); eventActionService.enableEventActionDefinitions(message2); - CHECK(eventActionService.eventActionDefinitionArray[0].enabled == 1); - CHECK(eventActionService.eventActionDefinitionArray[1].enabled == 1); + CHECK(eventActionService.eventActionDefinitionMap[0].enabled == 1); + CHECK(eventActionService.eventActionDefinitionMap[1].enabled == 1); } @@ -202,8 +190,8 @@ TEST_CASE("Disable event-action definitions TC[19,5]", "[service][st09]") { message2.appendEnum16(1); message2.appendEnum16(0); eventActionService.disableEventActionDefinitions(message2); - CHECK(eventActionService.eventActionDefinitionArray[0].enabled == 0); - CHECK(eventActionService.eventActionDefinitionArray[1].enabled == 0); + CHECK(eventActionService.eventActionDefinitionMap[0].enabled == 0); + CHECK(eventActionService.eventActionDefinitionMap[1].enabled == 0); } TEST_CASE("Request event-action definition status TC[19,6]", "[service][st09]") {