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

Plugin Unit Test #16

Merged
merged 2 commits into from
Aug 10, 2020
Merged
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
10 changes: 10 additions & 0 deletions reach_core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,16 @@ add_dependencies(data_loader
${catkin_EXPORTED_TARGETS}
)

##########
## TEST ##
##########

if(CATKIN_ENABLE_TESTING)
find_package(rostest REQUIRED)
add_rostest_gtest(${PROJECT_NAME}_plugin_utest test/plugin.test test/plugin_utest.cpp)
target_link_libraries(${PROJECT_NAME}_plugin_utest ${PROJECT_NAME} ${catkin_LIBRARIES})
endif()

#############
## INSTALL ##
#############
Expand Down
1 change: 1 addition & 0 deletions reach_core/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<depend>tf2_ros</depend>
<depend>tf2_eigen</depend>
<depend>visualization_msgs</depend>
<test_depend>rosunit</test_depend>

<export>
<reach_core plugin="${prefix}/plugin_description.xml"/>
Expand Down
4 changes: 4 additions & 0 deletions reach_core/test/plugin.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0"?>
<launch>
<test test-name="plugin_utest" pkg="reach_core" type="reach_core_plugin_utest"/>
</launch>
76 changes: 76 additions & 0 deletions reach_core/test/plugin_utest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#include <gtest/gtest.h>
#include <pluginlib/class_loader.h>
#include <reach_core/plugins/evaluation_base.h>
#include <reach_core/plugins/ik_solver_base.h>
#include <reach_core/plugins/reach_display_base.h>
#include <ros/ros.h>

const static std::string EVAL_PLUGIN_BASE = "reach::plugins::EvaluationBase";
const static std::string IK_PLUGIN_BASE = "reach::plugins::IKSolverBase";
const static std::string DISPLAY_PLUGIN_BASE = "reach::plugins::DisplayBase";

template<typename PluginT>
class PluginTest : public ::testing::Test
{
public:
PluginTest()
: ::testing::Test()
, loader("reach_core", base_class_name)
{
}

static const std::string base_class_name;
static const unsigned expected_count;
pluginlib::ClassLoader<PluginT> loader;
};

// Evaluation plugins - 1 in reach_core, 3 in moveit_reach_plugins
template<>
const std::string PluginTest<reach::plugins::EvaluationBase>::base_class_name = EVAL_PLUGIN_BASE;

template<>
const unsigned PluginTest<reach::plugins::EvaluationBase>::expected_count = 4;

// IK Solver plugins - 0 in reach_core, 2 in moveit_reach_plugins
template<>
const std::string PluginTest<reach::plugins::IKSolverBase>::base_class_name = IK_PLUGIN_BASE;

template<>
const unsigned PluginTest<reach::plugins::IKSolverBase>::expected_count = 2;

// Display Plugins - 0 in reach_core, 1 in moveit_reach_plugins
template<>
const std::string PluginTest<reach::plugins::DisplayBase>::base_class_name = DISPLAY_PLUGIN_BASE;

template<>
const unsigned PluginTest<reach::plugins::DisplayBase>::expected_count = 1;

// Test Implementations
using Implementations = ::testing::
Types<reach::plugins::EvaluationBase, reach::plugins::IKSolverBase, reach::plugins::DisplayBase>;

TYPED_TEST_CASE(PluginTest, Implementations);

TYPED_TEST(PluginTest, LoadPlugins)
{
std::vector<std::string> declared_classes = this->loader.getDeclaredClasses();

// Expect the number of declared classes of this type to equal the amount in the map
EXPECT_EQ(declared_classes.size(), this->expected_count);

// Loop over the available classes and attempt to load them
for (const std::string &cls : declared_classes)
{
std::cout << "Attempting to load '" << cls << "' class" << std::endl;
boost::shared_ptr<TypeParam> plugin;
EXPECT_NO_THROW(plugin = this->loader.createInstance(cls));
EXPECT_NE(plugin, nullptr);
}
}

int main(int argc, char **argv)
{
::testing::InitGoogleTest(&argc, argv);
ros::init(argc, argv, "plugin_utest");
return RUN_ALL_TESTS();
}