| 179 | /****************TESTS START HERE***************************/ |
| 180 | |
| 181 | TEST(Navigationtest, MoveBaseRecovery) |
| 182 | { |
| 183 | BehaviorTreeFactory factory; |
| 184 | |
| 185 | factory.registerNodeType<IsStuck>("IsStuck"); |
| 186 | factory.registerNodeType<BackUpAndSpin>("BackUpAndSpin"); |
| 187 | factory.registerNodeType<ComputePathToPose>("ComputePathToPose"); |
| 188 | factory.registerNodeType<FollowPath>("FollowPath"); |
| 189 | |
| 190 | auto tree = factory.createTreeFromText(xml_text); |
| 191 | |
| 192 | // Need to retrieve the node pointers with dynamic cast |
| 193 | // In a normal application you would NEVER want to do such a thing. |
| 194 | IsStuck* first_stuck_node = nullptr; |
| 195 | IsStuck* second_stuck_node = nullptr; |
| 196 | BackUpAndSpin* back_spin_node = nullptr; |
| 197 | ComputePathToPose* compute_node = nullptr; |
| 198 | FollowPath* follow_node = nullptr; |
| 199 | |
| 200 | for(auto& subtree : tree.subtrees) |
| 201 | { |
| 202 | for(auto& node : subtree->nodes) |
| 203 | { |
| 204 | auto ptr = node.get(); |
| 205 | |
| 206 | if(first_stuck_node == nullptr) |
| 207 | { |
| 208 | TryDynamicCastPtr(ptr, first_stuck_node); |
| 209 | } |
| 210 | else |
| 211 | { |
| 212 | TryDynamicCastPtr(ptr, second_stuck_node); |
| 213 | } |
| 214 | TryDynamicCastPtr(ptr, back_spin_node); |
| 215 | TryDynamicCastPtr(ptr, follow_node); |
| 216 | TryDynamicCastPtr(ptr, compute_node); |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | ASSERT_TRUE(first_stuck_node); |
| 221 | ASSERT_TRUE(second_stuck_node); |
| 222 | ASSERT_TRUE(back_spin_node); |
| 223 | ASSERT_TRUE(compute_node); |
| 224 | ASSERT_TRUE(follow_node); |
| 225 | |
| 226 | std::cout << "-----------------------" << std::endl; |
| 227 | |
| 228 | // First case: not stuck, everything fine. |
| 229 | NodeStatus status = NodeStatus::IDLE; |
| 230 | |
| 231 | first_stuck_node->setExpectedResult(false); |
| 232 | |
| 233 | while(status == NodeStatus::IDLE || status == NodeStatus::RUNNING) |
| 234 | { |
| 235 | status = tree.tickWhileRunning(); |
| 236 | std::this_thread::sleep_for(Milliseconds(100)); |
| 237 | } |
| 238 |
nothing calls this directly
no test coverage detected