From 530b5f99919763c73426cd7d8b0a0ebd927e08f0 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Sat, 27 Jan 2024 17:43:22 +0100 Subject: [PATCH] Make XMI test run with cpp_event_framework::Signals --- test/XmiFsm.cxx | 3 --- test/XmiFsm.hxx | 56 +++++++++++++++++++++++++++++---------------- test/XmiFsmImpl.cxx | 24 +++++++++---------- 3 files changed, 48 insertions(+), 35 deletions(-) diff --git a/test/XmiFsm.cxx b/test/XmiFsm.cxx index 89edffa..f3d83cf 100644 --- a/test/XmiFsm.cxx +++ b/test/XmiFsm.cxx @@ -1,6 +1,3 @@ #include "XmiFsm.hxx" -#define XmiTest_GET_INSTANCE_EVENT_ID(e) e -#define XmiTest_GET_STATIC_EVENT_ID(e) EXmiEvent::e - #include "generated/XmiTestInstance.hxx" diff --git a/test/XmiFsm.hxx b/test/XmiFsm.hxx index 0127c00..43f5f57 100644 --- a/test/XmiFsm.hxx +++ b/test/XmiFsm.hxx @@ -2,46 +2,62 @@ #include +#include +#include #include -enum class EXmiEvent +class Transition_1 : public cpp_event_framework::SignalBase { - Transition_1, - Transition_2, - Transition_3, - Transition_4, - Transition_6, - Transition_7, - Transition_8, - Internal }; -inline std::ostream& operator<<(std::ostream& os, EXmiEvent event) +class Transition_2 : public cpp_event_framework::NextSignal { - switch (event) +}; +class Transition_3 : public cpp_event_framework::NextSignal +{ +}; +class Transition_4 : public cpp_event_framework::NextSignal +{ +}; +class Transition_6 : public cpp_event_framework::NextSignal +{ +}; +class Transition_7 : public cpp_event_framework::NextSignal +{ +}; +class Transition_8 : public cpp_event_framework::NextSignal +{ +}; +class Internal : public cpp_event_framework::NextSignal +{ +}; + +inline std::ostream& operator<<(std::ostream& os, const cpp_event_framework::Signal::SPtr& event) +{ + switch (event->Id()) { - case EXmiEvent::Transition_1: + case Transition_1::kId: os << "Transition_1"; break; - case EXmiEvent::Transition_2: + case Transition_2::kId: os << "Transition_2"; break; - case EXmiEvent::Transition_3: + case Transition_3::kId: os << "Transition_3"; break; - case EXmiEvent::Transition_4: + case Transition_4::kId: os << "Transition_4"; break; - case EXmiEvent::Transition_6: + case Transition_6::kId: os << "Transition_6"; break; - case EXmiEvent::Transition_7: + case Transition_7::kId: os << "Transition_7"; break; - case EXmiEvent::Transition_8: + case Transition_8::kId: os << "Transition_8"; break; - case EXmiEvent::Internal: + case Internal::kId: os << "Internal"; break; default: @@ -52,7 +68,7 @@ inline std::ostream& operator<<(std::ostream& os, EXmiEvent event) } class IXmiFsmImpl; -using XmiTestBase = cpp_event_framework::Statemachine; +using XmiTestBase = cpp_event_framework::Statemachine; #include "generated/IXmiTestImpl.hxx" #include "generated/XmiTestDeclaration.hxx" diff --git a/test/XmiFsmImpl.cxx b/test/XmiFsmImpl.cxx index 747548a..b24764e 100644 --- a/test/XmiFsmImpl.cxx +++ b/test/XmiFsmImpl.cxx @@ -36,14 +36,14 @@ void XmiFsmImpl::Test() CheckAllFalse(); // Send event that is not handled in state - fsm_.React(EXmiEvent::Transition_3); + fsm_.React(Transition_3::MakeShared()); assert(fsm_.CurrentState() == &XmiTest::kState_1State_2); assert(on_unhandled_event_called_); on_unhandled_event_called_ = false; CheckAllFalse(); // Internal transition, action must be called. - fsm_.React(EXmiEvent::Internal); + fsm_.React(Internal::MakeShared()); assert(fsm_.CurrentState() == &XmiTest::kState_1State_2); assert(state2_internal_action_called_); state2_internal_action_called_ = false; @@ -51,7 +51,7 @@ void XmiFsmImpl::Test() // Guard returns false, no state change, no entry/exit state2_transition3_guard_result_ = false; - fsm_.React(EXmiEvent::Transition_3); + fsm_.React(Transition_3::MakeShared()); assert(fsm_.CurrentState() == &XmiTest::kState_1State_2); assert(on_unhandled_event_called_); on_unhandled_event_called_ = false; @@ -59,7 +59,7 @@ void XmiFsmImpl::Test() // Guard returns true, state change, entry/exit called state2_transition3_guard_result_ = true; - fsm_.React(EXmiEvent::Transition_3); + fsm_.React(Transition_3::MakeShared()); assert(fsm_.CurrentState() == &XmiTest::kState_1StateWithSameName); assert(transition3_action1_called_); transition3_action1_called_ = false; @@ -68,7 +68,7 @@ void XmiFsmImpl::Test() CheckAllFalse(); // Enter history compartment - fsm_.React(EXmiEvent::Transition_7); + fsm_.React(Transition_7::MakeShared()); assert(fsm_.CurrentState() == &XmiTest::kState_1State_4State_5); assert(state3_on_exit_called_); state3_on_exit_called_ = false; @@ -77,12 +77,12 @@ void XmiFsmImpl::Test() CheckAllFalse(); // Transition in history compartment - fsm_.React(EXmiEvent::Transition_3); + fsm_.React(Transition_3::MakeShared()); assert(fsm_.CurrentState() == &XmiTest::kState_1State_4StateWithSameName); CheckAllFalse(); // Step out of history compartment - fsm_.React(EXmiEvent::Transition_8); + fsm_.React(Transition_8::MakeShared()); assert(fsm_.CurrentState() == &XmiTest::kState_1State_2); assert(state4_on_exit_called_); state4_on_exit_called_ = false; @@ -91,21 +91,21 @@ void XmiFsmImpl::Test() CheckAllFalse(); // Reenter history compartment, history must be preserved - fsm_.React(EXmiEvent::Transition_6); + fsm_.React(Transition_6::MakeShared()); assert(fsm_.CurrentState() == &XmiTest::kState_1State_4StateWithSameName); assert(state4_on_entry_called_); state4_on_entry_called_ = false; CheckAllFalse(); // Choice: No guards return true - fsm_.React(EXmiEvent::Transition_7); + fsm_.React(Transition_7::MakeShared()); assert(on_unhandled_event_called_); on_unhandled_event_called_ = false; CheckAllFalse(); // Choice: One guard return true choice_guard1_result_ = true; - fsm_.React(EXmiEvent::Transition_7); + fsm_.React(Transition_7::MakeShared()); assert(fsm_.CurrentState() == &XmiTest::kState_1StateWithSameName); assert(choice_action1_called_); choice_action1_called_ = false; @@ -118,7 +118,7 @@ void XmiFsmImpl::Test() CheckAllFalse(); // Return to State_1::State_4::StateWithSameName - fsm_.React(EXmiEvent::Transition_7); + fsm_.React(Transition_7::MakeShared()); assert(fsm_.CurrentState() == &XmiTest::kState_1State_4StateWithSameName); assert(state3_on_exit_called_); state3_on_exit_called_ = false; @@ -128,7 +128,7 @@ void XmiFsmImpl::Test() // Choice: Two guards return true choice_guard2_result_ = true; - fsm_.React(EXmiEvent::Transition_7); + fsm_.React(Transition_7::MakeShared()); assert(fsm_.CurrentState() == &XmiTest::kState_1State_4State_5); assert(choice_action1_called_); choice_action1_called_ = false;