3 #include "gtest/gtest.h" 24 watch(
"on", [
this](
Event& e) {
27 watch(
"off", [
this](
Event &e) {
30 watch(
"set power", [
this](
Event& e) {
31 power_level = e.
value();
67 if ( e.
name() ==
"power level set" ) {
79 if ( e.
name() ==
"on button pressed" ) {
113 if ( e.
name() ==
"power level set" ) {
126 TEST(Microwave, Safety) {
156 ASSERT_EQ(
true, power.
running);
161 ASSERT_EQ(
false, power.
running);
167 GTEST_API_
int main(
int argc,
char **argv) {
168 testing::InitGoogleTest(&argc, argv);
169 return RUN_ALL_TESTS();
void entry(const Event &e)
Nothing to do upon entry.
The Process Manager class.
void exit(const Event &e)
Nothing to do upon exiting this state.
Manager & schedule(Process &process, high_resolution_clock::duration period)
The state in which the oven's door is open and the oven is off. See examples/microwave.cc.
double power_level
Keep track of the power level.
StateMachine & add_transition(std::string event_name, State &from, State &to)
void start()
Set running to false and power_level to zero.
The state in which the oven's door is closed and the oven is on. See examples/microwave.cc.
StateMachine & set_initial(State &s)
The state in which the oven's door is closed and the oven is off. See examples/microwave.cc.
bool running
Keep track of whether the power is on.
Events that can be emitted, watched, and responded to with event handlers.
void during()
Nothing to do during this state.
States for the StateMachine class.
A class the models the power component of a microwave oven. See examples/microwave.cc.
DoorOpen()
Make a new state.
void stop()
Nothing to do to stop.
void exit(const Event &e)
void entry(const Event &e)
Upon entry,.
void during()
Nothing to do in during.
void during()
Nothing to do in during.
void exit(const Event &e)
DoorClosedOff()
Make a new state.
void entry(const Event &e)
Manager & emit(const Event &event)
A finite state machine class.
void update()
Nothing to do to update.
Power()
Create a new power component.
DoorClosedOn()
Make a new state.
An abstract base class for processes.