Skip to content

Commit

Permalink
Make XMI test run with cpp_event_framework::Signals
Browse files Browse the repository at this point in the history
  • Loading branch information
dziegel committed Jan 27, 2024
1 parent 5724f77 commit 530b5f9
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 35 deletions.
3 changes: 0 additions & 3 deletions test/XmiFsm.cxx
Original file line number Diff line number Diff line change
@@ -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"
56 changes: 36 additions & 20 deletions test/XmiFsm.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,62 @@

#include <ostream>

#include <cpp_event_framework/Pool.hxx>
#include <cpp_event_framework/Signal.hxx>
#include <cpp_event_framework/Statemachine.hxx>

enum class EXmiEvent
class Transition_1 : public cpp_event_framework::SignalBase<Transition_1, 0>
{
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<Transition_2, Transition_1>
{
switch (event)
};
class Transition_3 : public cpp_event_framework::NextSignal<Transition_3, Transition_2>
{
};
class Transition_4 : public cpp_event_framework::NextSignal<Transition_4, Transition_3>
{
};
class Transition_6 : public cpp_event_framework::NextSignal<Transition_6, Transition_4>
{
};
class Transition_7 : public cpp_event_framework::NextSignal<Transition_7, Transition_6>
{
};
class Transition_8 : public cpp_event_framework::NextSignal<Transition_8, Transition_7>
{
};
class Internal : public cpp_event_framework::NextSignal<Internal, Transition_8>
{
};

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:
Expand All @@ -52,7 +68,7 @@ inline std::ostream& operator<<(std::ostream& os, EXmiEvent event)
}

class IXmiFsmImpl;
using XmiTestBase = cpp_event_framework::Statemachine<IXmiFsmImpl, EXmiEvent>;
using XmiTestBase = cpp_event_framework::Statemachine<IXmiFsmImpl, const cpp_event_framework::Signal::SPtr&>;

#include "generated/IXmiTestImpl.hxx"
#include "generated/XmiTestDeclaration.hxx"
Expand Down
24 changes: 12 additions & 12 deletions test/XmiFsmImpl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -36,30 +36,30 @@ 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;
CheckAllFalse();

// 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;
CheckAllFalse();

// 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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 530b5f9

Please sign in to comment.