Go to the documentation of this file.00001 #include <pluginlib/class_loader.h>
00002 #include "test_base.h"
00003 #include <gtest/gtest.h>
00004
00005 TEST(PluginlibUniquePtrTest, unknownPlugin)
00006 {
00007 pluginlib::ClassLoader<test_base::Fubar> test_loader("pluginlib", "test_base::Fubar");
00008 ASSERT_THROW(test_loader.createUniqueInstance("pluginlib/foobar"), pluginlib::LibraryLoadException);
00009 }
00010
00011
00012 TEST(PluginlibUniquePtrTest, misspelledPlugin)
00013 {
00014 pluginlib::ClassLoader<test_base::Fubar> bad_test_loader("pluginlib", "test_base::Fuba");
00015 ASSERT_THROW(bad_test_loader.createUniqueInstance("pluginlib/foo"), pluginlib::LibraryLoadException);
00016 }
00017
00018 TEST(PluginlibTest, brokenPlugin)
00019 {
00020 pluginlib::ClassLoader<test_base::Fubar> test_loader("pluginlib", "test_base::Fubar");
00021 ASSERT_THROW(test_loader.createUniqueInstance("pluginlib/none"), pluginlib::PluginlibException);
00022 }
00023
00024 TEST(PluginlibUniquePtrTest, workingPlugin)
00025 {
00026 pluginlib::ClassLoader<test_base::Fubar> test_loader("pluginlib", "test_base::Fubar");
00027
00028 try
00029 {
00030 pluginlib::UniquePtr<test_base::Fubar> foo = test_loader.createUniqueInstance("pluginlib/foo");
00031 foo->initialize(10.0);
00032 EXPECT_EQ(foo->result(),100.0);
00033 }
00034 catch(pluginlib::PluginlibException& ex)
00035 {
00036 FAIL() << "Throwing exception: " << ex.what();
00037 return;
00038 }
00039 catch(...)
00040 {
00041 FAIL() << "Uncaught exception";
00042 }
00043 }
00044
00045 TEST(PluginlibUniquePtrTest, createUniqueInstanceAndUnloadLibrary)
00046 {
00047 ROS_INFO( "Making the ClassLoader..." );
00048 pluginlib::ClassLoader<test_base::Fubar> pl("pluginlib", "test_base::Fubar");
00049
00050 ROS_INFO( "Instantiating plugin..." );
00051 {
00052 pluginlib::UniquePtr<test_base::Fubar> inst = pl.createUniqueInstance("pluginlib/foo");
00053 }
00054
00055 ROS_INFO( "Checking if plugin is loaded with isClassLoaded..." );
00056 if( pl.isClassLoaded( "pluginlib/foo" ) )
00057 ROS_INFO( "Class is loaded" );
00058 else
00059 {
00060 FAIL() << "Library containing class should be loaded but isn't.";
00061 }
00062
00063 ROS_INFO( "Trying to unload class with unloadLibraryForClass..." );
00064 try
00065 {
00066 pl.unloadLibraryForClass("pluginlib/foo");
00067 }
00068 catch(pluginlib::PluginlibException& e)
00069 {
00070 FAIL() << "Could not unload library when I should be able to.";
00071 }
00072 ROS_INFO( "Done." );
00073 }
00074
00075
00076 int main(int argc, char **argv){
00077 testing::InitGoogleTest(&argc, argv);
00078 return RUN_ALL_TESTS();
00079 }
00080
00081