diff --git a/test/Services/EventActionService.cpp b/test/Services/EventActionService.cpp index 7368b058466ccf9dbb48dec6101263adf83517d4..df396eea301ce1da299d603ec57e8d04ed3e8b7b 100644 --- a/test/Services/EventActionService.cpp +++ b/test/Services/EventActionService.cpp @@ -15,7 +15,8 @@ TEST_CASE("Add event-action definitions TC[19,1]", "[service][st19]") { // Add a message that is too large to check for the corresponding error Message message(19, 1, Message::TC, 0); message.appendEnum16(0); - message.appendEnum16(5); + message.appendEnum16(1); + message.appendEnum16(1); String<128> data = "0123456789012345678901234567890123456789012345678901234567890123456789"; message.appendString(data); @@ -27,74 +28,43 @@ TEST_CASE("Add event-action definitions TC[19,1]", "[service][st19]") { Message message1(19, 1, Message::TC, 0); message1.appendEnum16(0); message1.appendEnum16(2); + message1.appendEnum16(1); 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 == 0); - CHECK(eventActionService.eventActionDefinitionMap[2].request.compare(data) == 0); + + CHECK(eventActionService.eventActionDefinitionMap.lower_bound(2)->second.applicationId == 0); + CHECK(eventActionService.eventActionDefinitionMap.lower_bound(2)->second.eventDefinitionID == 2); + CHECK(eventActionService.eventActionDefinitionMap.lower_bound(2)->second.enabled == 0); + CHECK(eventActionService.eventActionDefinitionMap.lower_bound(2)->second.request.compare(data) == 0); // Add a second event-action definition Message message2(19, 1, Message::TC, 0); message2.appendEnum16(1); message2.appendEnum16(3); + message2.appendEnum16(1); 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 == 0); - CHECK(eventActionService.eventActionDefinitionMap[3].request.compare(data) == 0); - - // Enable an event-action definition for the purposes of adding an event-action definition - // that exists already and is enabled to check for the corresponding error. - Message message4(19, 4, Message::TC, 0); - message4.appendUint16(1); - message4.appendEnum16(1); - message4.appendEnum16(3); - eventActionService.enableEventActionDefinitions(message4); - - // Add an already existing event-action definition - Message message3(19, 1, Message::TC, 0); - message3.appendEnum16(1); - message3.appendEnum16(3); - data = "789"; - message3.appendString(data); - eventActionService.addEventActionDefinitions(message3); - CHECK(ServiceTests::thrownError(ErrorHandler::EventActionAddEnabledDefinitionError)); - CHECK(ServiceTests::countErrors() == 2); - - // Disable an event-action definition for the purposes of adding an event-action definition - // that exists already and is disabled to check for any errors that shoudln't be thrown. - Message message5(19, 5, Message::TC, 0); - message5.appendUint16(1); - message5.appendEnum16(1); - message5.appendEnum16(3); - eventActionService.disableEventActionDefinitions(message5); + CHECK(eventActionService.eventActionDefinitionMap.lower_bound(3)->second.applicationId == 1); + CHECK(eventActionService.eventActionDefinitionMap.lower_bound(3)->second.eventDefinitionID == 3); + CHECK(eventActionService.eventActionDefinitionMap.lower_bound(3)->second.enabled == 0); + CHECK(eventActionService.eventActionDefinitionMap.lower_bound(3)->second.request.compare(data) == 0); - Message message6(19, 1, Message::TC, 0); - message6.appendEnum16(1); - message6.appendEnum16(3); - data = "789"; - message6.appendString(data); - eventActionService.addEventActionDefinitions(message6); - - // Check that the addition was done correctly and no errors occured - CHECK(eventActionService.eventActionDefinitionMap[3].applicationId == 1); - CHECK(eventActionService.eventActionDefinitionMap[3].eventDefinitionID == 3); - CHECK(eventActionService.eventActionDefinitionMap[3].enabled == 0); - CHECK(eventActionService.eventActionDefinitionMap[3].request.compare(data) == 0); + // Adding the same message to check for error + eventActionService.addEventActionDefinitions(message2); + CHECK(ServiceTests::thrownError(ErrorHandler::EventActionEventActionDefinitionIDExistsError)); CHECK(ServiceTests::countErrors() == 2); } TEST_CASE("Delete event-action definitions TC[19,2]", "[service][st19]") { - // Add messages for the purupose of deleting them + // Add messages for the purpose of deleting them Message message0(19, 1, Message::TC, 0); message0.appendEnum16(1); message0.appendEnum16(0); + message0.appendEnum16(1); String<64> data = "0"; message0.appendString(data); eventActionService.addEventActionDefinitions(message0); @@ -102,6 +72,7 @@ TEST_CASE("Delete event-action definitions TC[19,2]", "[service][st19]") { Message message1(19, 1, Message::TC, 0); message1.appendEnum16(1); message1.appendEnum16(1); + message1.appendEnum16(1); data = "1"; message1.appendString(data); eventActionService.addEventActionDefinitions(message1); @@ -109,70 +80,45 @@ TEST_CASE("Delete event-action definitions TC[19,2]", "[service][st19]") { Message message2(19, 1, Message::TC, 0); message2.appendEnum16(1); message2.appendEnum16(2); + message2.appendEnum16(1); data = "2"; message2.appendString(data); eventActionService.addEventActionDefinitions(message2); - Message message3(19, 1, Message::TC, 0); - message3.appendEnum16(1); - message3.appendEnum16(3); - data = "3"; - message3.appendString(data); - eventActionService.addEventActionDefinitions(message3); - - Message message4(19, 1, Message::TC, 0); - message4.appendEnum16(1); - message4.appendEnum16(4); - data = "4"; - message4.appendString(data); - eventActionService.addEventActionDefinitions(message4); - Message message5(19, 2, Message::TC, 0); - message5.appendUint16(2); - message5.appendEnum16(1); - message5.appendEnum16(4); + message5.appendUint16(1); message5.appendEnum16(1); message5.appendEnum16(2); + message5.appendEnum16(1); eventActionService.deleteEventActionDefinitions(message5); // Checking the values after deleting some definitions - 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 == 0); - - 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 == 0); + CHECK(eventActionService.eventActionDefinitionMap.lower_bound(0)->second.applicationId == 1); + CHECK(eventActionService.eventActionDefinitionMap.lower_bound(0)->second.eventDefinitionID == 0); + CHECK(eventActionService.eventActionDefinitionMap.lower_bound(0)->second.request.compare("0") == 0); + CHECK(eventActionService.eventActionDefinitionMap.lower_bound(0)->second.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.eventActionDefinitionMap.lower_bound(1)->second.applicationId == 1); + CHECK(eventActionService.eventActionDefinitionMap.lower_bound(1)->second.eventDefinitionID == 1); + CHECK(eventActionService.eventActionDefinitionMap.lower_bound(1)->second.request.compare("1") == 0); + CHECK(eventActionService.eventActionDefinitionMap.lower_bound(1)->second.enabled == 0); - 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 == 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); + CHECK(eventActionService.eventActionDefinitionMap.find(2) == eventActionService.eventActionDefinitionMap.end()); // Enabling a definition to check for errors in the case of an attempt to delete it Message message8(19, 4, Message::TC, 0); message8.appendUint16(1); message8.appendEnum16(1); - message8.appendEnum16(3); + message8.appendEnum16(1); + message8.appendEnum16(1); eventActionService.enableEventActionDefinitions(message8); Message message6(19, 2, Message::TC, 0); message6.appendUint16(1); message6.appendEnum16(1); - message6.appendEnum16(3); + message6.appendEnum16(1); + message6.appendEnum16(1); eventActionService.deleteEventActionDefinitions(message6); // Checking for errors in the case mentioned above @@ -184,9 +130,21 @@ TEST_CASE("Delete event-action definitions TC[19,2]", "[service][st19]") { message7.appendUint16(1); message7.appendEnum16(1); message7.appendEnum16(10); + message7.appendEnum16(1); eventActionService.deleteEventActionDefinitions(message7); - CHECK(ServiceTests::thrownError(ErrorHandler::EventActionUnknownDefinitionError)); + + CHECK(ServiceTests::thrownError(ErrorHandler::EventActionUnknownEventDefinitionError)); CHECK(ServiceTests::countErrors() == 2); + + Message message9(19, 2, Message::TC, 0); + message9.appendUint16(1); + message9.appendEnum16(1); + message9.appendEnum16(1); + message9.appendEnum16(10); + eventActionService.deleteEventActionDefinitions(message9); + + CHECK(ServiceTests::thrownError(ErrorHandler::EventActionUnknownEventActionDefinitionIDError)); + CHECK(ServiceTests::countErrors() == 3); } TEST_CASE("Delete all event-action definitions TC[19,3]", "[service][st19]") { @@ -195,6 +153,7 @@ TEST_CASE("Delete all event-action definitions TC[19,3]", "[service][st19]") { Message message0(19, 1, Message::TC, 0); message0.appendEnum16(1); message0.appendEnum16(0); + message0.appendEnum16(1); String<64> data = "0"; message0.appendString(data); eventActionService.addEventActionDefinitions(message0); @@ -202,6 +161,7 @@ TEST_CASE("Delete all event-action definitions TC[19,3]", "[service][st19]") { Message message1(19, 1, Message::TC, 0); message1.appendEnum16(1); message1.appendEnum16(1); + message1.appendEnum16(1); data = "1"; message1.appendString(data); eventActionService.addEventActionDefinitions(message1); @@ -209,6 +169,7 @@ TEST_CASE("Delete all event-action definitions TC[19,3]", "[service][st19]") { Message message2(19, 1, Message::TC, 0); message2.appendEnum16(1); message2.appendEnum16(2); + message2.appendEnum16(1); data = "2"; message2.appendString(data); eventActionService.addEventActionDefinitions(message2); @@ -216,6 +177,7 @@ TEST_CASE("Delete all event-action definitions TC[19,3]", "[service][st19]") { Message message3(19, 1, Message::TC, 0); message3.appendEnum16(1); message3.appendEnum16(3); + message3.appendEnum16(1); data = "3"; message3.appendString(data); eventActionService.addEventActionDefinitions(message3); @@ -223,6 +185,7 @@ TEST_CASE("Delete all event-action definitions TC[19,3]", "[service][st19]") { Message message4(19, 1, Message::TC, 0); message4.appendEnum16(1); message4.appendEnum16(4); + message4.appendEnum16(1); data = "4"; message4.appendString(data); eventActionService.addEventActionDefinitions(message4); @@ -232,9 +195,7 @@ TEST_CASE("Delete all event-action definitions TC[19,3]", "[service][st19]") { // Checking the content of the map for (int i = 0; i < 256; i++){ - CHECK(eventActionService.eventActionDefinitionMap[i].applicationId == 0); - CHECK(eventActionService.eventActionDefinitionMap[i].eventDefinitionID == 65535); - CHECK(eventActionService.eventActionDefinitionMap[i].request.compare("") == 0); + CHECK(eventActionService.eventActionDefinitionMap.find(i) == eventActionService.eventActionDefinitionMap.end()); } } @@ -244,6 +205,7 @@ TEST_CASE("Enable event-action definitions TC[19,4]", "[service][st19]") { Message message0(19, 1, Message::TC, 0); message0.appendEnum16(1); message0.appendEnum16(0); + message0.appendEnum16(1); String<64> data = "0"; message0.appendString(data); eventActionService.addEventActionDefinitions(message0); @@ -251,13 +213,14 @@ TEST_CASE("Enable event-action definitions TC[19,4]", "[service][st19]") { Message message1(19, 1, Message::TC, 0); message1.appendEnum16(1); message1.appendEnum16(1); + message1.appendEnum16(1); data = "00"; message1.appendString(data); eventActionService.addEventActionDefinitions(message1); // Checking their enabled status - CHECK(eventActionService.eventActionDefinitionMap[0].enabled == 0); - CHECK(eventActionService.eventActionDefinitionMap[1].enabled == 0); + CHECK(eventActionService.eventActionDefinitionMap.lower_bound(0)->second.enabled == 0); + CHECK(eventActionService.eventActionDefinitionMap.lower_bound(1)->second.enabled == 0); // Creating a message to enable the previous messages Message message3(19, 4, Message::TC, 0); @@ -266,11 +229,13 @@ TEST_CASE("Enable event-action definitions TC[19,4]", "[service][st19]") { message3.appendEnum16(0); message3.appendEnum16(1); message3.appendEnum16(1); + message3.appendEnum16(1); + message3.appendEnum16(1); eventActionService.enableEventActionDefinitions(message3); // Checking if the messages are enabled - CHECK(eventActionService.eventActionDefinitionMap[0].enabled == 1); - CHECK(eventActionService.eventActionDefinitionMap[1].enabled == 1); + CHECK(eventActionService.eventActionDefinitionMap.lower_bound(0)->second.enabled == 1); + CHECK(eventActionService.eventActionDefinitionMap.lower_bound(1)->second.enabled == 1); // Checking for errors in the case of an attempt to enable an unknown definition Message message7(19, 4, Message::TC, 0); @@ -279,16 +244,28 @@ TEST_CASE("Enable event-action definitions TC[19,4]", "[service][st19]") { message7.appendEnum16(6); eventActionService.enableEventActionDefinitions(message7); - CHECK(ServiceTests::thrownError(ErrorHandler::EventActionUnknownDefinitionError)); + CHECK(ServiceTests::thrownError(ErrorHandler::EventActionUnknownEventDefinitionError)); CHECK(ServiceTests::countErrors() == 1); + + // Checking for errors in the case of an attempt to enable an unknown definition + Message message8(19, 4, Message::TC, 0); + message8.appendUint16(1); + message8.appendEnum16(1); + message8.appendEnum16(1); + message8.appendEnum16(10); + eventActionService.enableEventActionDefinitions(message8); + + CHECK(ServiceTests::thrownError(ErrorHandler::EventActionUnknownEventActionDefinitionIDError)); + CHECK(ServiceTests::countErrors() == 2); } TEST_CASE("Disable event-action definitions TC[19,5]", "[service][st19]") { - // Adding event action definitions to disable them + // Adding event action definitions to enable them Message message0(19, 1, Message::TC, 0); message0.appendEnum16(1); message0.appendEnum16(0); + message0.appendEnum16(1); String<64> data = "0"; message0.appendString(data); eventActionService.addEventActionDefinitions(message0); @@ -296,28 +273,65 @@ TEST_CASE("Disable event-action definitions TC[19,5]", "[service][st19]") { Message message1(19, 1, Message::TC, 0); message1.appendEnum16(1); message1.appendEnum16(1); + message1.appendEnum16(1); data = "00"; message1.appendString(data); eventActionService.addEventActionDefinitions(message1); - // Enabling a message - Message message2(19, 4, Message::TC, 0); - message2.appendUint16(1); - message2.appendEnum16(1); - message2.appendEnum16(0); - eventActionService.enableEventActionDefinitions(message2); + // Checking their enabled status + CHECK(eventActionService.eventActionDefinitionMap.lower_bound(0)->second.enabled == 0); + CHECK(eventActionService.eventActionDefinitionMap.lower_bound(1)->second.enabled == 0); - CHECK(eventActionService.eventActionDefinitionMap[0].enabled == 1); - CHECK(eventActionService.eventActionDefinitionMap[1].enabled == 0); + // Creating a message to enable the previous messages + Message message3(19, 4, Message::TC, 0); + message3.appendUint16(2); + message3.appendEnum16(1); + message3.appendEnum16(0); + message3.appendEnum16(1); + message3.appendEnum16(1); + message3.appendEnum16(1); + message3.appendEnum16(1); + eventActionService.enableEventActionDefinitions(message3); - // Checking for an error in case of an attempt to disable an unknown definition + // Checking if the messages are enabled + CHECK(eventActionService.eventActionDefinitionMap.lower_bound(0)->second.enabled == 1); + CHECK(eventActionService.eventActionDefinitionMap.lower_bound(1)->second.enabled == 1); + + // Creating a message to enable the previous messages + Message message4(19, 5, Message::TC, 0); + message4.appendUint16(2); + message4.appendEnum16(1); + message4.appendEnum16(0); + message4.appendEnum16(1); + message4.appendEnum16(1); + message4.appendEnum16(1); + message4.appendEnum16(1); + eventActionService.disableEventActionDefinitions(message4); + + // Checking if the messages are enabled + CHECK(eventActionService.eventActionDefinitionMap.lower_bound(0)->second.enabled == 0); + CHECK(eventActionService.eventActionDefinitionMap.lower_bound(1)->second.enabled == 0); + + // Checking for errors in the case of an attempt to enable an unknown definition Message message7(19, 5, Message::TC, 0); message7.appendUint16(1); message7.appendEnum16(1); - message7.appendEnum16(10); + message7.appendEnum16(6); eventActionService.disableEventActionDefinitions(message7); - CHECK(ServiceTests::thrownError(ErrorHandler::EventActionUnknownDefinitionError)); + + CHECK(ServiceTests::thrownError(ErrorHandler::EventActionUnknownEventDefinitionError)); CHECK(ServiceTests::countErrors() == 1); + + // Checking for errors in the case of an attempt to enable an unknown definition + Message message8(19, 5, Message::TC, 0); + message8.appendUint16(1); + message8.appendEnum16(1); + message8.appendEnum16(1); + message8.appendEnum16(10); + eventActionService.disableEventActionDefinitions(message8); + + CHECK(ServiceTests::thrownError(ErrorHandler::EventActionUnknownEventActionDefinitionIDError)); + CHECK(ServiceTests::countErrors() == 2); } TEST_CASE("Request event-action definition status TC[19,6]", "[service][st19]") { @@ -335,10 +349,10 @@ TEST_CASE("Request event-action definition status TC[19,6]", "[service][st19]") TEST_CASE("Event-action status report TM[19,7]", "[service][st19]") { // Adding event-action definitions to report them - Message message0(19, 1, Message::TC, 0); message0.appendEnum16(1); message0.appendEnum16(0); + message0.appendEnum16(1); String<64> data = "0"; message0.appendString(data); eventActionService.addEventActionDefinitions(message0); @@ -346,6 +360,7 @@ TEST_CASE("Event-action status report TM[19,7]", "[service][st19]") { Message message1(19, 1, Message::TC, 0); message1.appendEnum16(1); message1.appendEnum16(2); + message1.appendEnum16(1); data = "2"; message1.appendString(data); eventActionService.addEventActionDefinitions(message1); @@ -355,6 +370,7 @@ TEST_CASE("Event-action status report TM[19,7]", "[service][st19]") { message2.appendUint16(1); message2.appendEnum16(1); message2.appendEnum16(0); + message2.appendEnum16(1); eventActionService.enableEventActionDefinitions(message2); eventActionService.eventActionStatusReport(); @@ -365,9 +381,11 @@ TEST_CASE("Event-action status report TM[19,7]", "[service][st19]") { CHECK(report.readUint16() == 2); CHECK(report.readEnum16() == 1); CHECK(report.readEnum16() == 0); + CHECK(report.readEnum16() == 1); CHECK(report.readBoolean() == 1); CHECK(report.readEnum16() == 1); CHECK(report.readEnum16() == 2); + CHECK(report.readEnum16() == 1); CHECK(report.readBoolean() == 0); }