From 6b184e100bbd675a9a8bb1883490c787785c95c4 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Fri, 26 Jan 2024 17:45:37 +0100 Subject: [PATCH] Extend tests: Check choice states --- generator/pom.xml | 2 +- test/XmiFsmImpl.cxx | 67 +++++++++++++++++ test/XmiFsmImpl.hxx | 10 +++ test/generated/IXmiTestImpl.hxx | 7 +- test/generated/XmiTestDeclaration.hxx | 2 +- test/generated/XmiTestInstance.hxx | 15 +++- test/xmi/XmiTest.notation | 101 +++++++++++++++++++++----- test/xmi/XmiTest.uml | 14 ++++ 8 files changed, 197 insertions(+), 21 deletions(-) diff --git a/generator/pom.xml b/generator/pom.xml index ddc4b6b..b86a408 100644 --- a/generator/pom.xml +++ b/generator/pom.xml @@ -2,7 +2,7 @@ 4.0.0 net.ziegelmeier net.ziegelmeier.statemachinegenerator - 1.0.0 + 1.4.0 Dirk Ziegelmeiers Statemachine Generator src diff --git a/test/XmiFsmImpl.cxx b/test/XmiFsmImpl.cxx index e5cc0da..747548a 100644 --- a/test/XmiFsmImpl.cxx +++ b/test/XmiFsmImpl.cxx @@ -96,12 +96,54 @@ void XmiFsmImpl::Test() assert(state4_on_entry_called_); state4_on_entry_called_ = false; CheckAllFalse(); + + // Choice: No guards return true + fsm_.React(EXmiEvent::Transition_7); + 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); + assert(fsm_.CurrentState() == &XmiTest::kState_1StateWithSameName); + assert(choice_action1_called_); + choice_action1_called_ = false; + assert(choice_action3_called_); + choice_action3_called_ = false; + assert(state3_on_entry_called_); + state3_on_entry_called_ = false; + assert(state4_on_exit_called_); + state4_on_exit_called_ = false; + CheckAllFalse(); + + // Return to State_1::State_4::StateWithSameName + fsm_.React(EXmiEvent::Transition_7); + assert(fsm_.CurrentState() == &XmiTest::kState_1State_4StateWithSameName); + assert(state3_on_exit_called_); + state3_on_exit_called_ = false; + assert(state4_on_entry_called_); + state4_on_entry_called_ = false; + CheckAllFalse(); + + // Choice: Two guards return true + choice_guard2_result_ = true; + fsm_.React(EXmiEvent::Transition_7); + assert(fsm_.CurrentState() == &XmiTest::kState_1State_4State_5); + assert(choice_action1_called_); + choice_action1_called_ = false; + assert(choice_action2_called_); + choice_action2_called_ = false; + CheckAllFalse(); } void XmiFsmImpl::CheckAllFalse() const { assert(on_unhandled_event_called_ == false); + assert(choice_action1_called_ == false); + assert(choice_action2_called_ == false); + assert(choice_action3_called_ == false); assert(state2_internal_action_called_ == false); assert(transition3_action1_called_ == false); @@ -119,6 +161,21 @@ void XmiFsmImpl::UnhandledEvent() on_unhandled_event_called_ = true; } +void XmiFsmImpl::ChoiceAction1(XmiTestBase::Event /*event*/) +{ + std::cout << std::source_location::current().function_name() << "\n"; + choice_action1_called_ = true; +} +void XmiFsmImpl::ChoiceAction2(XmiTestBase::Event /*event*/) +{ + std::cout << std::source_location::current().function_name() << "\n"; + choice_action2_called_ = true; +} +void XmiFsmImpl::ChoiceAction3(XmiTestBase::Event /*event*/) +{ + std::cout << std::source_location::current().function_name() << "\n"; + choice_action3_called_ = true; +} void XmiFsmImpl::State2InternalAction(XmiTestBase::Event /*event*/) { std::cout << std::source_location::current().function_name() << "\n"; @@ -130,6 +187,16 @@ void XmiFsmImpl::Transition3Action1(XmiTestBase::Event /*event*/) transition3_action1_called_ = true; } +bool XmiFsmImpl::ChoiceGuard1(XmiTestBase::Event /*event*/) +{ + std::cout << std::source_location::current().function_name() << "\n"; + return choice_guard1_result_; +} +bool XmiFsmImpl::ChoiceGuard2(XmiTestBase::Event /*event*/) +{ + std::cout << std::source_location::current().function_name() << "\n"; + return choice_guard2_result_; +} bool XmiFsmImpl::State2Transition3Guard(XmiTestBase::Event /*event*/) { std::cout << std::source_location::current().function_name() << "\n"; diff --git a/test/XmiFsmImpl.hxx b/test/XmiFsmImpl.hxx index 7d824ad..e6f4d59 100644 --- a/test/XmiFsmImpl.hxx +++ b/test/XmiFsmImpl.hxx @@ -15,11 +15,21 @@ private: bool on_unhandled_event_called_ = false; void UnhandledEvent() override; + bool choice_action1_called_ = false; + void ChoiceAction1(XmiTestBase::Event event) override; + bool choice_action2_called_ = false; + void ChoiceAction2(XmiTestBase::Event event) override; + bool choice_action3_called_ = false; + void ChoiceAction3(XmiTestBase::Event event) override; bool state2_internal_action_called_ = false; void State2InternalAction(XmiTestBase::Event event) override; bool transition3_action1_called_ = false; void Transition3Action1(XmiTestBase::Event event) override; + bool choice_guard1_result_ = false; + bool ChoiceGuard1(XmiTestBase::Event event) override; + bool choice_guard2_result_ = false; + bool ChoiceGuard2(XmiTestBase::Event event) override; bool state2_transition3_guard_result_ = false; bool State2Transition3Guard(XmiTestBase::Event event) override; diff --git a/test/generated/IXmiTestImpl.hxx b/test/generated/IXmiTestImpl.hxx index 6cb65cb..a75f79e 100644 --- a/test/generated/IXmiTestImpl.hxx +++ b/test/generated/IXmiTestImpl.hxx @@ -1,5 +1,5 @@ // Statemachine XmiTest implementation interface -// Generated: 25.01.24, 21:47 +// Generated: 26.01.24, 17:29 #pragma once @@ -7,10 +7,15 @@ class IXmiTestImpl { public: // Actions + virtual void ChoiceAction1(XmiTestBase::Event event) = 0; + virtual void ChoiceAction2(XmiTestBase::Event event) = 0; + virtual void ChoiceAction3(XmiTestBase::Event event) = 0; virtual void State2InternalAction(XmiTestBase::Event event) = 0; virtual void Transition3Action1(XmiTestBase::Event event) = 0; // Guards + virtual bool ChoiceGuard1(XmiTestBase::Event event) = 0; + virtual bool ChoiceGuard2(XmiTestBase::Event event) = 0; virtual bool State2Transition3Guard(XmiTestBase::Event event) = 0; // Entry/Exit diff --git a/test/generated/XmiTestDeclaration.hxx b/test/generated/XmiTestDeclaration.hxx index c4829b7..cd44399 100644 --- a/test/generated/XmiTestDeclaration.hxx +++ b/test/generated/XmiTestDeclaration.hxx @@ -1,5 +1,5 @@ // Statemachine XmiTest declaration -// Generated: 25.01.24, 21:47 +// Generated: 26.01.24, 17:29 #pragma once diff --git a/test/generated/XmiTestInstance.hxx b/test/generated/XmiTestInstance.hxx index ed595e6..f473b9d 100644 --- a/test/generated/XmiTestInstance.hxx +++ b/test/generated/XmiTestInstance.hxx @@ -1,5 +1,5 @@ // Statemachine XmiTest instance -// Generated: 25.01.24, 21:47 +// Generated: 26.01.24, 17:29 #pragma once @@ -119,6 +119,19 @@ static XmiTest::Transition State_1State_4StateWithSameNameHandler(XmiTest::ImplP } return XmiTest::UnhandledEvent(); + case XmiTest_GET_STATIC_EVENT_ID(Transition_7): + if (impl->ChoiceGuard1(event) && impl->ChoiceGuard2(event)) + { + static const XmiTest::Transition::ActionContainer<2> kActions = {&XmiTest::Impl::ChoiceAction1, &XmiTest::Impl::ChoiceAction2}; + return XmiTest::TransitionTo(XmiTest::kState_1State_4State_5, kActions); + } + if (impl->ChoiceGuard1(event)) + { + static const XmiTest::Transition::ActionContainer<2> kActions = {&XmiTest::Impl::ChoiceAction1, &XmiTest::Impl::ChoiceAction3}; + return XmiTest::TransitionTo(XmiTest::kState_1StateWithSameName, kActions); + } + return XmiTest::UnhandledEvent(); + default: return XmiTest::UnhandledEvent(); } diff --git a/test/xmi/XmiTest.notation b/test/xmi/XmiTest.notation index de49397..eda993c 100644 --- a/test/xmi/XmiTest.notation +++ b/test/xmi/XmiTest.notation @@ -137,12 +137,22 @@ + + + + + + + + + + - + - + @@ -157,14 +167,14 @@ - + - + - + @@ -175,7 +185,7 @@ - + @@ -190,12 +200,12 @@ - + - + - + @@ -237,7 +247,7 @@ - + @@ -253,7 +263,7 @@ - + @@ -272,7 +282,7 @@ - + @@ -291,7 +301,7 @@ - + @@ -310,7 +320,7 @@ - + @@ -329,7 +339,7 @@ - + @@ -345,7 +355,7 @@ - + @@ -361,8 +371,65 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/xmi/XmiTest.uml b/test/xmi/XmiTest.uml index 4eb99ab..a59ac7c 100644 --- a/test/xmi/XmiTest.uml +++ b/test/xmi/XmiTest.uml @@ -47,9 +47,23 @@ + + + + + + + + + + + + + +