From 57a6c926aafda4487b96cfb35198cd87bec06516 Mon Sep 17 00:00:00 2001 From: Dennis Klein Date: Tue, 28 Feb 2023 15:29:52 +0100 Subject: [PATCH] test: Deduplicate code and fix [-Wunused-result] --- test/helper/devices/TestErrorState.h | 103 ++++++--------------------- 1 file changed, 21 insertions(+), 82 deletions(-) diff --git a/test/helper/devices/TestErrorState.h b/test/helper/devices/TestErrorState.h index 1e0d428f..055ff41b 100644 --- a/test/helper/devices/TestErrorState.h +++ b/test/helper/devices/TestErrorState.h @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (C) 2018-2022 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * Copyright (C) 2018-2023 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * * * * This software is distributed under the terms of the * * GNU Lesser General Public Licence (LGPL) version 3, * @@ -10,96 +10,35 @@ #define FAIR_MQ_TEST_ERROR_STATE_H #include +#include + #include -#include +#include namespace fair::mq::test { class ErrorState : public Device { + auto ErrorIfRequestedById(std::string_view state) + { + if (std::string::npos != GetId().find(tools::ToString("_", state, "_"))) { + LOG(info) << "going to change to Error state from " << state << "()"; + ChangeStateOrThrow(fair::mq::Transition::ErrorFound); + } + } + public: - void Init() override - { - std::string state("Init"); - if (std::string::npos != GetId().find("_" + state + "_")) { - LOG(info) << "going to change to Error state from " << state << "()"; - ChangeState(fair::mq::Transition::ErrorFound); - } - } - - void Bind() override - { - std::string state("Bind"); - if (std::string::npos != GetId().find("_" + state + "_")) { - LOG(info) << "going to change to Error state from " << state << "()"; - ChangeState(fair::mq::Transition::ErrorFound); - } - } - - void Connect() override - { - std::string state("Connect"); - if (std::string::npos != GetId().find("_" + state + "_")) { - LOG(info) << "going to change to Error state from " << state << "()"; - ChangeState(fair::mq::Transition::ErrorFound); - } - } - - void InitTask() override - { - std::string state("InitTask"); - if (std::string::npos != GetId().find("_" + state + "_")) { - LOG(info) << "going to change to Error state from " << state << "()"; - ChangeState(fair::mq::Transition::ErrorFound); - } - } - - void PreRun() override - { - std::string state("PreRun"); - if (std::string::npos != GetId().find("_" + state + "_")) { - LOG(info) << "going to change to Error state from " << state << "()"; - ChangeState(fair::mq::Transition::ErrorFound); - } - } - - void Run() override - { - std::string state("Run"); - if (std::string::npos != GetId().find("_" + state + "_")) { - LOG(info) << "going to change to Error state from " << state << "()"; - ChangeState(fair::mq::Transition::ErrorFound); - } - } - - void PostRun() override - { - std::string state("PostRun"); - if (std::string::npos != GetId().find("_" + state + "_")) { - LOG(info) << "going to change to Error state from " << state << "()"; - ChangeState(fair::mq::Transition::ErrorFound); - } - } - - void ResetTask() override - { - std::string state("ResetTask"); - if (std::string::npos != GetId().find("_" + state + "_")) { - LOG(info) << "going to change to Error state from " << state << "()"; - ChangeState(fair::mq::Transition::ErrorFound); - } - } - - void Reset() override - { - std::string state("Reset"); - if (std::string::npos != GetId().find("_" + state + "_")) { - LOG(info) << "going to change to Error state from " << state << "()"; - ChangeState(fair::mq::Transition::ErrorFound); - } - } + void Init() override { ErrorIfRequestedById("Init"); } + void Bind() override { ErrorIfRequestedById("Bind"); } + void Connect() override { ErrorIfRequestedById("Connect"); } + void InitTask() override { ErrorIfRequestedById("InitTask"); } + void PreRun() override { ErrorIfRequestedById("PreRun"); } + void Run() override { ErrorIfRequestedById("Run"); } + void PostRun() override { ErrorIfRequestedById("PostRun"); } + void ResetTask() override { ErrorIfRequestedById("ResetTask"); } + void Reset() override { ErrorIfRequestedById("Reset"); } }; } // namespace fair::mq::test