Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b651be8

Browse files
committed
Allow registration of TestNode
1 parent d434deb commit b651be8

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

include/behaviortree_cpp/actions/test_node.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,10 @@ struct TestNodeConfig
6060
class TestNode : public BT::StatefulActionNode
6161
{
6262
public:
63-
TestNode(const std::string& name, const NodeConfig& config) :
64-
StatefulActionNode(name, config)
63+
TestNode(const std::string& name, const NodeConfig& config,
64+
TestNodeConfig test_config = {}) :
65+
StatefulActionNode(name, config),
66+
_test_config(std::move(test_config))
6567
{
6668
setRegistrationID("TestNode");
6769
}

tests/gtest_parallel.cpp

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212

1313
#include <gtest/gtest.h>
1414
#include "action_test_node.h"
15+
#include "behaviortree_cpp/loggers/bt_observer.h"
1516
#include "condition_test_node.h"
16-
#include "behaviortree_cpp/behavior_tree.h"
17+
#include "behaviortree_cpp/bt_factory.h"
1718

1819
using BT::NodeStatus;
1920
using std::chrono::milliseconds;
@@ -393,3 +394,38 @@ TEST_F(ComplexParallelTest, ConditionRightFalseAction1Done)
393394

394395
ASSERT_EQ(NodeStatus::SUCCESS, state);
395396
}
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

Comments
 (0)