Skip to content

Commit 6117937

Browse files
committed
test that logging works correctly with ReactiveSequence BehaviorTree#643
1 parent be414e0 commit 6117937

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

tests/gtest_reactive.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <gtest/gtest.h>
22
#include "behaviortree_cpp/bt_factory.h"
33
#include "test_helper.hpp"
4+
#include "behaviortree_cpp/loggers/bt_observer.h"
45

56
using BT::NodeStatus;
67
using std::chrono::milliseconds;
@@ -124,3 +125,41 @@ TEST(Reactive, PreTickHooks)
124125
}
125126

126127

128+
TEST(Reactive, TestLogging)
129+
{
130+
using namespace BT;
131+
132+
static const char* reactive_xml_text = R"(
133+
<root BTCPP_format="4" >
134+
<BehaviorTree ID="Main">
135+
<ReactiveSequence>
136+
<TestA name="testA"/>
137+
<AlwaysSuccess name="success"/>
138+
<Sleep msec="100"/>
139+
</ReactiveSequence>
140+
</BehaviorTree>
141+
</root>
142+
)";
143+
144+
BehaviorTreeFactory factory;
145+
146+
std::array<int, 1> counters;
147+
RegisterTestTick(factory, "Test", counters);
148+
149+
auto tree = factory.createTreeFromText(reactive_xml_text);
150+
TreeObserver observer(tree);
151+
152+
auto ret = tree.tickWhileRunning();
153+
ASSERT_EQ(ret, NodeStatus::SUCCESS);
154+
155+
int num_ticks = counters[0];
156+
ASSERT_GE(num_ticks, 5);
157+
158+
ASSERT_EQ(observer.getStatistics("testA").success_count, num_ticks);
159+
ASSERT_EQ(observer.getStatistics("success").success_count, num_ticks);
160+
}
161+
162+
163+
164+
165+

0 commit comments

Comments
 (0)