utest.cpp
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(PluginlibTest, unknownPlugin)
00006 {
00007   pluginlib::ClassLoader<test_base::Fubar> test_loader("pluginlib", "test_base::Fubar");
00008   ASSERT_THROW(test_loader.createInstance("pluginlib/foobar"), pluginlib::LibraryLoadException);
00009 }
00010 
00011 TEST(PluginlibTest, misspelledPlugin)
00012 {
00013   pluginlib::ClassLoader<test_base::Fubar> bad_test_loader("pluginlib", "test_base::Fuba");
00014   ASSERT_THROW(bad_test_loader.createInstance("pluginlib/foo"), pluginlib::LibraryLoadException);
00015 }
00016 
00017 TEST(PluginlibTest, invalidPackage)
00018 {
00019   ASSERT_THROW(pluginlib::ClassLoader<test_base::Fubar>("pluginlib_bad", "test_base::Fubar"), pluginlib::ClassLoaderException);
00020 }
00021 
00022 TEST(PluginlibTest, brokenPlugin)
00023 {
00024   pluginlib::ClassLoader<test_base::Fubar> test_loader("pluginlib", "test_base::Fubar");
00025   ASSERT_THROW(test_loader.createInstance("pluginlib/none"), pluginlib::PluginlibException);
00026 }
00027 
00028 TEST(PluginlibTest, workingPlugin)
00029 {
00030   pluginlib::ClassLoader<test_base::Fubar> test_loader("pluginlib", "test_base::Fubar");
00031 
00032   try
00033   {
00034     boost::shared_ptr<test_base::Fubar> foo = test_loader.createInstance("pluginlib/foo");
00035     foo->initialize(10.0);
00036     EXPECT_EQ(foo->result(),100.0);
00037   }
00038   catch(pluginlib::PluginlibException& ex)
00039   {
00040     FAIL() << "Throwing exception: " << ex.what();
00041     return;
00042   }
00043   catch(...)
00044   {
00045     FAIL() << "Uncaught exception";
00046   }
00047 }
00048 
00049 TEST(PluginlibTest, createUnmanagedInstanceAndUnloadLibrary)
00050 {
00051   ROS_INFO( "Making the ClassLoader..." );
00052   pluginlib::ClassLoader<test_base::Fubar> pl("pluginlib", "test_base::Fubar");
00053 
00054   ROS_INFO( "Instantiating plugin..." );
00055   test_base::Fubar *inst = pl.createUnmanagedInstance("pluginlib/foo");
00056 
00057   ROS_INFO( "Deleting plugin..." );
00058   delete inst;
00059 
00060   ROS_INFO( "Checking if plugin is loaded with isClassLoaded..." );
00061   if( pl.isClassLoaded( "pluginlib/foo" ) )
00062     ROS_INFO( "Class is loaded" );
00063   else
00064   {
00065     FAIL() <<  "Library containing class should be loaded but isn't.";
00066   }
00067   ROS_INFO( "Trying to unload class with unloadLibraryForClass..." );
00068   try
00069   {
00070     pl.unloadLibraryForClass("pluginlib/foo");
00071   }
00072   catch(pluginlib::PluginlibException& e)
00073   {
00074     FAIL() << "Could not unload library when I should be able to.";
00075   }
00076   ROS_INFO( "Done." );
00077 }
00078 
00079 TEST(PluginlibTest, createManagedInstanceAndUnloadLibrary)
00080 {
00081   ROS_INFO( "Making the ClassLoader..." );
00082   pluginlib::ClassLoader<test_base::Fubar> pl("pluginlib", "test_base::Fubar");
00083 
00084   ROS_INFO( "Instantiating plugin..." );
00085   {
00086     boost::shared_ptr<test_base::Fubar> inst = pl.createInstance("pluginlib/foo");
00087   }
00088 
00089   ROS_INFO( "Checking if plugin is loaded with isClassLoaded..." );
00090   if( pl.isClassLoaded( "pluginlib/foo" ) )
00091     ROS_INFO( "Class is loaded" );
00092   else
00093   {
00094     FAIL() <<  "Library containing class should be loaded but isn't.";
00095   }
00096 
00097   ROS_INFO( "Trying to unload class with unloadLibraryForClass..." );
00098   try
00099   {
00100     pl.unloadLibraryForClass("pluginlib/foo");
00101   }
00102   catch(pluginlib::PluginlibException& e)
00103   {
00104     FAIL() << "Could not unload library when I should be able to.";
00105   }
00106   ROS_INFO( "Done." );
00107 }
00108 
00109 TEST(PluginlibTest, brokenXML)
00110 {
00111   try
00112   {
00113     pluginlib::ClassLoader<test_base::Fubar> test_loader("pluginlib", "test_base::Fubar", "plugin_test");
00114   }
00115   catch(pluginlib::ClassLoaderException& ex)
00116   {
00117     SUCCEED();
00118     return;
00119   }
00120 
00121   ADD_FAILURE() << "Didn't throw exception as expected";
00122 }
00123 
00124 // Run all the tests that were declared with TEST()
00125 int main(int argc, char **argv){
00126   testing::InitGoogleTest(&argc, argv);
00127   return RUN_ALL_TESTS();
00128 }
00129 
00130 


pluginlib
Author(s): Eitan Marder-Eppstein, Tully Foote, Dirk Thomas, Mirza Shah
autogenerated on Thu Jul 27 2017 02:19:34