|
| 1 | +// Copyright 2020 Open Source Robotics Foundation, Inc. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +#include <gtest/gtest.h> |
| 16 | +#include <memory> |
| 17 | +#include <string> |
| 18 | +#include <utility> |
| 19 | +#include <vector> |
| 20 | + |
| 21 | +#include "controller_manager/controller_manager.hpp" |
| 22 | +#include "controller_manager_test_common.hpp" |
| 23 | + |
| 24 | +#include "ros2_control_test_assets/descriptions.hpp" |
| 25 | + |
| 26 | +class TestControllerManagerWithTestableCM; |
| 27 | + |
| 28 | +class TestableControllerManager : public controller_manager::ControllerManager |
| 29 | +{ |
| 30 | + friend TestControllerManagerWithTestableCM; |
| 31 | + |
| 32 | + FRIEND_TEST(TestControllerManagerWithTestableCM, initial_no_load_urdf_called); |
| 33 | + FRIEND_TEST(TestControllerManagerWithTestableCM, load_urdf_called_after_callback); |
| 34 | + FRIEND_TEST(TestControllerManagerWithTestableCM, load_urdf_called_after_invalid_urdf_passed); |
| 35 | + FRIEND_TEST(TestControllerManagerWithTestableCM, load_urdf_called_after_callback); |
| 36 | + FRIEND_TEST(TestControllerManagerWithTestableCM, load_urdf_called_after_callback); |
| 37 | + |
| 38 | +public: |
| 39 | + TestableControllerManager( |
| 40 | + std::unique_ptr<hardware_interface::ResourceManager> resource_manager, |
| 41 | + std::shared_ptr<rclcpp::Executor> executor, |
| 42 | + const std::string & manager_node_name = "controller_manager", |
| 43 | + const std::string & namespace_ = "") |
| 44 | + : controller_manager::ControllerManager( |
| 45 | + std::move(resource_manager), executor, manager_node_name, namespace_) |
| 46 | + { |
| 47 | + } |
| 48 | +}; |
| 49 | + |
| 50 | +class TestControllerManagerWithTestableCM |
| 51 | +: public ControllerManagerFixture<TestableControllerManager>, |
| 52 | + public testing::WithParamInterface<Strictness> |
| 53 | +{ |
| 54 | +public: |
| 55 | + // create cm with no urdf |
| 56 | + TestControllerManagerWithTestableCM() |
| 57 | + : ControllerManagerFixture<TestableControllerManager>("", false) |
| 58 | + { |
| 59 | + } |
| 60 | +}; |
| 61 | + |
| 62 | +TEST_P(TestControllerManagerWithTestableCM, initial_no_load_urdf_called) |
| 63 | +{ |
| 64 | + ASSERT_FALSE(cm_->resource_manager_->is_urdf_already_loaded()); |
| 65 | +} |
| 66 | + |
| 67 | +TEST_P(TestControllerManagerWithTestableCM, load_urdf_called_after_callback) |
| 68 | +{ |
| 69 | + ASSERT_FALSE(cm_->resource_manager_->is_urdf_already_loaded()); |
| 70 | + // mimic callback |
| 71 | + auto msg = std_msgs::msg::String(); |
| 72 | + msg.data = ros2_control_test_assets::minimal_robot_urdf; |
| 73 | + cm_->robot_description_callback(msg); |
| 74 | + ASSERT_TRUE(cm_->resource_manager_->is_urdf_already_loaded()); |
| 75 | +} |
| 76 | + |
| 77 | +TEST_P(TestControllerManagerWithTestableCM, load_urdf_called_after_invalid_urdf_passed) |
| 78 | +{ |
| 79 | + ASSERT_FALSE(cm_->resource_manager_->is_urdf_already_loaded()); |
| 80 | + // mimic callback |
| 81 | + auto msg = std_msgs::msg::String(); |
| 82 | + msg.data = ros2_control_test_assets::minimal_robot_missing_command_keys_urdf; |
| 83 | + cm_->robot_description_callback(msg); |
| 84 | + ASSERT_TRUE(cm_->resource_manager_->is_urdf_already_loaded()); |
| 85 | +} |
| 86 | + |
| 87 | +INSTANTIATE_TEST_SUITE_P( |
| 88 | + test_best_effort, TestControllerManagerWithTestableCM, testing::Values(best_effort)); |
0 commit comments