Skip to content
Snippets Groups Projects
Commit 75ee24a9 authored by kongr45gpen's avatar kongr45gpen
Browse files

Add tests for ST[17]

parent 30c64765
No related branches found
No related tags found
No related merge requests found
...@@ -18,6 +18,6 @@ add_executable(ecss_services src/main.cpp src/Message.cpp src/Service.cpp src/Se ...@@ -18,6 +18,6 @@ add_executable(ecss_services src/main.cpp src/Message.cpp src/Service.cpp src/Se
IF(EXISTS "${PROJECT_SOURCE_DIR}/lib/Catch2/CMakeLists.txt") IF(EXISTS "${PROJECT_SOURCE_DIR}/lib/Catch2/CMakeLists.txt")
add_subdirectory(lib/Catch2) add_subdirectory(lib/Catch2)
add_executable(test src/Message.cpp src/Service.cpp src/Services/TestService.cpp tests/tests.cpp tests/Message.cpp) add_executable(test src/Message.cpp src/Services/TestService.cpp tests/tests.cpp tests/Message.cpp tests/TestPlatform.cpp tests/Services/TestService.cpp)
target_link_libraries(test Catch2::Catch2) target_link_libraries(test Catch2::Catch2)
ENDIF() ENDIF()
#ifndef ECSS_SERVICES_TESTS_SERVICES_SERVICETESTS_HPP
#define ECSS_SERVICES_TESTS_SERVICES_SERVICETESTS_HPP
#include <vector>
#include <Message.hpp>
/**
* Supporting class for tests against ECSS services
*
* @todo See if members of this class can be made non-static
*/
class ServiceTests {
static std::vector<Message> queuedMessages;
public:
/**
* Get a message from the list of queued messages to send
* @param number The number of the message, starting from 0 in chronological order
*/
static Message& get(unsigned long number) {
return queuedMessages.at(number);
}
/**
* Add a message to the queue of messages to be sent
*/
static void queue(const Message &message) {
queuedMessages.push_back(message);
}
/**
* Counts the number of messages in the queue
*/
static unsigned long count() {
return queuedMessages.size();
}
/**
* Checks that there is *exactly* one message in the list of queued messages
*/
static bool hasOneMessage() {
return count() == 1;
}
/**
* Remove all the queued messages from the list, starting over from 0 items again
*/
static void reset() {
queuedMessages.clear();
}
};
#endif //ECSS_SERVICES_TESTS_SERVICES_SERVICETESTS_HPP
#include <catch2/catch.hpp>
#include <Services/TestService.hpp>
#include <Message.hpp>
#include "ServiceTests.hpp"
TEST_CASE("TM[17,1]", "[service][st17]") {
TestService testService;
Message receivedPacket = Message(17, 1, Message::TC, 1);
testService.areYouAlive(receivedPacket);
REQUIRE(ServiceTests::hasOneMessage());
Message response = ServiceTests::get(0);
CHECK(response.serviceType == 17);
CHECK(response.messageType == 2);
REQUIRE(response.dataSize == 0);
}
TEST_CASE("TM[17,3]", "[service][st17]") {
TestService testService;
Message receivedPacket = Message(17, 3, Message::TC, 1);
receivedPacket.appendEnum16(40);
testService.onBoardConnection(receivedPacket);
REQUIRE(ServiceTests::hasOneMessage());
Message response = ServiceTests::get(0);
CHECK(response.serviceType == 17);
CHECK(response.messageType == 4);
REQUIRE(response.dataSize == 2);
CHECK(response.readEnum16() == 40);
}
#define CATCH_CONFIG_EXTERNAL_INTERFACES
#include <catch2/catch.hpp>
#include <Message.hpp>
#include <Service.hpp>
#include "Services/ServiceTests.hpp"
std::vector<Message> ServiceTests::queuedMessages = std::vector<Message>();
void Service::storeMessage(const Message &message) {
ServiceTests::queue(message);
}
struct ServiceTestsListener : Catch::TestEventListenerBase {
using TestEventListenerBase::TestEventListenerBase; // inherit constructor
void testCaseStarting( Catch::TestCaseInfo const& testInfo ) override {
// Perform some setup before a test case is run
}
void testCaseEnded( Catch::TestCaseStats const& testCaseStats ) override {
// Tear-down after a test case is run
ServiceTests::reset();
}
};
CATCH_REGISTER_LISTENER( ServiceTestsListener )
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment