Skip to content

Commit

Permalink
Extend tests: Check choice states
Browse files Browse the repository at this point in the history
  • Loading branch information
dziegel committed Jan 26, 2024
1 parent 1fd5155 commit 6b184e1
Show file tree
Hide file tree
Showing 8 changed files with 197 additions and 21 deletions.
2 changes: 1 addition & 1 deletion generator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>net.ziegelmeier</groupId>
<artifactId>net.ziegelmeier.statemachinegenerator</artifactId>
<version>1.0.0</version>
<version>1.4.0</version>
<description>Dirk Ziegelmeiers Statemachine Generator</description>
<build>
<sourceDirectory>src</sourceDirectory>
Expand Down
67 changes: 67 additions & 0 deletions test/XmiFsmImpl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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";
Expand All @@ -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";
Expand Down
10 changes: 10 additions & 0 deletions test/XmiFsmImpl.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
7 changes: 6 additions & 1 deletion test/generated/IXmiTestImpl.hxx
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
// Statemachine XmiTest implementation interface
// Generated: 25.01.24, 21:47
// Generated: 26.01.24, 17:29

#pragma once

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
Expand Down
2 changes: 1 addition & 1 deletion test/generated/XmiTestDeclaration.hxx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Statemachine XmiTest declaration
// Generated: 25.01.24, 21:47
// Generated: 26.01.24, 17:29

#pragma once

Expand Down
15 changes: 14 additions & 1 deletion test/generated/XmiTestInstance.hxx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Statemachine XmiTest instance
// Generated: 25.01.24, 21:47
// Generated: 26.01.24, 17:29

#pragma once

Expand Down Expand Up @@ -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();
}
Expand Down
Loading

0 comments on commit 6b184e1

Please sign in to comment.