| 408 | } |
| 409 | |
| 410 | TEST(Parallel, FailingParallel) |
| 411 | { |
| 412 | static const char* xml_text = R"( |
| 413 | <root BTCPP_format="4"> |
| 414 | <BehaviorTree ID="MainTree"> |
| 415 | <Parallel name="parallel" success_count="1" failure_count="3"> |
| 416 | <GoodTest name="first"/> |
| 417 | <BadTest name="second"/> |
| 418 | <SlowTest name="third"/> |
| 419 | </Parallel> |
| 420 | </BehaviorTree> |
| 421 | </root> )"; |
| 422 | using namespace BT; |
| 423 | |
| 424 | BehaviorTreeFactory factory; |
| 425 | |
| 426 | BT::TestNodeConfig good_config; |
| 427 | good_config.async_delay = std::chrono::milliseconds(200); |
| 428 | good_config.return_status = NodeStatus::SUCCESS; |
| 429 | factory.registerNodeType<BT::TestNode>("GoodTest", good_config); |
| 430 | |
| 431 | BT::TestNodeConfig bad_config; |
| 432 | bad_config.async_delay = std::chrono::milliseconds(100); |
| 433 | bad_config.return_status = NodeStatus::FAILURE; |
| 434 | factory.registerNodeType<BT::TestNode>("BadTest", bad_config); |
| 435 | |
| 436 | BT::TestNodeConfig slow_config; |
| 437 | slow_config.async_delay = std::chrono::milliseconds(300); |
| 438 | slow_config.return_status = NodeStatus::SUCCESS; |
| 439 | factory.registerNodeType<BT::TestNode>("SlowTest", slow_config); |
| 440 | |
| 441 | auto tree = factory.createTreeFromText(xml_text); |
| 442 | BT::TreeObserver observer(tree); |
| 443 | |
| 444 | auto state = tree.tickWhileRunning(); |
| 445 | // since at least one succeeded. |
| 446 | ASSERT_EQ(NodeStatus::SUCCESS, state); |
| 447 | ASSERT_EQ(1, observer.getStatistics("first").success_count); |
| 448 | ASSERT_EQ(1, observer.getStatistics("second").failure_count); |
| 449 | ASSERT_EQ(0, observer.getStatistics("third").failure_count); |
| 450 | } |
| 451 | |
| 452 | TEST(Parallel, ParallelAll) |
| 453 | { |
nothing calls this directly
no test coverage detected