diff --git a/inc/Services/EventReportService.hpp b/inc/Services/EventReportService.hpp index a5973b027918bb3c212a4f1feb80df9127a27d58..160123a2522f7900a044886309b448304888e167 100644 --- a/inc/Services/EventReportService.hpp +++ b/inc/Services/EventReportService.hpp @@ -60,7 +60,7 @@ public: /** * When an execution of a notification/event fails to start */ - FailedStartOfExecution = 7 + FailedStartOfExecution = 7 }; /** @@ -138,7 +138,11 @@ public: */ void listOfDisabledEventsReport(); - std::bitset<numberOfEvents> getStateOfEvents(){ + /** + * Getter for stateOfEvents bitset + * @return stateOfEvents, just in case the whole bitset is needed + */ + std::bitset<numberOfEvents> getStateOfEvents() { return stateOfEvents; } diff --git a/src/Services/EventReportService.cpp b/src/Services/EventReportService.cpp index d852452f540feda053cecd1b70af414b849551d5..86f3c8fbd369b18c84157b18dc25e7b0114abd3b 100644 --- a/src/Services/EventReportService.cpp +++ b/src/Services/EventReportService.cpp @@ -77,13 +77,13 @@ void EventReportService::requestListOfDisabledEvents() { } void EventReportService::listOfDisabledEventsReport() { - // TC[5,8] + // TM[5,8] Message report = createTM(8); // Any chance we'll have more than uint8_t (>255 events) ? This will produce an error! - uint8_t numberOfDisabledEvents = stateOfEvents.size() - stateOfEvents.any(); + uint8_t numberOfDisabledEvents = stateOfEvents.size() - stateOfEvents.count(); report.appendByte(numberOfDisabledEvents); - for (uint8_t i = 0; i < numberOfDisabledEvents; i++) { + for (uint8_t i = 0; i < stateOfEvents.size(); i++) { if (stateOfEvents[i] == 0) { report.appendEnum8(i); } diff --git a/src/main.cpp b/src/main.cpp index 4961b299ccece9c96c4b526139779100187daeaa..3dc835dbe97a3d5a561b63729dba868ff48bec4e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -133,18 +133,14 @@ int main() { message = Message(1, 10, Message::TC, 2); messageParser.execute(message); - //ST[05] (5,5 to 5,8) - EventReportService::Event eventIDs[] = - {EventReportService::HighSeverityUnknownEvent, - EventReportService::HighSeverityUnknownEvent}; - std::cout << eventReportService.getStateOfEvents()[0]; - - eventReportService.enableReportGeneration(2, eventIDs); - std::cout << eventReportService.getStateOfEvents()[0]; - std::cout << eventReportService.getStateOfEvents()[1]; - std::cout << eventReportService.getStateOfEvents()[3]; - std::cout << eventReportService.getStateOfEvents()[4]; - std::cout << eventReportService.getStateOfEvents()[6]; + //ST[05] (5,5 to 5,8) test [works] + EventReportService::Event eventIDs[] = {EventReportService::HighSeverityUnknownEvent, + EventReportService::MediumSeverityUnknownEvent}; + EventReportService::Event eventIDs2[] = {EventReportService::HighSeverityUnknownEvent}; + eventReportService.disableReportGeneration(2, eventIDs); + eventReportService.listOfDisabledEventsReport(); + eventReportService.enableReportGeneration(1,eventIDs2); + eventReportService.requestListOfDisabledEvents(); return 0; } diff --git a/test/Services/EventReportService.cpp b/test/Services/EventReportService.cpp index 86f5e9e930810ccc982473f7769dfad9b574243d..3a351da9a3af49a7f9cb270e57f6d30b430c6c91 100644 --- a/test/Services/EventReportService.cpp +++ b/test/Services/EventReportService.cpp @@ -87,22 +87,52 @@ TEST_CASE("High Severity Anomaly Report TM[5,4]", "[service][st05]") { CHECK(strcmp(checkString, reinterpret_cast<const char *>(eventReportData)) == 0); } -TEST_CASE("Enable Report Generation TC[5,5]", "[service][st05]"){ - -} - -TEST_CASE("Disable Report Generation TC[5,6]", "[service][st05]"){ - +TEST_CASE("Enable Report Generation TC[5,5]", "[service][st05]") { + EventReportService eventReportService; + eventReportService.getStateOfEvents().reset(); + EventReportService::Event eventID[] = {EventReportService::AssertionFail, + EventReportService::LowSeverityUnknownEvent}; + eventReportService.enableReportGeneration(2, eventID); + CHECK(eventReportService.getStateOfEvents()[2] == 1); + CHECK(eventReportService.getStateOfEvents()[4] == 1); } -TEST_CASE("Request list of disabled events TC[5,7]", "[service][st05]"){ - +TEST_CASE("Disable Report Generation TC[5,6]", "[service][st05]") { + EventReportService eventReportService; + EventReportService::Event eventID[] = {EventReportService::InformativeUnknownEvent, + EventReportService::MediumSeverityUnknownEvent}; + eventReportService.disableReportGeneration(2, eventID); + CHECK(eventReportService.getStateOfEvents()[0] == 0); + CHECK(eventReportService.getStateOfEvents()[5] == 0); } -TEST_CASE("List of Disabled Events Report TM[5,8]", "[service][st05]"){ +TEST_CASE("Request list of disabled events TC[5,7]", "[service][st05]") { + EventReportService eventReportService; + eventReportService.requestListOfDisabledEvents(); + REQUIRE(ServiceTests::hasOneMessage()); + Message report = ServiceTests::get(0); + // Check if there is message of type 8 created + CHECK(report.messageType == 8); } -TEST_CASE("Getter for stateOfEvents variable"){ +TEST_CASE("List of Disabled Events Report TM[5,8]", "[service][st05]") { + EventReportService eventReportService; + EventReportService::Event eventID[] = {EventReportService::MCUStart, + EventReportService::HighSeverityUnknownEvent}; + // Disable 3rd and 6th + eventReportService.disableReportGeneration(2, eventID); + eventReportService.listOfDisabledEventsReport(); + REQUIRE(ServiceTests::hasOneMessage()); + Message report = ServiceTests::get(0); + // Check for the data-members of the report Message created + CHECK(report.serviceType == 5); + CHECK(report.messageType == 8); + CHECK(report.packetType == Message::TM); // packet type(TM = 0, TC = 1) + REQUIRE(report.dataSize == 3); + // Check for the information stored in report + CHECK(report.readByte() == 2); + CHECK(report.readEnum8() == 3); + CHECK(report.readEnum8() == 6); }