Skip to content

Commit 9c1aa08

Browse files
committed
Merge branch 'add_vector_to_json'
2 parents 0ee319b + 3ac3191 commit 9c1aa08

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

tests/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ set(BT_TESTS
2828
gtest_tree.cpp
2929
gtest_updates.cpp
3030
gtest_wakeup.cpp
31+
gtest_interface.cpp
3132

3233
script_parser_test.cpp
3334
test_helper.hpp

tests/gtest_interface.cpp

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#include <gtest/gtest.h>
2+
3+
#include <behaviortree_cpp/bt_factory.h>
4+
#include <iostream>
5+
#include <memory>
6+
7+
// interface
8+
struct IMotor
9+
{
10+
virtual void doMove() = 0;
11+
};
12+
13+
// implementation
14+
struct LinearMotor : public IMotor
15+
{
16+
void doMove() override
17+
{
18+
std::cout << ">> doMove" << std::endl;
19+
}
20+
};
21+
22+
static const char* xml_text = R"(
23+
<root BTCPP_format="4">
24+
<BehaviorTree ID="MainTree">
25+
<Sequence name="root_sequence">
26+
<PathFollow/>
27+
</Sequence>
28+
</BehaviorTree>
29+
</root>
30+
)";
31+
32+
// node using interface
33+
class PathFollow : public BT::StatefulActionNode
34+
{
35+
public:
36+
PathFollow(const std::string& name, const BT::NodeConfig& config, IMotor& motor)
37+
: BT::StatefulActionNode(name, config), imotor_(motor)
38+
{}
39+
static BT::PortsList providedPorts()
40+
{
41+
return {};
42+
}
43+
BT::NodeStatus onStart() override
44+
{
45+
std::cout << "onStart" << std::endl;
46+
imotor_.doMove();
47+
return BT::NodeStatus::RUNNING;
48+
}
49+
BT::NodeStatus onRunning() override
50+
{
51+
std::cout << "onRunning" << std::endl;
52+
imotor_.doMove();
53+
return BT::NodeStatus::SUCCESS;
54+
}
55+
void onHalted() override
56+
{}
57+
58+
private:
59+
IMotor& imotor_;
60+
};
61+
62+
TEST(Factory, VirtualInterface_Issue_945)
63+
{
64+
LinearMotor motor;
65+
BT::BehaviorTreeFactory factory;
66+
factory.registerNodeType<PathFollow>("PathFollow", std::ref(motor));
67+
68+
auto tree = factory.createTreeFromText(xml_text);
69+
tree.tickWhileRunning();
70+
}

0 commit comments

Comments
 (0)