Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include <gtest/gtest.h>
00014 #include "action_test_node.h"
00015 #include "condition_test_node.h"
00016 #include "behaviortree_cpp/behavior_tree.h"
00017
00018 using BT::NodeStatus;
00019
00020 struct BehaviorTreeTest : testing::Test
00021 {
00022 BT::SequenceNode root;
00023 BT::AsyncActionTest action_1;
00024 BT::ConditionTestNode condition_1;
00025 BT::ConditionTestNode condition_2;
00026
00027 BT::FallbackNode fal_conditions;
00028
00029 BehaviorTreeTest()
00030 : root("root_sequence")
00031 , action_1("action_1")
00032 , condition_1("condition_1")
00033 , condition_2("condition_2")
00034 , fal_conditions("fallback_conditions")
00035 {
00036 root.addChild(&fal_conditions);
00037 {
00038 fal_conditions.addChild(&condition_1);
00039 fal_conditions.addChild(&condition_2);
00040 }
00041 root.addChild(&action_1);
00042 }
00043 ~BehaviorTreeTest()
00044 {
00045 haltAllActions(&root);
00046 }
00047 };
00048
00049
00050
00051 TEST_F(BehaviorTreeTest, Condition1ToFalseCondition2True)
00052 {
00053 condition_1.setBoolean(false);
00054 condition_2.setBoolean(true);
00055
00056 BT::NodeStatus state = root.executeTick();
00057
00058 ASSERT_EQ(NodeStatus::RUNNING, state);
00059 ASSERT_EQ(NodeStatus::SUCCESS, fal_conditions.status());
00060 ASSERT_EQ(NodeStatus::IDLE, condition_1.status());
00061 ASSERT_EQ(NodeStatus::IDLE, condition_2.status());
00062 ASSERT_EQ(NodeStatus::RUNNING, action_1.status());
00063 }
00064
00065 TEST_F(BehaviorTreeTest, Condition2ToFalseCondition1True)
00066 {
00067 condition_2.setBoolean(false);
00068 condition_1.setBoolean(true);
00069
00070 BT::NodeStatus state = root.executeTick();
00071
00072 ASSERT_EQ(NodeStatus::RUNNING, state);
00073 ASSERT_EQ(NodeStatus::SUCCESS, fal_conditions.status());
00074 ASSERT_EQ(NodeStatus::IDLE, condition_1.status());
00075 ASSERT_EQ(NodeStatus::IDLE, condition_2.status());
00076 ASSERT_EQ(NodeStatus::RUNNING, action_1.status());
00077 }
00078
00079 int main(int argc, char** argv)
00080 {
00081 testing::InitGoogleTest(&argc, argv);
00082 return RUN_ALL_TESTS();
00083 }