From 0ea4a01c9603e9af1e20fae053613ca23c0c647a Mon Sep 17 00:00:00 2001
From: thodkatz <thodkatz@gmail.com>
Date: Wed, 21 Nov 2018 04:13:18 +0200
Subject: [PATCH] Add tests for ST[01]

---
 CMakeLists.txt                               |   6 +-
 test/Services/RequestVerificationService.cpp | 113 +++++++++++++++++++
 2 files changed, 117 insertions(+), 2 deletions(-)
 create mode 100644 test/Services/RequestVerificationService.cpp

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1eee6054..37ee7a55 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -19,7 +19,9 @@ add_executable(ecss_services src/main.cpp src/Message.cpp src/Service.cpp
 
 IF (EXISTS "${PROJECT_SOURCE_DIR}/lib/Catch2/CMakeLists.txt")
     add_subdirectory(lib/Catch2)
-    add_executable(tests src/Message.cpp src/Services/TestService.cpp test/tests.cpp
-            test/Message.cpp test/TestPlatform.cpp test/Services/TestService.cpp)
+    add_executable(tests src/Message.cpp src/Services/TestService.cpp
+            src/Services/RequestVerificationService.cpp test/tests.cpp
+            test/Message.cpp test/TestPlatform.cpp test/Services/TestService.cpp
+            test/Services/RequestVerificationService.cpp)
     target_link_libraries(tests Catch2::Catch2)
 ENDIF ()
diff --git a/test/Services/RequestVerificationService.cpp b/test/Services/RequestVerificationService.cpp
new file mode 100644
index 00000000..4301ce79
--- /dev/null
+++ b/test/Services/RequestVerificationService.cpp
@@ -0,0 +1,113 @@
+#include <catch2/catch.hpp>
+#include <Services/RequestVerificationService.hpp>
+#include <Message.hpp>
+#include "ServiceTests.hpp"
+
+TEST_CASE("TM[1,1]", "[service][st01]") {
+	RequestVerificationService reqVerifService;
+	reqVerifService.successAcceptanceVerification(Message::TC, true, 2, 2, 10);
+	REQUIRE(ServiceTests::hasOneMessage());
+
+	Message response = ServiceTests::get(0);
+	// Checks for the class-members of the object response
+	CHECK(response.serviceType == 1);
+	CHECK(response.messageType == 1);
+	CHECK(response.packetType == 0); // packet type(TM = 0, TC = 1)
+	CHECK(response.applicationId == 0);
+	REQUIRE(response.dataSize == 4); // dataSize is the number of bytes of data array
+	// Check for the value that is stored in data array(member-class of object response)
+	CHECK(response.readEnumerated(3) == 2); // packet version number
+	CHECK(response.readEnumerated(1) == 1); // packet type
+	CHECK(response.readBits(1) == true); // secondary header flag
+	CHECK(response.readEnumerated(11) == 2); // application process ID
+	CHECK(response.readEnumerated(2) == 2); // sequence flags
+	CHECK(response.readBits(14) == 10); // packet sequence count
+}
+
+TEST_CASE("TM[1,2]", "[service][st01]") {
+	RequestVerificationService reqVerifService;
+	reqVerifService.failAcceptanceVerification(Message::TC, true, 2, 2, 10, 5);
+	REQUIRE(ServiceTests::hasOneMessage());
+
+	Message response = ServiceTests::get(0);
+	// Checks for the class-members of the object response
+	CHECK(response.serviceType == 1);
+	CHECK(response.messageType == 2);
+	CHECK(response.packetType == 0); // packet type(TM = 0, TC = 1)
+	CHECK(response.applicationId == 0);
+	REQUIRE(response.dataSize == 6); // dataSize is the number of bytes of data array
+	// Check for the value that is stored in data array(member-class of object response)
+	CHECK(response.readEnumerated(3) == 2); // packet version number
+	CHECK(response.readEnumerated(1) == 1); // packet type
+	CHECK(response.readBits(1) == true); // secondary header flag
+	CHECK(response.readEnumerated(11) == 2); // application process ID
+	CHECK(response.readEnumerated(2) == 2); // sequence flags
+	CHECK(response.readBits(14) == 10); // packet sequence count
+	CHECK(response.readEnum16() == 5); // error code
+}
+
+TEST_CASE("TM[1,7]", "[service][st01]") {
+	RequestVerificationService reqVerifService;
+	reqVerifService.successExecutionVerification(Message::TC, true, 2, 2, 10);
+	REQUIRE(ServiceTests::hasOneMessage());
+
+	Message response = ServiceTests::get(0);
+	// Checks for the class-members of the object response
+	CHECK(response.serviceType == 1);
+	CHECK(response.messageType == 7);
+	CHECK(response.packetType == 0); // packet type(TM = 0, TC = 1)
+	CHECK(response.applicationId == 0);
+	REQUIRE(response.dataSize == 4); // dataSize is the number of bytes of data array
+	// Check for the value that is stored in data array(member-class of object response)
+	CHECK(response.readEnumerated(3) == 2); // packet version number
+	CHECK(response.readEnumerated(1) == 1); // packet type
+	CHECK(response.readBits(1) == true); // secondary header flag
+	CHECK(response.readEnumerated(11) == 2); // application process ID
+	CHECK(response.readEnumerated(2) == 2); // sequence flags
+	CHECK(response.readBits(14) == 10); // packet sequence count
+}
+
+TEST_CASE("TM[1,8]", "[service][st01]") {
+	RequestVerificationService reqVerifService;
+	reqVerifService.failExecutionVerification(Message::TC, true, 2, 2, 10, 6);
+	REQUIRE(ServiceTests::hasOneMessage());
+
+	Message response = ServiceTests::get(0);
+	// Checks for the class-members of the object response
+	CHECK(response.serviceType == 1);
+	CHECK(response.messageType == 8);
+	CHECK(response.packetType == 0); // packet type(TM = 0, TC = 1)
+	CHECK(response.applicationId == 0);
+	REQUIRE(response.dataSize == 6); // dataSize is the number of bytes of data array
+	// Check for the value that is stored in data array(member-class of object response)
+	CHECK(response.readEnumerated(3) == 2); // packet version number
+	CHECK(response.readEnumerated(1) == 1); // packet type
+	CHECK(response.readBits(1) == true); // secondary header flag
+	CHECK(response.readEnumerated(11) == 2); // application process ID
+	CHECK(response.readEnumerated(2) == 2); // sequence flags
+	CHECK(response.readBits(14) == 10); // packet sequence count
+	CHECK(response.readEnum16() == 6); // error code
+}
+
+TEST_CASE("TM[1,10]", "[service][st01]") {
+	RequestVerificationService reqVerifService;
+	reqVerifService.failRoutingVerification(Message::TC, true, 2, 2, 10, 7);
+	REQUIRE(ServiceTests::hasOneMessage());
+
+	Message response = ServiceTests::get(0);
+	// Checks for the class-members of the object response
+	CHECK(response.serviceType == 1);
+	CHECK(response.messageType == 10);
+	CHECK(response.packetType == 0); // packet type(TM = 0, TC = 1)
+	CHECK(response.applicationId == 0);
+	REQUIRE(response.dataSize == 6); // dataSize is the number of bytes of data array
+	// Check for the value that is stored in data array(member-class of object response)
+	CHECK(response.readEnumerated(3) == 2); // packet version number
+	CHECK(response.readEnumerated(1) == 1); // packet type
+	CHECK(response.readBits(1) == true); // secondary header flag
+	CHECK(response.readEnumerated(11) == 2); // application process ID
+	CHECK(response.readEnumerated(2) == 2); // sequence flags
+	CHECK(response.readBits(14) == 10); // packet sequence count
+	CHECK(response.readEnum16() == 7); // error code
+}
+
-- 
GitLab