Skip to content

Commit a0b24ab

Browse files
committed
Add unit test related to SequenceWithMemory #636
1 parent 719a560 commit a0b24ab

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

tests/gtest_sequence.cpp

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
#include <gtest/gtest.h>
1414
#include "action_test_node.h"
1515
#include "condition_test_node.h"
16-
#include "behaviortree_cpp/behavior_tree.h"
16+
#include "behaviortree_cpp/bt_factory.h"
17+
#include "test_helper.hpp"
1718

1819
using BT::NodeStatus;
1920
using std::chrono::milliseconds;
@@ -388,3 +389,44 @@ TEST_F(ComplexSequenceWithMemoryTest, Conditions1ToFalse)
388389
ASSERT_EQ(NodeStatus::IDLE, action_2.status());
389390
}
390391

392+
393+
TEST(SequenceWithMemoryTest, Issue_636)
394+
{
395+
static const char* xml_text = R"(
396+
397+
<root BTCPP_format="4" main_tree_to_execute="MainTree" >
398+
399+
<BehaviorTree ID="MainTree">
400+
<SequenceWithMemory>
401+
<Script code = " var := 0 " />
402+
<TestA/>
403+
<ScriptCondition code = "var+=1; var >= 5" />
404+
<TestB/>
405+
<TestC/>
406+
</SequenceWithMemory>
407+
</BehaviorTree>
408+
</root> )";
409+
410+
BT::BehaviorTreeFactory factory;
411+
412+
std::array<int, 3> counters;
413+
RegisterTestTick(factory, "Test", counters);
414+
415+
auto tree = factory.createTreeFromText(xml_text);
416+
417+
auto res = tree.tickOnce();
418+
int tick_count = 1;
419+
420+
while(res != BT::NodeStatus::SUCCESS)
421+
{
422+
res = tree.tickOnce();
423+
tick_count++;
424+
}
425+
426+
ASSERT_EQ(1, counters[0]);
427+
ASSERT_EQ(1, counters[1]);
428+
ASSERT_EQ(1, counters[2]);
429+
430+
ASSERT_EQ(5, tick_count);
431+
}
432+

0 commit comments

Comments
 (0)