@@ -302,6 +302,101 @@ TEST_F(ClearCostmapAroundRobotServiceTestFixture, test_tick)
302302 EXPECT_EQ (config_->blackboard ->get <int >(" number_recoveries" ), 1 );
303303}
304304
305+ class ClearCostmapAroundPoseService : public TestService <nav2_msgs::srv::ClearCostmapAroundPose>
306+ {
307+ public:
308+ ClearCostmapAroundPoseService ()
309+ : TestService(" clear_costmap_around_pose" )
310+ {}
311+ };
312+
313+ class ClearCostmapAroundPoseServiceTestFixture : public ::testing::Test
314+ {
315+ public:
316+ static void SetUpTestCase ()
317+ {
318+ node_ = std::make_shared<nav2::LifecycleNode>(" clear_costmap_around_pose_test_fixture" );
319+ factory_ = std::make_shared<BT::BehaviorTreeFactory>();
320+
321+ config_ = new BT::NodeConfiguration ();
322+
323+ // Create the blackboard that will be shared by all of the nodes in the tree
324+ config_->blackboard = BT::Blackboard::create ();
325+ // Put items on the blackboard
326+ config_->blackboard ->set (
327+ " node" ,
328+ node_);
329+ config_->blackboard ->set <std::chrono::milliseconds>(
330+ " server_timeout" ,
331+ std::chrono::milliseconds (10 ));
332+ config_->blackboard ->set <std::chrono::milliseconds>(
333+ " bt_loop_duration" ,
334+ std::chrono::milliseconds (10 ));
335+ config_->blackboard ->set <std::chrono::milliseconds>(
336+ " wait_for_service_timeout" ,
337+ std::chrono::milliseconds (1000 ));
338+ config_->blackboard ->set (" initial_pose_received" , false );
339+ config_->blackboard ->set (" number_recoveries" , 0 );
340+
341+ factory_->registerNodeType <nav2_behavior_tree::ClearCostmapAroundPoseService>(
342+ " ClearCostmapAroundPose" );
343+ }
344+
345+ static void TearDownTestCase ()
346+ {
347+ delete config_;
348+ config_ = nullptr ;
349+ node_.reset ();
350+ server_.reset ();
351+ factory_.reset ();
352+ }
353+
354+ void SetUp () override
355+ {
356+ config_->blackboard ->set (" number_recoveries" , 0 );
357+ }
358+
359+ void TearDown () override
360+ {
361+ tree_.reset ();
362+ }
363+
364+ static std::shared_ptr<ClearCostmapAroundPoseService> server_;
365+
366+ protected:
367+ static nav2::LifecycleNode::SharedPtr node_;
368+ static BT::NodeConfiguration * config_;
369+ static std::shared_ptr<BT::BehaviorTreeFactory> factory_;
370+ static std::shared_ptr<BT::Tree> tree_;
371+ };
372+
373+ nav2::LifecycleNode::SharedPtr
374+ ClearCostmapAroundPoseServiceTestFixture::node_ = nullptr ;
375+ std::shared_ptr<ClearCostmapAroundPoseService>
376+ ClearCostmapAroundPoseServiceTestFixture::server_ = nullptr ;
377+ BT::NodeConfiguration
378+ * ClearCostmapAroundPoseServiceTestFixture::config_ = nullptr ;
379+ std::shared_ptr<BT::BehaviorTreeFactory>
380+ ClearCostmapAroundPoseServiceTestFixture::factory_ = nullptr ;
381+ std::shared_ptr<BT::Tree>
382+ ClearCostmapAroundPoseServiceTestFixture::tree_ = nullptr ;
383+
384+ TEST_F (ClearCostmapAroundPoseServiceTestFixture, test_tick)
385+ {
386+ std::string xml_txt =
387+ R"(
388+ <root BTCPP_format="4">
389+ <BehaviorTree ID="MainTree">
390+ <ClearCostmapAroundPose service_name="clear_costmap_around_pose"/>
391+ </BehaviorTree>
392+ </root>)" ;
393+
394+ tree_ = std::make_shared<BT::Tree>(factory_->createTreeFromText (xml_txt, config_->blackboard ));
395+ EXPECT_EQ (config_->blackboard ->get <int >(" number_recoveries" ), 0 );
396+ EXPECT_EQ (tree_->rootNode ()->executeTick (), BT::NodeStatus::SUCCESS);
397+ EXPECT_EQ (config_->blackboard ->get <int >(" number_recoveries" ), 1 );
398+ }
399+
305400int main (int argc, char ** argv)
306401{
307402 ::testing::InitGoogleTest (&argc, argv);
@@ -327,13 +422,20 @@ int main(int argc, char ** argv)
327422 rclcpp::spin (ClearCostmapAroundRobotServiceTestFixture::server_);
328423 });
329424
425+ ClearCostmapAroundPoseServiceTestFixture::server_ =
426+ std::make_shared<ClearCostmapAroundPoseService>();
427+ std::thread server_thread_around_pose ([]() {
428+ rclcpp::spin (ClearCostmapAroundPoseServiceTestFixture::server_);
429+ });
430+
330431 int all_successful = RUN_ALL_TESTS ();
331432
332433 // shutdown ROS
333434 rclcpp::shutdown ();
334435 server_thread.join ();
335436 server_thread_except_region.join ();
336437 server_thread_around_robot.join ();
438+ server_thread_around_pose.join ();
337439
338440 return all_successful;
339441}
0 commit comments