feat: Improve ChangeState API

* Add `[[nodiscard]]` to `bool Device::ChangeState()`
* Introduce throwing variant `void Device::ChangeStateOrThrow()`

resolves #441
This commit is contained in:
Dennis Klein
2023-02-28 12:12:54 +01:00
parent 919c496c42
commit 035029df6a
4 changed files with 75 additions and 24 deletions

View File

@@ -97,4 +97,26 @@ TEST(Transitions, ConcurrentTransitionTos)
}
}
TEST(Transitions, InvalidChangeState)
{
Device device;
thread t([&] { device.RunStateMachine(); });
ASSERT_FALSE(device.ChangeState(Transition::Connect));
ASSERT_TRUE(device.ChangeState(Transition::End));
if (t.joinable()) { t.join(); }
}
TEST(Transitions, InvalidChangeStateOrThrow)
{
Device device;
thread t([&] { device.RunStateMachine(); });
ASSERT_THROW(device.ChangeStateOrThrow(Transition::Connect), std::system_error);
ASSERT_NO_THROW(device.ChangeStateOrThrow(Transition::End));
if (t.joinable()) { t.join(); }
}
} // namespace