Skip to content

Commit

Permalink
✅ (tests): Add state machine tests for BLE
Browse files Browse the repository at this point in the history
  • Loading branch information
HPezz committed May 6, 2022
1 parent 096024e commit 41eb886
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
40 changes: 40 additions & 0 deletions libs/RobotKit/tests/StateMachine_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,43 @@ TEST_F(StateMachineTest, stateChargingEventUpdateRequestedGuardFalse)

EXPECT_TRUE(sm.is(lksm::state::charging));
}

TEST_F(StateMachineTest, stateSleepingEventBleConnection)
{
sm.set_current_states(lksm::state::sleeping);

EXPECT_CALL(mock_rc, startConnectingBehavior).Times(1);

sm.process_event(lksm::event::ble_connection {});

EXPECT_TRUE(sm.is(lksm::state::sleeping));
}

TEST_F(StateMachineTest, stateSleepingEventBleDisconnection)
{
sm.set_current_states(lksm::state::sleeping);

sm.process_event(lksm::event::ble_disconnection {});

EXPECT_TRUE(sm.is(lksm::state::idle));
}

TEST_F(StateMachineTest, stateIdleEventBleConnection)
{
sm.set_current_states(lksm::state::idle);

EXPECT_CALL(mock_rc, startConnectingBehavior).Times(1);

sm.process_event(lksm::event::ble_connection {});

EXPECT_TRUE(sm.is(lksm::state::idle));
}

TEST_F(StateMachineTest, stateIdleEventBleDisconnection)
{
sm.set_current_states(lksm::state::idle);

sm.process_event(lksm::event::ble_disconnection {});

EXPECT_TRUE(sm.is(lksm::state::idle));
}
2 changes: 2 additions & 0 deletions libs/RobotKit/tests/mocks/RobotController.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ struct RobotController : public interface::RobotController {
MOCK_METHOD(void, startChargingBehavior, (), (override));
MOCK_METHOD(void, stopChargingBehavior, (), (override));

MOCK_METHOD(void, startConnectingBehavior, (), (override));

MOCK_METHOD(bool, isReadyToUpdate, (), (override));
MOCK_METHOD(void, applyUpdate, (), (override));
};
Expand Down

0 comments on commit 41eb886

Please sign in to comment.