Skip to content

Commit

Permalink
Improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
dziegel committed Aug 22, 2024
1 parent e93458c commit 4102f58
Show file tree
Hide file tree
Showing 8 changed files with 190 additions and 44 deletions.
2 changes: 1 addition & 1 deletion generator/src/generator/ScxmlModel.egl
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ operation t_transition getModel(state: Tuple) : Tuple {
result.actions.add(script.a_src);
}

if (self.a_cond.isDefined()) {
if (self.a_cond.isDefined() and (self.a_cond != "else")) {
result.guards.add(self.a_cond);
}

Expand Down
38 changes: 38 additions & 0 deletions test/XmiFsmImpl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ void XmiFsmImpl::Test()

// Choice: One guard return true
choice_guard1_result_ = true;
choice_guard2_result_ = false;
choice_guard3_result_ = false;
fsm_.React(Transition_7::MakeShared());
assert(fsm_.CurrentState() == &XmiTest::kState_1StateWithSameName);
assert(choice_action1_called_);
Expand All @@ -136,7 +138,9 @@ void XmiFsmImpl::Test()
CheckAllFalse();

// Choice: Two guards return true
choice_guard1_result_ = true;
choice_guard2_result_ = true;
choice_guard3_result_ = false;
fsm_.React(Transition_7::MakeShared());
assert(fsm_.CurrentState() == &XmiTest::kState_1State_4State_5);
assert(choice_action1_called_);
Expand All @@ -145,6 +149,29 @@ void XmiFsmImpl::Test()
choice_action2_called_ = false;
CheckAllFalse();

// Return to State_1::State_4::StateWithSameName
fsm_.React(Transition_3::MakeShared());
assert(fsm_.CurrentState() == &XmiTest::kState_1State_4StateWithSameName);
CheckAllFalse();

// Choice: Two guards return true, part 2
choice_guard1_result_ = true;
choice_guard2_result_ = false;
choice_guard3_result_ = true;
fsm_.React(Transition_7::MakeShared());
assert(fsm_.CurrentState() == &XmiTest::kState_1State_2);
assert(choice_action1_called_);
choice_action1_called_ = false;
assert(choice_action3_called_);
choice_action3_called_ = false;
assert(choice_action4_called_);
choice_action4_called_ = false;
assert(state2_on_entry_called_);
state2_on_entry_called_ = false;
assert(state4_on_exit_called_);
state4_on_exit_called_ = false;
CheckAllFalse();

assert(pool_->FillLevel() == kPoolSize);
}

Expand All @@ -155,6 +182,7 @@ void XmiFsmImpl::CheckAllFalse() const
assert(choice_action1_called_ == false);
assert(choice_action2_called_ == false);
assert(choice_action3_called_ == false);
assert(choice_action4_called_ == false);
assert(state2_internal_action_called_ == false);
assert(transition3_action1_called_ == false);

Expand Down Expand Up @@ -187,6 +215,11 @@ void XmiFsmImpl::ChoiceAction3(XmiTestBase::Event /*event*/)
std::cout << std::source_location::current().function_name() << "\n";
choice_action3_called_ = true;
}
void XmiFsmImpl::ChoiceAction4(XmiTestBase::Event /*event*/)
{
std::cout << std::source_location::current().function_name() << "\n";
choice_action4_called_ = true;
}
void XmiFsmImpl::State2InternalAction(XmiTestBase::Event /*event*/)
{
std::cout << std::source_location::current().function_name() << "\n";
Expand All @@ -208,6 +241,11 @@ bool XmiFsmImpl::ChoiceGuard2(XmiTestBase::Event /*event*/)
std::cout << std::source_location::current().function_name() << "\n";
return choice_guard2_result_;
}
bool XmiFsmImpl::ChoiceGuard3(XmiTestBase::Event /*event*/)
{
std::cout << std::source_location::current().function_name() << "\n";
return choice_guard3_result_;
}
bool XmiFsmImpl::State2Transition3Guard(XmiTestBase::Event /*event*/)
{
std::cout << std::source_location::current().function_name() << "\n";
Expand Down
4 changes: 4 additions & 0 deletions test/XmiFsmImpl.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ private:
void ChoiceAction2(XmiTestBase::Event event) override;
bool choice_action3_called_ = false;
void ChoiceAction3(XmiTestBase::Event event) override;
bool choice_action4_called_ = false;
void ChoiceAction4(XmiTestBase::Event event) override;
bool state2_internal_action_called_ = false;
void State2InternalAction(XmiTestBase::Event event) override;
bool transition3_action1_called_ = false;
Expand All @@ -31,6 +33,8 @@ private:
bool ChoiceGuard1(XmiTestBase::Event event) override;
bool choice_guard2_result_ = false;
bool ChoiceGuard2(XmiTestBase::Event event) override;
bool choice_guard3_result_ = false;
bool ChoiceGuard3(XmiTestBase::Event event) override;
bool state2_transition3_guard_result_ = false;
bool State2Transition3Guard(XmiTestBase::Event event) override;

Expand Down
4 changes: 3 additions & 1 deletion test/generated/IXmiTestImpl.hxx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Statemachine XmiTest implementation interface
// Generated: 21.08.24, 21:04
// Generated: 21.08.24, 22:20

#pragma once

Expand All @@ -12,12 +12,14 @@ class IXmiTestImpl
virtual void ChoiceAction1(XmiTestBase::Event event) = 0;
virtual void ChoiceAction2(XmiTestBase::Event event) = 0;
virtual void ChoiceAction3(XmiTestBase::Event event) = 0;
virtual void ChoiceAction4(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 ChoiceGuard3(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: 21.08.24, 21:03
// Generated: 21.08.24, 22:20

#pragma once

Expand Down
11 changes: 10 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: 21.08.24, 21:04
// Generated: 21.08.24, 22:20

#pragma once

Expand Down Expand Up @@ -121,6 +121,15 @@ static XmiTest::Transition State_1State_4StateWithSameNameHandler(XmiTest::ImplP
return XmiTest::TransitionTo(XmiTest::kState_1State_4State_5, kActions);
}
}

if (impl->ChoiceGuard3(event))
{

{
static const auto kActions = std::to_array<XmiTest::Transition::ActionType>({&XmiTest::Impl::ChoiceAction1, &XmiTest::Impl::ChoiceAction3, &XmiTest::Impl::ChoiceAction4});
return XmiTest::TransitionTo(XmiTest::kState_1State_2, kActions);
}
}
{
static const auto kActions = std::to_array<XmiTest::Transition::ActionType>({&XmiTest::Impl::ChoiceAction1, &XmiTest::Impl::ChoiceAction3});
return XmiTest::TransitionTo(XmiTest::kState_1StateWithSameName, kActions);
Expand Down
Loading

0 comments on commit 4102f58

Please sign in to comment.