|
12 | 12 |
|
13 | 13 | #include <gtest/gtest.h>
|
14 | 14 | #include "action_test_node.h"
|
| 15 | +#include "behaviortree_cpp/loggers/bt_observer.h" |
15 | 16 | #include "condition_test_node.h"
|
16 |
| -#include "behaviortree_cpp/behavior_tree.h" |
| 17 | +#include "behaviortree_cpp/bt_factory.h" |
17 | 18 |
|
18 | 19 | using BT::NodeStatus;
|
19 | 20 | using std::chrono::milliseconds;
|
@@ -393,3 +394,38 @@ TEST_F(ComplexParallelTest, ConditionRightFalseAction1Done)
|
393 | 394 |
|
394 | 395 | ASSERT_EQ(NodeStatus::SUCCESS, state);
|
395 | 396 | }
|
| 397 | + |
| 398 | +TEST(FailingParallel, FailingParallel) |
| 399 | +{ |
| 400 | + static const char* xml_text = R"( |
| 401 | +<root BTCPP_format="4"> |
| 402 | + <BehaviorTree ID="MainTree"> |
| 403 | + <Parallel name="parallel" success_count="1" failure_count="3"> |
| 404 | + <GoodTest name="first"/> |
| 405 | + <BadTest name="second"/> |
| 406 | + <GoodTest name="third"/> |
| 407 | + </Parallel> |
| 408 | + </BehaviorTree> |
| 409 | +</root> )"; |
| 410 | + using namespace BT; |
| 411 | + |
| 412 | + BehaviorTreeFactory factory; |
| 413 | + |
| 414 | + BT::TestNodeConfig good_config; |
| 415 | + good_config.async_delay = std::chrono::milliseconds(300); |
| 416 | + good_config.return_status = NodeStatus::SUCCESS; |
| 417 | + factory.registerNodeType<BT::TestNode>("GoodTest", good_config); |
| 418 | + |
| 419 | + BT::TestNodeConfig bad_config; |
| 420 | + bad_config.async_delay = std::chrono::milliseconds(100); |
| 421 | + bad_config.return_status = NodeStatus::FAILURE; |
| 422 | + factory.registerNodeType<BT::TestNode>("BadTest", bad_config); |
| 423 | + |
| 424 | + auto tree = factory.createTreeFromText(xml_text); |
| 425 | + BT::TreeObserver observer(tree); |
| 426 | + |
| 427 | + auto state = tree.tickWhileRunning(); |
| 428 | + // since at least one succeeded. |
| 429 | + ASSERT_EQ(NodeStatus::SUCCESS, state); |
| 430 | + ASSERT_EQ( 1, observer.getStatistics("second").failure_count); |
| 431 | +} |
0 commit comments