diff --git a/src/Services/EventActionService.cpp b/src/Services/EventActionService.cpp index a9debbbe1c7f63e81ce26e4938582193e9fcfd3b..800d9abbd0bea9527bcef9370b2edb177908d419 100644 --- a/src/Services/EventActionService.cpp +++ b/src/Services/EventActionService.cpp @@ -8,46 +8,41 @@ void EventActionService::addEventActionDefinitions(Message &message) { uint16_t applicationID = message.readEnum16(); uint16_t eventDefinitionID = message.readEnum16(); if (eventActionDefinitionMap.find(eventDefinitionID) == eventActionDefinitionMap.end()) { - EventActionDefinition temp; - temp.enabled = true; - temp.applicationId = applicationID; - temp.eventDefinitionID = eventDefinitionID; if (message.dataSize - 4 > ECSS_TC_REQUEST_STRING_SIZE) { ErrorHandler::reportInternalError(ErrorHandler::MessageTooLarge); } else { char data[ECSS_TC_REQUEST_STRING_SIZE]; message.readString(data, message.dataSize - 4); + EventActionDefinition temp; + temp.enabled = true; + temp.applicationId = applicationID; + temp.eventDefinitionID = eventDefinitionID; temp.request = String<ECSS_TC_REQUEST_STRING_SIZE>(data); + eventActionDefinitionMap.insert(std::make_pair(eventDefinitionID, temp)); } - eventActionDefinitionMap.insert(std::make_pair(eventDefinitionID, temp)); } else { - ErrorHandler::reportError(message, - ErrorHandler::EventActionAddExistingDefinitionError); + ErrorHandler::reportError(message, ErrorHandler::EventActionAddExistingDefinitionError); } } void EventActionService::deleteEventActionDefinitions(Message &message) { message.assertTC(19, 2); - - uint16_t numberOfEventActionDefinitions = message.readUint16(); - for (uint16_t i = 0; i < numberOfEventActionDefinitions; i++) { - uint16_t applicationID = message.readEnum16(); - uint16_t eventDefinitionID = message.readEnum16(); - if (eventActionDefinitionMap.find(eventDefinitionID) != - eventActionDefinitionMap.end()) { - // I need this to buffer the first readEnum16, since cpp check fails if I don't - // use it anywhere - eventActionDefinitionMap[eventDefinitionID].applicationId = applicationID; - if (eventActionDefinitionMap[eventDefinitionID].enabled == true) { - ErrorHandler::reportError(message, - ErrorHandler::EventActionDeleteEnabledDefinitionError); - } else { - eventActionDefinitionMap.erase(eventDefinitionID); - } - } else { + uint16_t numberOfEventActionDefinitions = message.readUint16(); + for (uint16_t i = 0; i < numberOfEventActionDefinitions; i++) { + uint16_t applicationID = message.readEnum16(); + uint16_t eventDefinitionID = message.readEnum16(); + if (eventActionDefinitionMap.find(eventDefinitionID) != eventActionDefinitionMap.end()) { + // I need this to buffer the first readEnum16, since cpp check fails if I don't + // use it anywhere + eventActionDefinitionMap[eventDefinitionID].applicationId = applicationID; + if (eventActionDefinitionMap[eventDefinitionID].enabled == true) { ErrorHandler::reportError(message, - ErrorHandler::EventActionUnknownDefinitionError); + ErrorHandler::EventActionDeleteEnabledDefinitionError); + } else { + eventActionDefinitionMap.erase(eventDefinitionID); } + } else { + ErrorHandler::reportError(message, ErrorHandler::EventActionUnknownDefinitionError); } } } @@ -57,7 +52,7 @@ void EventActionService::deleteAllEventActionDefinitions(Message &message) { message.assertTC(19, 3); setEventActionFunctionStatus(false); - eventActionDefinitionMap.clear(); + eventActionDefinitionMap.clear(); } void EventActionService::enableEventActionDefinitions(Message &message) { @@ -65,24 +60,24 @@ void EventActionService::enableEventActionDefinitions(Message &message) { message.assertTC(19, 4); uint16_t numberOfEventActionDefinitions = message.readUint16(); - if (numberOfEventActionDefinitions != 0){ + if (numberOfEventActionDefinitions != 0) { for (uint16_t i = 0; i < numberOfEventActionDefinitions; i++) { uint16_t applicationID = message.readEnum16(); uint16_t eventDefinitionID = message.readEnum16(); - if (eventActionDefinitionMap.find(eventDefinitionID) != eventActionDefinitionMap - .end()) { - // This is need to pass the cpp check. The applicationId should be used - // somewhere - eventActionDefinitionMap[eventDefinitionID].applicationId = applicationID; - eventActionDefinitionMap[eventDefinitionID].enabled = true; - } else { - ErrorHandler::reportError(message, - ErrorHandler::EventActionUnknownDefinitionError); + if (eventActionDefinitionMap.find(eventDefinitionID) != eventActionDefinitionMap + .end()) { + // This is need to pass the cpp check. The applicationId should be used + // somewhere + eventActionDefinitionMap[eventDefinitionID].applicationId = applicationID; + eventActionDefinitionMap[eventDefinitionID].enabled = true; + } else { + ErrorHandler::reportError(message, + ErrorHandler::EventActionUnknownDefinitionError); } } } else { - for (auto& element : eventActionDefinitionMap) { - element.second.enabled = true; + for (auto &element : eventActionDefinitionMap) { + element.second.enabled = true; } } } @@ -92,24 +87,24 @@ void EventActionService::disableEventActionDefinitions(Message &message) { message.assertTC(19, 5); uint16_t numberOfEventActionDefinitions = message.readUint16(); - if (numberOfEventActionDefinitions != 0){ + if (numberOfEventActionDefinitions != 0) { for (uint16_t i = 0; i < numberOfEventActionDefinitions; i++) { uint16_t applicationID = message.readEnum16(); uint16_t eventDefinitionID = message.readEnum16(); - if (eventActionDefinitionMap.find(eventDefinitionID) != eventActionDefinitionMap - .end()) { - // This is need to pass the cpp check. The applicationId should be used - // somewhere - eventActionDefinitionMap[eventDefinitionID].applicationId = applicationID; - eventActionDefinitionMap[eventDefinitionID].enabled = false; - } else { - ErrorHandler::reportError(message, - ErrorHandler::EventActionUnknownDefinitionError); + if (eventActionDefinitionMap.find(eventDefinitionID) != eventActionDefinitionMap + .end()) { + // This is need to pass the cpp check. The applicationId should be used + // somewhere + eventActionDefinitionMap[eventDefinitionID].applicationId = applicationID; + eventActionDefinitionMap[eventDefinitionID].enabled = false; + } else { + ErrorHandler::reportError(message, + ErrorHandler::EventActionUnknownDefinitionError); } } } else { - for (auto& element : eventActionDefinitionMap) { - element.second.enabled = false; + for (auto &element : eventActionDefinitionMap) { + element.second.enabled = false; } } } @@ -126,7 +121,7 @@ void EventActionService::eventActionStatusReport() { Message report = createTM(7); uint8_t count = eventActionDefinitionMap.size(); report.appendUint8(count); - for (const auto& element : eventActionDefinitionMap) { + for (const auto &element : eventActionDefinitionMap) { report.appendEnum16(element.second.applicationId); report.appendEnum16(element.second.eventDefinitionID); report.appendBoolean(element.second.enabled); diff --git a/test/Services/EventActionService.cpp b/test/Services/EventActionService.cpp index 9faf7618a92aa8f3f22513ff755ab1a2622aedcb..dbc63c629e6f4ebad284adcc0822e596eae062de 100644 --- a/test/Services/EventActionService.cpp +++ b/test/Services/EventActionService.cpp @@ -14,12 +14,19 @@ TEST_CASE("Add event-action definitions TC[19,1]", "[service][st19]") { Message message(19, 1, Message::TC, 0); message.appendEnum16(0); - message.appendEnum16(2); - String<64> data = "123"; + message.appendEnum16(5); + String<128> data = "0123456789012345678901234567890123456789012345678901234567890123456789"; message.appendString(data); eventActionService.addEventActionDefinitions(message); - + CHECK(ServiceTests::thrownError(ErrorHandler::MessageTooLarge)); + CHECK(ServiceTests::countErrors() == 1); + Message message1(19, 1, Message::TC, 0); + message1.appendEnum16(0); + message1.appendEnum16(2); + data = "01234"; + message1.appendString(data); + eventActionService.addEventActionDefinitions(message1); CHECK(eventActionService.eventActionDefinitionMap[2].applicationId == 0); CHECK(eventActionService.eventActionDefinitionMap[2].eventDefinitionID == 2); CHECK(eventActionService.eventActionDefinitionMap[2].enabled == 1); @@ -30,12 +37,21 @@ TEST_CASE("Add event-action definitions TC[19,1]", "[service][st19]") { message2.appendEnum16(3); data = "456"; message2.appendString(data); - eventActionService.addEventActionDefinitions(message2); 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); + + Message message3(19, 1, Message::TC, 0); + message3.appendEnum16(1); + message3.appendEnum16(3); + data = "456"; + message3.appendString(data); + eventActionService.addEventActionDefinitions(message3); + + CHECK(ServiceTests::thrownError(ErrorHandler::EventActionAddExistingDefinitionError)); + CHECK(ServiceTests::countErrors() == 2); } TEST_CASE("Delete event-action definitions TC[19,2]", "[service][st19]") { @@ -115,6 +131,22 @@ TEST_CASE("Delete event-action definitions TC[19,2]", "[service][st19]") { CHECK(eventActionService.eventActionDefinitionMap[4].request.compare("") == 0); CHECK(eventActionService.eventActionDefinitionMap[4].enabled == 0); + Message message6(19, 2, Message::TC, 0); + message6.appendUint16(1); + message6.appendEnum16(1); + message6.appendEnum16(3); + eventActionService.deleteEventActionDefinitions(message6); + + CHECK(ServiceTests::thrownError(ErrorHandler::EventActionDeleteEnabledDefinitionError)); + CHECK(ServiceTests::countErrors() == 1); + + Message message7(19, 2, Message::TC, 0); + message7.appendUint16(1); + message7.appendEnum16(1); + message7.appendEnum16(10); + eventActionService.deleteEventActionDefinitions(message7); + CHECK(ServiceTests::thrownError(ErrorHandler::EventActionUnknownDefinitionError)); + CHECK(ServiceTests::countErrors() == 2); } TEST_CASE("Delete all event-action definitions TC[19,3]", "[service][st19]") { @@ -164,6 +196,7 @@ TEST_CASE("Delete all event-action definitions TC[19,3]", "[service][st19]") { } TEST_CASE("Enable event-action definitions TC[19,4]", "[service][st19]") { + Message message0(19, 1, Message::TC, 0); message0.appendEnum16(1); message0.appendEnum16(0); @@ -198,6 +231,14 @@ TEST_CASE("Enable event-action definitions TC[19,4]", "[service][st19]") { CHECK(eventActionService.eventActionDefinitionMap[0].enabled == 1); CHECK(eventActionService.eventActionDefinitionMap[1].enabled == 1); + + Message message7(19, 2, Message::TC, 0); + message7.appendUint16(1); + message7.appendEnum16(1); + message7.appendEnum16(10); + eventActionService.enableEventActionDefinitions(message7); + CHECK(ServiceTests::thrownError(ErrorHandler::EventActionUnknownDefinitionError)); + CHECK(ServiceTests::countErrors() == 1); } TEST_CASE("Disable event-action definitions TC[19,5]", "[service][st19]") { @@ -223,6 +264,14 @@ TEST_CASE("Disable event-action definitions TC[19,5]", "[service][st19]") { CHECK(eventActionService.eventActionDefinitionMap[0].enabled == 0); CHECK(eventActionService.eventActionDefinitionMap[1].enabled == 0); + + Message message7(19, 2, Message::TC, 0); + message7.appendUint16(1); + message7.appendEnum16(1); + message7.appendEnum16(10); + eventActionService.enableEventActionDefinitions(message7); + CHECK(ServiceTests::thrownError(ErrorHandler::EventActionUnknownDefinitionError)); + CHECK(ServiceTests::countErrors() == 1); } TEST_CASE("Request event-action definition status TC[19,6]", "[service][st19]") {