forked from boost-ext/sml
-
Notifications
You must be signed in to change notification settings - Fork 0
Fix issue_253: clear nested defer queue on sub-state-machine exit #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| // | ||
| // Copyright (c) 2016-2020 Kris Jusiak (kris at jusiak dot net) | ||
| // | ||
| // Distributed under the Boost Software License, Version 1.0. | ||
| // (See accompanying file LICENSE_1_0.txt or copy at | ||
| // http://www.boost.org/LICENSE_1_0.txt) | ||
| // | ||
| #include <boost/sml.hpp> | ||
| #include <deque> | ||
| #include <queue> | ||
|
|
||
|
gabewillen marked this conversation as resolved.
|
||
| namespace sml = boost::sml; | ||
|
|
||
| test issue_253_nested_defer_queue_is_cleared_on_exit = [] { | ||
| struct issue_253_enter {}; | ||
| struct issue_253_exit {}; | ||
| struct issue_253_to_s2 {}; | ||
| struct issue_253_to_s1 {}; | ||
| struct issue_253_e1 {}; | ||
| struct issue_253_outer_idle {}; | ||
|
|
||
| struct issue_253_counters { | ||
| int nested_calls = 0; | ||
| int outer_calls = 0; | ||
| }; | ||
|
|
||
| struct issue_253_nested { | ||
| auto operator()() const { | ||
| using namespace sml; | ||
| const auto issue_253_s1 = sml::state<class issue_253_s1>; | ||
| const auto issue_253_s2 = sml::state<class issue_253_s2>; | ||
| // clang-format off | ||
| return make_transition_table( | ||
| *issue_253_s1 + event<issue_253_to_s2> = issue_253_s2 | ||
| , issue_253_s2 + event<issue_253_e1> / defer | ||
| , issue_253_s2 + event<issue_253_to_s1> = issue_253_s1 | ||
| , issue_253_s1 + event<issue_253_e1> / [](issue_253_counters& counters) { ++counters.nested_calls; } | ||
| ); | ||
| // clang-format on | ||
| } | ||
| }; | ||
|
|
||
| struct issue_253_outer { | ||
| auto operator()() const { | ||
| using namespace sml; | ||
| const auto issue_253_idle = sml::state<issue_253_outer_idle>; | ||
| const auto issue_253_nested_state = sml::state<issue_253_nested>; | ||
| // clang-format off | ||
| return make_transition_table( | ||
| *issue_253_idle + event<issue_253_enter> = issue_253_nested_state | ||
| , issue_253_nested_state + event<issue_253_exit> = issue_253_idle | ||
| , issue_253_idle + event<issue_253_e1> / [](issue_253_counters& counters) { ++counters.outer_calls; } | ||
| ); | ||
| // clang-format on | ||
| } | ||
| }; | ||
|
|
||
| issue_253_counters counters{}; | ||
| sml::sm<issue_253_outer, sml::defer_queue<std::deque>, sml::process_queue<std::queue>> sm{counters}; | ||
|
|
||
| expect(sm.process_event(issue_253_enter{})); | ||
| expect(sm.process_event(issue_253_to_s2{})); | ||
| expect(sm.process_event(issue_253_e1{})); | ||
| expect(sm.process_event(issue_253_to_s1{})); | ||
| expect(sm.process_event(issue_253_exit{})); | ||
| expect(1 == counters.nested_calls); | ||
| expect(0 == counters.outer_calls); | ||
|
|
||
| expect(sm.process_event(issue_253_e1{})); | ||
| expect(1 == counters.outer_calls); | ||
|
|
||
| expect(sm.process_event(issue_253_enter{})); | ||
| expect(sm.process_event(issue_253_to_s2{})); | ||
| expect(sm.process_event(issue_253_to_s1{})); | ||
| expect(sm.process_event(issue_253_exit{})); | ||
| expect(1 == counters.nested_calls); | ||
|
|
||
| expect(sm.process_event(issue_253_e1{})); | ||
| expect(2 == counters.outer_calls); | ||
| }; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.