-
Notifications
You must be signed in to change notification settings - Fork 814
Expand file tree
/
Copy pathgtest_updates.cpp
More file actions
132 lines (111 loc) · 3.43 KB
/
gtest_updates.cpp
File metadata and controls
132 lines (111 loc) · 3.43 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include "test_helper.hpp"
#include "behaviortree_cpp/basic_types.h"
#include "behaviortree_cpp/bt_factory.h"
#include <string>
#include <gtest/gtest.h>
using namespace BT;
const std::string xml_text_check = R"(
<root BTCPP_format="4" >
<BehaviorTree ID="Check">
<Sequence>
<Fallback>
<WasEntryUpdated entry="A"/>
<TestA/>
</Fallback>
<SkipUnlessUpdated entry="A">
<TestB/>
</SkipUnlessUpdated>
</Sequence>
</BehaviorTree>
</root>)";
TEST(EntryUpdates, NoEntry)
{
BehaviorTreeFactory factory;
std::array<int, 2> counters{};
RegisterTestTick(factory, "Test", counters);
const std::string xml_text = R"(
<root BTCPP_format="4" >
<BehaviorTree ID="Main">
<Sequence>
<SubTree ID="Check" _autoremap="true"/>
</Sequence>
</BehaviorTree>
</root>)";
factory.registerBehaviorTreeFromText(xml_text_check);
factory.registerBehaviorTreeFromText(xml_text);
auto tree = factory.createTree("Main");
const auto status = tree.tickWhileRunning();
ASSERT_EQ(status, NodeStatus::SUCCESS);
EXPECT_EQ(1, counters[0]); // fallback!
EXPECT_EQ(0, counters[1]); // skipped
}
TEST(EntryUpdates, Initialized)
{
BehaviorTreeFactory factory;
std::array<int, 2> counters{};
RegisterTestTick(factory, "Test", counters);
const std::string xml_text = R"(
<root BTCPP_format="4" >
<BehaviorTree ID="Main">
<Sequence>
<Script code="A:=1;B:=1"/>
<SubTree ID="Check" _autoremap="true"/>
</Sequence>
</BehaviorTree>
</root>)";
factory.registerBehaviorTreeFromText(xml_text_check);
factory.registerBehaviorTreeFromText(xml_text);
auto tree = factory.createTree("Main");
const auto status = tree.tickWhileRunning();
ASSERT_EQ(status, NodeStatus::SUCCESS);
EXPECT_EQ(0, counters[0]); // fallback!
EXPECT_EQ(1, counters[1]); // skipped
}
TEST(EntryUpdates, UpdateOnce)
{
BehaviorTreeFactory factory;
std::array<int, 2> counters{};
RegisterTestTick(factory, "Test", counters);
const std::string xml_text = R"(
<root BTCPP_format="4" >
<BehaviorTree ID="Main">
<Sequence>
<Script code="A:=1"/>
<Repeat num_cycles="2" >
<SubTree ID="Check" _autoremap="true"/>
</Repeat>
</Sequence>
</BehaviorTree>
</root>)";
factory.registerBehaviorTreeFromText(xml_text_check);
factory.registerBehaviorTreeFromText(xml_text);
auto tree = factory.createTree("Main");
const auto status = tree.tickWhileRunning();
ASSERT_EQ(status, NodeStatus::SUCCESS);
EXPECT_EQ(1, counters[0]); // fallback!
EXPECT_EQ(1, counters[1]); // skipped
}
TEST(EntryUpdates, UpdateTwice)
{
BehaviorTreeFactory factory;
std::array<int, 2> counters{};
RegisterTestTick(factory, "Test", counters);
const std::string xml_text = R"(
<root BTCPP_format="4" >
<BehaviorTree ID="Main">
<Repeat num_cycles="2" >
<Sequence>
<Script code="A:=1"/>
<SubTree ID="Check" _autoremap="true"/>
</Sequence>
</Repeat>
</BehaviorTree>
</root>)";
factory.registerBehaviorTreeFromText(xml_text_check);
factory.registerBehaviorTreeFromText(xml_text);
auto tree = factory.createTree("Main");
const auto status = tree.tickWhileRunning();
ASSERT_EQ(status, NodeStatus::SUCCESS);
EXPECT_EQ(0, counters[0]); // fallback!
EXPECT_EQ(2, counters[1]); // skipped
}