Skip to content

Commit

Permalink
mock operations reset function (#569)
Browse files Browse the repository at this point in the history
* reset function

* reset function
  • Loading branch information
magni-mar authored May 30, 2024
1 parent 2801e75 commit 431db34
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ struct mock_interface {
/// \brief remove all callback subscriptions
auto remove_all_callbacks() -> std::error_code;

/// \brief reset operation mode to starting state
auto reset() -> std::error_code;

/// \brief subscribe to events when entering new mode
/// \param mode mode to subscribe to
/// \param callback invocable<new_mode_e, old_mode_e>
Expand Down
5 changes: 5 additions & 0 deletions libs/operation_mode/testing/mocks/src/operation_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ std::error_code mock_interface::remove_all_callbacks() {
callbacks_.clear();
return {};
}
std::error_code mock_interface::reset() {
set(mode_e::unknown);
auto err = remove_all_callbacks();
return err;
}
uuid_t mock_interface::append_callback_impl(mode_e mode_value,
transition_e transition,
std::function<void(new_mode_e, old_mode_e)> callback) {
Expand Down
10 changes: 10 additions & 0 deletions libs/operation_mode/testing/tests/mock_operation_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ struct instance {
int main(int, char** argv) {
std::array<char const*, 4> args{ argv[0], "--log-level", "trace", "--stdout" };
tfc::base::init(args.size(), args.data());

"reset function"_test = [] {
instance i;
i.op.on_leave(tfc::operation::mode_e::running,
[&i](tfc::operation::mode_e, tfc::operation::mode_e) { i.ran[0] = true; });
i.op.set(tfc::operation::mode_e::running);
i.op.reset();
expect(i.ran[0]);
};

"mode mock on enter test"_test = [] {
instance i;
i.op.on_enter(tfc::operation::mode_e::running,
Expand Down

0 comments on commit 431db34

Please sign in to comment.