From 5499a637c6d74687e921eee95d8dc298d45f0a3a Mon Sep 17 00:00:00 2001
From: Grigoris Pavlakis <grigpavl@ece.auth.gr>
Date: Mon, 26 Nov 2018 23:43:50 +0200
Subject: [PATCH] Add a basic test for parameter setting

---
 test/Services/ParameterService.cpp | 35 ++++++++++++++++++++++++++----
 1 file changed, 31 insertions(+), 4 deletions(-)

diff --git a/test/Services/ParameterService.cpp b/test/Services/ParameterService.cpp
index f6fa7fd9..05e0c8ce 100644
--- a/test/Services/ParameterService.cpp
+++ b/test/Services/ParameterService.cpp
@@ -6,11 +6,9 @@
 #define CATCH_CONFIG_MAIN
 
 TEST_CASE("Parameter Report Subservice") {
-
 	ParameterService pserv;
 
 	SECTION("Faulty Instruction Ignorance Test") {
-
 		//TODO: Find a better criterion than checking the first 16 bits
 
 		Message request(20, 1, Message::TC, 1);
@@ -33,8 +31,7 @@ TEST_CASE("Parameter Report Subservice") {
 	}
 
 	SECTION("Wrong Message Type Handling Test") {
-
-		Message falseRequest(15, 3, Message::TM, 1);   //a totally wrong message
+		Message falseRequest(15, 3, Message::TM, 1);   // a totally wrong message
 
 		pserv.reportParameterIds(falseRequest);
 		Message response = ServiceTests::get(0);
@@ -46,6 +43,36 @@ TEST_CASE("Parameter Report Subservice") {
 }
 
 TEST_CASE("Parameter Setting Subservice") {
+	ParameterService pserv;
+
+	SECTION("Faulty Instruction Handling Test") {
+		Message setRequest(20, 3, Message::TC, 1);
+		Message reportRequest(20, 1, Message::TC, 1);
+
+		setRequest.appendUint16(2);           // correct number of IDs
+		setRequest.appendUint16(3);           // correct ID
+		setRequest.appendUint32(3735928559);  // 0xDEADBEEF in hex (new setting)
+		setRequest.appendUint16(16742);       // faulty ID in this context
+		setRequest.appendUint32(3131746989);  // 0xBAAAAAAD (this shouldn't be found in the report)
 
+		reportRequest.appendUint16(2);
+		reportRequest.appendUint16(16742);
+		reportRequest.appendUint16(3);
 
+		pserv.reportParameterIds(reportRequest);
+		Message before = ServiceTests::get(0);
+
+		pserv.setParameterIds(setRequest);
+
+		pserv.reportParameterIds(reportRequest);
+		Message after = ServiceTests::get(1);
+
+		before.readUint16();
+		after.readUint16();                    // skip the number of IDs
+
+		while (after.readPosition <= after.dataSize) {
+			CHECK(before.readUint16() == after.readUint16());   //check if all IDs are present
+			CHECK(after.readUint32() != 0xBAAAAAAD);      //check if any settings are BAAAAAAD :P
+		}
+	}
 }
-- 
GitLab