-
Notifications
You must be signed in to change notification settings - Fork 839
Expand file tree
/
Copy pathgtest_interface.cpp
More file actions
80 lines (71 loc) · 1.6 KB
/
gtest_interface.cpp
File metadata and controls
80 lines (71 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <iostream>
#include <memory>
#include <behaviortree_cpp/bt_factory.h>
#include <gtest/gtest.h>
// interface
struct IMotor
{
IMotor() = default;
virtual ~IMotor() = default;
IMotor(const IMotor&) = default;
IMotor& operator=(const IMotor&) = default;
IMotor(IMotor&&) = default;
IMotor& operator=(IMotor&&) = default;
virtual void doMove() = 0;
};
// implementation
struct LinearMotor : public IMotor
{
void doMove() override
{
std::cout << ">> doMove" << std::endl;
}
};
namespace
{
const char* xml_text = R"(
<root BTCPP_format="4">
<BehaviorTree ID="MainTree">
<Sequence name="root_sequence">
<PathFollow/>
</Sequence>
</BehaviorTree>
</root>
)";
} // namespace
// node using interface
class PathFollow : public BT::StatefulActionNode
{
public:
PathFollow(const std::string& name, const BT::NodeConfig& config, IMotor& motor)
: BT::StatefulActionNode(name, config), imotor_(motor)
{}
static BT::PortsList providedPorts()
{
return {};
}
BT::NodeStatus onStart() override
{
std::cout << "onStart" << std::endl;
imotor_.doMove();
return BT::NodeStatus::RUNNING;
}
BT::NodeStatus onRunning() override
{
std::cout << "onRunning" << std::endl;
imotor_.doMove();
return BT::NodeStatus::SUCCESS;
}
void onHalted() override
{}
private:
IMotor& imotor_;
};
TEST(Factory, VirtualInterface_Issue_945)
{
LinearMotor motor;
BT::BehaviorTreeFactory factory;
factory.registerNodeType<PathFollow>("PathFollow", std::ref(motor));
auto tree = factory.createTreeFromText(xml_text);
tree.tickWhileRunning();
}