Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testing #1

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions battery_state_broadcaster/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,35 @@ ament_target_dependencies(battery_state_broadcaster PUBLIC ${THIS_PACKAGE_INCLUD

pluginlib_export_plugin_description_file(controller_interface battery_state_broadcaster.xml)

if(BUILD_TESTING)
find_package(ament_cmake_gmock REQUIRED)
find_package(controller_manager REQUIRED)
find_package(hardware_interface REQUIRED)
find_package(ros2_control_test_assets REQUIRED)

ament_add_gmock(test_load_battery_state_broadcaster
test/test_load_battery_state_broadcaster.cpp)
target_include_directories(test_load_battery_state_broadcaster PRIVATE include)
target_link_libraries(test_load_battery_state_broadcaster
battery_state_broadcaster
)
ament_target_dependencies(test_load_battery_state_broadcaster
controller_manager
hardware_interface
ros2_control_test_assets
)

#[[ament_add_gmock(test_battery_state_broadcaster
test/test_battery_state_broadcaster.cpp)
target_include_directories(test_battery_state_broadcaster PRIVATE include)
target_link_libraries(test_battery_state_broadcaster
battery_state_broadcaster
)
ament_target_dependencies(test_battery_state_broadcaster
hardware_interface
)]]#
endif()

install(
DIRECTORY include/
DESTINATION include/battery_state_broadcaster
Expand Down
7 changes: 6 additions & 1 deletion battery_state_broadcaster/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
<depend>realtime_tools</depend>
<depend>sensor_msgs</depend>

<test_depend>ament_cmake_gmock</test_depend>
<test_depend>controller_manager</test_depend>
<test_depend>hardware_interface_testing</test_depend>
<test_depend>ros2_control_test_assets</test_depend>

<export>
<build_type>ament_cmake</build_type>
</export>
</package>
</package>
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <gmock/gmock.h>
#include <memory>

#include "controller_manager/controller_manager.hpp"
#include "hardware_interface/resource_manager.hpp"
#include "rclcpp/executor.hpp"
#include "rclcpp/executors/single_threaded_executor.hpp"
#include "rclcpp/utilities.hpp"
#include "ros2_control_test_assets/descriptions.hpp"

TEST(TestLoadBatteryStateBroadcaster, load_controller)
{
std::shared_ptr<rclcpp::Executor> executor = std::make_shared<rclcpp::executors::SingleThreadedExecutor>();

controller_manager::ControllerManager cm(
std::make_unique<hardware_interface::ResourceManager>(ros2_control_test_assets::minimal_robot_urdf),
executor,
"test_controller_manager");

ASSERT_NE(cm.load_controller("test_battery_state_broadcaster", "battery_state_broadcaster/BatteryStateBroadcaster"),
nullptr);
}

int main(int argc, char** argv)
{
::testing::InitGoogleMock(&argc, argv);
rclcpp::init(argc, argv);
int result = RUN_ALL_TESTS();
rclcpp::shutdown();
return result;
}