|
13 | 13 | #include <gtest/gtest.h>
|
14 | 14 | #include "action_test_node.h"
|
15 | 15 | #include "condition_test_node.h"
|
16 |
| -#include "behaviortree_cpp/behavior_tree.h" |
| 16 | +#include "behaviortree_cpp/bt_factory.h" |
| 17 | +#include "test_helper.hpp" |
17 | 18 |
|
18 | 19 | using BT::NodeStatus;
|
19 | 20 | using std::chrono::milliseconds;
|
@@ -388,3 +389,44 @@ TEST_F(ComplexSequenceWithMemoryTest, Conditions1ToFalse)
|
388 | 389 | ASSERT_EQ(NodeStatus::IDLE, action_2.status());
|
389 | 390 | }
|
390 | 391 |
|
| 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