gtest_blackboard.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2018 Davide Faconti - 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"
18 
19 using namespace BT;
20 
22 {
23  public:
24  InitTestNode(bool try_to_access_bb, const std::string& name):
25  SyncActionNode(name),
26  _value(0)
27  {
28  if( try_to_access_bb )
29  {
30  // this should throw
31  blackboard()->set(KEY(), 33);
32  }
33  }
34 
35  void onInit() {
36  blackboard()->get(KEY(), _value);
37  }
38 
40  {
41  _value *= 2;
42  blackboard()->set(KEY(), _value);
43  return NodeStatus::SUCCESS;
44  }
45 
46  static const char* KEY() { return "my_entry"; }
47 
48  private:
49  int _value;
50 };
51 
52 
53 
54 
55 /****************TESTS START HERE***************************/
56 
57 TEST(BlackboardTest, CheckOInit)
58 {
59  auto bb = Blackboard::create<BlackboardLocal>();
60  const auto KEY = InitTestNode::KEY();
61 
62  EXPECT_THROW( InitTestNode(true,"init_test"), std::logic_error );
63 
64  InitTestNode node(false,"init_test");
65  node.setBlackboard(bb);
66 
67  bb->set(KEY, 11 );
68 
69  // this should read and write "my_entry", respectively in onInit() and tick()
70  node.executeTick();
71 
72  ASSERT_EQ( bb->get<int>(KEY), 22 );
73 
74  // check that onInit is executed only once
75  bb->set(KEY, 1 );
76 
77  // since this value is read in OnInit(), the node will not notice the change in bb
79  node.executeTick();
80  ASSERT_EQ( bb->get<int>(KEY), 44 );
81 }
TEST(BlackboardTest, CheckOInit)
NodeStatus tick()
Method to be implemented by the user.
The SyncActionNode is an helper derived class that explicitly forbids the status RUNNING and doesn&#39;t ...
Definition: action_node.h:50
static const char * KEY()
virtual NodeStatus executeTick() override
The method that will be executed to invoke tick(); and setStatus();.
InitTestNode(bool try_to_access_bb, const std::string &name)
NodeStatus
Definition: basic_types.h:28
void setBlackboard(const Blackboard::Ptr &bb)
Definition: tree_node.cpp:59
void setStatus(NodeStatus new_status)
Definition: tree_node.cpp:43


behaviortree_cpp
Author(s): Michele Colledanchise, Davide Faconti
autogenerated on Sat Feb 2 2019 04:01:53