gtest_tree.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2015-2017 Michele Colledanchise - All Rights Reserved
2 *
3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
4 * to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
5 * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
9 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
10 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
11 */
12 
13 #include <gtest/gtest.h>
14 #include "action_test_node.h"
15 #include "condition_test_node.h"
17 
18 using BT::NodeStatus;
19 using std::chrono::milliseconds;
20 
21 struct BehaviorTreeTest : testing::Test
22 {
27 
29 
31  : root("root_sequence")
32  , action_1("action_1", milliseconds(100) )
33  , condition_1("condition_1")
34  , condition_2("condition_2")
35  , fal_conditions("fallback_conditions")
36  {
37  root.addChild(&fal_conditions);
38  {
39  fal_conditions.addChild(&condition_1);
40  fal_conditions.addChild(&condition_2);
41  }
42  root.addChild(&action_1);
43  }
45  {
46  haltAllActions(&root);
47  }
48 };
49 
50 /****************TESTS START HERE***************************/
51 
52 TEST_F(BehaviorTreeTest, Condition1ToFalseCondition2True)
53 {
54  condition_1.setBoolean(false);
55  condition_2.setBoolean(true);
56 
58 
59  ASSERT_EQ(NodeStatus::RUNNING, state);
60  ASSERT_EQ(NodeStatus::SUCCESS, fal_conditions.status());
61  ASSERT_EQ(NodeStatus::IDLE, condition_1.status());
62  ASSERT_EQ(NodeStatus::IDLE, condition_2.status());
63  ASSERT_EQ(NodeStatus::RUNNING, action_1.status());
64 }
65 
66 TEST_F(BehaviorTreeTest, Condition2ToFalseCondition1True)
67 {
68  condition_2.setBoolean(false);
69  condition_1.setBoolean(true);
70 
72 
73  ASSERT_EQ(NodeStatus::RUNNING, state);
74  ASSERT_EQ(NodeStatus::SUCCESS, fal_conditions.status());
75  ASSERT_EQ(NodeStatus::IDLE, condition_1.status());
76  ASSERT_EQ(NodeStatus::IDLE, condition_2.status());
77  ASSERT_EQ(NodeStatus::RUNNING, action_1.status());
78 }
79 
80 int main(int argc, char** argv)
81 {
82  testing::InitGoogleTest(&argc, argv);
83  return RUN_ALL_TESTS();
84 }
BT::ConditionTestNode condition_2
Definition: gtest_tree.cpp:26
BT::ConditionTestNode condition_1
Definition: gtest_tree.cpp:25
BT::FallbackNode fal_conditions
Definition: gtest_tree.cpp:28
void setBoolean(bool boolean_value)
void haltAllActions(TreeNode *root_node)
int main(int argc, char **argv)
Definition: gtest_tree.cpp:80
void addChild(TreeNode *child)
The method used to add nodes to the children vector.
NodeStatus status() const
Definition: tree_node.cpp:56
NodeStatus
Definition: basic_types.h:35
BT::SequenceNode root
Definition: gtest_tree.cpp:23
virtual BT::NodeStatus executeTick()
The method that should be used to invoke tick() and setStatus();.
Definition: tree_node.cpp:33
The FallbackNode is used to try different strategies, until one succeeds. If any child returns RUNNIN...
Definition: fallback_node.h:33
The SequenceNode is used to tick children in an ordered sequence. If any child returns RUNNING...
Definition: sequence_node.h:34
TEST_F(BehaviorTreeTest, Condition1ToFalseCondition2True)
Definition: gtest_tree.cpp:52
BT::AsyncActionTest action_1
Definition: gtest_tree.cpp:24


behaviortree_cpp
Author(s): Michele Colledanchise, Davide Faconti
autogenerated on Sat Jun 8 2019 18:04:05