gtest_updates.cpp
Go to the documentation of this file.
1 #include <gtest/gtest.h>
2 #include <string>
5 #include "test_helper.hpp"
6 
7 using namespace BT;
8 
9 const std::string xml_text_check = R"(
10 
11  <root BTCPP_format="4" >
12  <BehaviorTree ID="Check">
13  <Sequence>
14 
15  <Fallback>
16  <WasEntryUpdated entry="A"/>
17  <TestA/>
18  </Fallback>
19 
20  <SkipUnlessUpdated entry="A">
21  <TestB/>
22  </SkipUnlessUpdated>
23 
24  </Sequence>
25  </BehaviorTree>
26  </root>)";
27 
28 TEST(EntryUpdates, NoEntry)
29 {
30  BehaviorTreeFactory factory;
31  std::array<int, 2> counters;
32  RegisterTestTick(factory, "Test", counters);
33 
34  const std::string xml_text = R"(
35  <root BTCPP_format="4" >
36  <BehaviorTree ID="Main">
37  <Sequence>
38  <SubTree ID="Check" _autoremap="true"/>
39  </Sequence>
40  </BehaviorTree>
41  </root>)";
42 
45  auto tree = factory.createTree("Main");
46  const auto status = tree.tickWhileRunning();
47  ASSERT_EQ(status, NodeStatus::SUCCESS);
48  EXPECT_EQ(1, counters[0]); // fallback!
49  EXPECT_EQ(0, counters[1]); // skipped
50 }
51 
52 TEST(EntryUpdates, Initialized)
53 {
54  BehaviorTreeFactory factory;
55  std::array<int, 2> counters;
56  RegisterTestTick(factory, "Test", counters);
57 
58  const std::string xml_text = R"(
59  <root BTCPP_format="4" >
60  <BehaviorTree ID="Main">
61  <Sequence>
62  <Script code="A:=1;B:=1"/>
63  <SubTree ID="Check" _autoremap="true"/>
64  </Sequence>
65  </BehaviorTree>
66  </root>)";
67 
70  auto tree = factory.createTree("Main");
71  const auto status = tree.tickWhileRunning();
72  ASSERT_EQ(status, NodeStatus::SUCCESS);
73  EXPECT_EQ(0, counters[0]); // fallback!
74  EXPECT_EQ(1, counters[1]); // skipped
75 }
76 
77 TEST(EntryUpdates, UpdateOnce)
78 {
79  BehaviorTreeFactory factory;
80  std::array<int, 2> counters;
81  RegisterTestTick(factory, "Test", counters);
82 
83  const std::string xml_text = R"(
84  <root BTCPP_format="4" >
85  <BehaviorTree ID="Main">
86  <Sequence>
87  <Script code="A:=1"/>
88  <Repeat num_cycles="2" >
89  <SubTree ID="Check" _autoremap="true"/>
90  </Repeat>
91  </Sequence>
92  </BehaviorTree>
93  </root>)";
94 
97  auto tree = factory.createTree("Main");
98  const auto status = tree.tickWhileRunning();
99  ASSERT_EQ(status, NodeStatus::SUCCESS);
100  EXPECT_EQ(1, counters[0]); // fallback!
101  EXPECT_EQ(1, counters[1]); // skipped
102 }
103 
104 TEST(EntryUpdates, UpdateTwice)
105 {
106  BehaviorTreeFactory factory;
107  std::array<int, 2> counters;
108  RegisterTestTick(factory, "Test", counters);
109 
110  const std::string xml_text = R"(
111  <root BTCPP_format="4" >
112  <BehaviorTree ID="Main">
113  <Repeat num_cycles="2" >
114  <Sequence>
115  <Script code="A:=1"/>
116  <SubTree ID="Check" _autoremap="true"/>
117  </Sequence>
118  </Repeat>
119  </BehaviorTree>
120  </root>)";
121 
124  auto tree = factory.createTree("Main");
125  const auto status = tree.tickWhileRunning();
126  ASSERT_EQ(status, NodeStatus::SUCCESS);
127  EXPECT_EQ(0, counters[0]); // fallback!
128  EXPECT_EQ(2, counters[1]); // skipped
129 }
BT
Definition: ex01_wrap_legacy.cpp:29
BT::BehaviorTreeFactory::createTree
Tree createTree(const std::string &tree_name, Blackboard::Ptr blackboard=Blackboard::create())
Definition: bt_factory.cpp:432
basic_types.h
RegisterTestTick
void RegisterTestTick(BT::BehaviorTreeFactory &factory, const std::string &name_prefix, std::array< int, N > &tick_counters)
Definition: test_helper.hpp:15
bt_factory.h
xml_text_check
const std::string xml_text_check
Definition: gtest_updates.cpp:9
test_helper.hpp
TEST
TEST(EntryUpdates, NoEntry)
Definition: gtest_updates.cpp:28
BT::Tree::tickWhileRunning
NodeStatus tickWhileRunning(std::chrono::milliseconds sleep_time=std::chrono::milliseconds(10))
Definition: bt_factory.cpp:609
BT::BehaviorTreeFactory
The BehaviorTreeFactory is used to create instances of a TreeNode at run-time.
Definition: bt_factory.h:205
BT::NodeStatus::SUCCESS
@ SUCCESS
BT::BehaviorTreeFactory::registerBehaviorTreeFromText
void registerBehaviorTreeFromText(const std::string &xml_text)
Definition: bt_factory.cpp:277
xml_text
static const char * xml_text
Definition: ex01_wrap_legacy.cpp:52


behaviortree_cpp_v4
Author(s): Davide Faconti
autogenerated on Fri Jun 28 2024 02:20:07