From eb65591d2aa8c4096b283132f7db41f808404c48 Mon Sep 17 00:00:00 2001
From: athatheocsd <athatheo@csd.auth.gr>
Date: Mon, 31 Dec 2018 23:03:57 +0200
Subject: [PATCH] TC[19,1] completed

---
 src/Services/EventActionService.cpp  | 51 ++++++++--------------------
 test/Services/EventActionService.cpp | 32 +++++++++--------
 2 files changed, 33 insertions(+), 50 deletions(-)

diff --git a/src/Services/EventActionService.cpp b/src/Services/EventActionService.cpp
index e724b39f..3f819c74 100644
--- a/src/Services/EventActionService.cpp
+++ b/src/Services/EventActionService.cpp
@@ -12,47 +12,26 @@ void EventActionService::addEventActionDefinitions(Message message) {
 
 	if (message.messageType == 1 && message.packetType == Message::TC && message.serviceType ==
 																						19) {
-		char x[64];
-		uint16_t N = message.readUint16();
 		uint16_t index = 0;
 		uint8_t flag = 0; // used as boolean 0 is false, 1 is true
-		for (uint16_t i = 0; i < N; i++) {
-			while (eventActionDefinitionArray[index].empty == 0) {
-				if (index == 255) { // 255 should be changed depending on size of the array
-					flag = 1;
-					break;
-				}
-				std::cout << "index: " << index << " empty: " << (unsigned)
-				eventActionDefinitionArray[index].empty << " \n";
-				index++;
-			}
-
-
-			if (flag == 0) {
-				char data[128];
-				std::cout << "Inside the flag == 0 " << "index: " << index << " empty: " <<
-				(unsigned)
-					eventActionDefinitionArray[index].empty << " \n";
-				eventActionDefinitionArray[index].empty = 0;
-				eventActionDefinitionArray[index].applicationId = message.readEnum16();
-				eventActionDefinitionArray[index].eventDefinitionID = message.readEnum16();
-				if (index == 0){
-					message.readString(data, 3); // ECSS_MAX_STRING_SIZE??
-				} else {
-					message.readString(data, 3); // ECSS_MAX_STRING_SIZE??
-				}
-				eventActionDefinitionArray[index].request = String<64>(data);
-				std::cout << "char data: " << data << " String<64>(data): " << String<64>(data)
-				    .data() << " \n";
-				std::cout << "String: " << eventActionDefinitionArray[index].request.data() << " \n";
-				index++;
-
+		while (eventActionDefinitionArray[index].empty == 0) {
+			if (index == 255) { // 255 should be changed depending on size of the array
+				flag = 1;
+				break;
 			}
+			index++;
+		}
+		if (flag == 0) {
+			char data[128];
+			eventActionDefinitionArray[index].empty = 0;
+			eventActionDefinitionArray[index].applicationId = message.readEnum16();
+			eventActionDefinitionArray[index].eventDefinitionID = message.readEnum16();
+			// Tests pass with message.dataSize - 3, message.dataSize - 4, but not
+			// message.dataSize - 5
+			message.readString(data, message.dataSize);
+			eventActionDefinitionArray[index].request = String<64>(data);
 		}
-
 	}
-	//std::cout << eventActionDefinitionArray[0].empty;
-
 }
 
 void EventActionService::deleteEventActionDefinitions(Message message) {
diff --git a/test/Services/EventActionService.cpp b/test/Services/EventActionService.cpp
index 171fb5a2..cb23ba3e 100644
--- a/test/Services/EventActionService.cpp
+++ b/test/Services/EventActionService.cpp
@@ -9,29 +9,33 @@ TEST_CASE("Add event-action definitions TC[19,1]", "[service][st09]") {
 	EventActionService eventActionService;
 	char checkstring[256];
 	Message message(19, 1, Message::TC, 0);
-	message.appendUint16(2);
 	message.appendEnum16(0);
 	message.appendEnum16(2);
 	String<64> data = "123";
 	message.appendString(data);
 
-	message.appendEnum16(1);
-	message.appendEnum16(3);
-	data = "456";
-	message.appendString(data);
-	// Should I check byte by byte or check the contents of the EventActionDefinitionArray
 	eventActionService.addEventActionDefinitions(message);
-	CHECK(message.readUint16() == 2);
 	CHECK(eventActionService.eventActionDefinitionArray[0].empty == 0);
-	message.readEnum16();
+	CHECK(eventActionService.eventActionDefinitionArray[0].applicationId == 0);
+	CHECK(eventActionService.eventActionDefinitionArray[0].eventDefinitionID == 2);
+	CHECK(message.readEnum16() == 0);
 	CHECK(message.readEnum16() == 2);
 	message.readString(checkstring, 3);
-	CHECK(eventActionService.eventActionDefinitionArray[0].request.compare(checkstring) == 0);
-	CHECK(message.readEnum16() == 1);
-	CHECK(message.readEnum16() == 3);
-	message.readString(checkstring, 3);
-	std::cout << checkstring;
-	CHECK(eventActionService.eventActionDefinitionArray[1].request.compare(checkstring) == 0);
+	CHECK(eventActionService.eventActionDefinitionArray[0].request.compare(data) == 0);
+
+	Message message2(19, 1, Message::TC, 0);
+	message2.appendEnum16(1);
+	message2.appendEnum16(3);
+	data = "456";
+	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(message2.readEnum16() == 1);
+	CHECK(message2.readEnum16() == 3);
+	CHECK(eventActionService.eventActionDefinitionArray[1].request.compare(data) == 0);
 }
 
 TEST_CASE("Delete event-action definitions TC[19,2]", "[service][st09]") {
-- 
GitLab