gtest_tree.cpp
Go to the documentation of this file.
00001 /* Copyright (C) 2015-2017 Michele Colledanchise - All Rights Reserved
00002 *
00003 *   Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
00004 *   to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
00005 *   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:
00006 *   The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
00007 *
00008 *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00009 *   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,
00010 *   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.
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 /****************TESTS START HERE***************************/
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 }


behaviortree_cpp
Author(s): Michele Colledanchise, Davide Faconti
autogenerated on Sat Feb 2 2019 03:50:10