diff --git a/inc/ErrorHandler.hpp b/inc/ErrorHandler.hpp index dbc8c3ad6d91f431ec1c16e82a19f4543e7035d4..07c290934b7f5bc3b2e86c2d56324ccb2169c4c0 100644 --- a/inc/ErrorHandler.hpp +++ b/inc/ErrorHandler.hpp @@ -1,6 +1,8 @@ #ifndef PROJECT_ERRORHANDLER_HPP #define PROJECT_ERRORHANDLER_HPP +#include <type_traits> + // Forward declaration of the class, since its header file depends on the ErrorHandler class Message; @@ -223,19 +225,19 @@ public: // While this may seem like a "hacky" way to convert enums to ErrorSource, it should be // optimised by the compiler to constant time. - if (typeid(ErrorType) == typeid(AcceptanceErrorType)) { + if (std::is_same<ErrorType, AcceptanceErrorType>()) { return Acceptance; } - if (typeid(ErrorType) == typeid(ExecutionStartErrorType)) { + if (std::is_same<ErrorType, ExecutionStartErrorType>()) { return ExecutionStart; } - if (typeid(ErrorType) == typeid(ExecutionProgressErrorType)) { + if (std::is_same<ErrorType, ExecutionProgressErrorType>()) { return ExecutionProgress; } - if (typeid(ErrorType) == typeid(ExecutionCompletionErrorType)) { + if (std::is_same<ErrorType, ExecutionCompletionErrorType>()) { return ExecutionCompletion; } - if (typeid(ErrorType) == typeid(RoutingErrorType)) { + if (std::is_same<ErrorType, RoutingErrorType>()) { return Routing; } return Internal; diff --git a/test/Services/ServiceTests.hpp b/test/Services/ServiceTests.hpp index 0c9f5b922501c10d7f6c7b28ebed119c9246e2ba..09957305df164f3c7042ddd058aa19a4081b7054 100644 --- a/test/Services/ServiceTests.hpp +++ b/test/Services/ServiceTests.hpp @@ -12,14 +12,24 @@ * @todo See if members of this class can be made non-static */ class ServiceTests { +protected: /** * The list of Messages that have been sent as a result of all the processing. + * + * Whenever a Message is sent from anywhere in the code, it is stored in this array. The + * testing code can fetch these Messages using the ServiceTests::get() method. */ static std::vector<Message> queuedMessages; /** - * The list of Errors that the ErrorHandler caught - * @var A multimap with keys (ErrorSource, ErrorType) and values of 1 + * The list of Errors that the ErrorHandler caught. + * + * Whenever an Error is thrown anywhere in the code, it is collected in the thrownErrors + * array. Then, the user can tests whether or which types of errors were thrown, using + * the ServiceTests::hasNoErrors() and ServiceTests::thrownError() functions. + * + * A multimap with keys (ErrorHandler::ErrorSource, ErrorHandler::ErrorType) and values of `1`. + * * @todo If errors get more complex, this should hold the complete error information */ static std::multimap<std::pair<ErrorHandler::ErrorSource, uint16_t>, bool> thrownErrors; @@ -40,7 +50,7 @@ public: } /** - * Add a message to the queue of messages to be sent + * Add a message to the queue of messages having been sent */ static void queue(const Message &message) { queuedMessages.push_back(message); @@ -49,6 +59,9 @@ public: /** * Add one error to the list of occurred errors. * + * @note This function will be called automatically by the ErrorHandler, and should not be + * used in tests. + * * @param errorSource The source of the error. * @param errorCode The integer code of the error, coming directly from one of the ErrorCode * enumerations in ErrorHandler.