|
3 | 3 | #include "behaviortree_cpp/basic_types.h" |
4 | 4 | #include "behaviortree_cpp/bt_factory.h" |
5 | 5 | #include "test_helper.hpp" |
| 6 | +#include "action_test_node.h" |
6 | 7 |
|
7 | 8 | using namespace BT; |
8 | 9 |
|
@@ -121,39 +122,56 @@ TEST(SkippingLogic, SkippingReactiveSequence) |
121 | 122 | std::array<int, 2> counters; |
122 | 123 | RegisterTestTick(factory, "Test", counters); |
123 | 124 |
|
124 | | - const std::string xml_text = R"( |
| 125 | + const std::string xml_text_noskip = R"( |
125 | 126 | <root BTCPP_format="4" > |
126 | 127 | <BehaviorTree> |
127 | | - <Sequence> |
128 | | - <ReactiveSequence> |
129 | | - <Script code=" value:=50 "/> |
130 | | - <TestA _skipIf="value < 25"/> |
131 | | - </ReactiveSequence> |
132 | | -
|
133 | | - <ReactiveSequence> |
134 | | - <Script code=" value:=10 "/> |
135 | | - <TestB _skipIf="value < 25"/> |
136 | | - </ReactiveSequence> |
137 | | - </Sequence> |
| 128 | + <ReactiveSequence> |
| 129 | + <Script code=" value:=50 "/> |
| 130 | + <TestA _skipIf="value < 25"/> |
| 131 | + <AsyncActionTest/> |
| 132 | + </ReactiveSequence> |
138 | 133 | </BehaviorTree> |
139 | 134 | </root>)"; |
140 | 135 |
|
141 | | - auto tree = factory.createTreeFromText(xml_text); |
| 136 | + const std::string xml_text_skip = R"( |
| 137 | + <root BTCPP_format="4" > |
| 138 | + <BehaviorTree> |
| 139 | + <ReactiveSequence> |
| 140 | + <Script code=" value:=10 "/> |
| 141 | + <TestB _skipIf="value < 25"/> |
| 142 | + <AsyncActionTest/> |
| 143 | + </ReactiveSequence> |
| 144 | + </BehaviorTree> |
| 145 | + </root>)"; |
| 146 | + |
| 147 | + factory.registerNodeType<AsyncActionTest>("AsyncActionTest"); |
| 148 | + |
| 149 | + int expected_test_A_ticks = 0; |
142 | 150 |
|
143 | | - BT::NodeStatus status; |
144 | | - try { |
145 | | - int runs = 0; |
146 | | - while(runs < 5) |
| 151 | + for(auto const* xml_text: {&xml_text_noskip, &xml_text_skip}) |
| 152 | + { |
| 153 | + auto tree = factory.createTreeFromText(*xml_text); |
| 154 | + |
| 155 | + for(int repeat=0; repeat<3; repeat++) |
147 | 156 | { |
148 | | - status = tree.tickOnce(); |
149 | | - tree.sleep(std::chrono::milliseconds(10)); |
150 | | - runs++; |
| 157 | + NodeStatus status = NodeStatus::IDLE; |
| 158 | + while(!StatusCompleted(status)) |
| 159 | + { |
| 160 | + status = tree.tickOnce(); |
| 161 | + |
| 162 | + if(xml_text == &xml_text_noskip) |
| 163 | + { |
| 164 | + expected_test_A_ticks++; |
| 165 | + } |
| 166 | + |
| 167 | + tree.sleep(std::chrono::milliseconds{15}); |
| 168 | + } |
| 169 | + ASSERT_EQ(status, NodeStatus::SUCCESS); |
151 | 170 | } |
152 | | - } catch (BT::LogicError err) { |
153 | | - std::cout << err.what() << std::endl; |
154 | 171 | } |
| 172 | + // counters[0] contains the number ot times TestA was ticked |
| 173 | + ASSERT_EQ(counters[0], expected_test_A_ticks); |
155 | 174 |
|
156 | | - ASSERT_EQ(status, NodeStatus::SUCCESS); |
157 | | - ASSERT_EQ(counters[0], 5); |
| 175 | + // counters[1] contains the number ot times TestB was ticked |
158 | 176 | ASSERT_EQ(counters[1], 0); |
159 | 177 | } |
0 commit comments