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 test_base::Fubar* foo = NULL;
00009
00010 try
00011 {
00012 foo = test_loader.createClassInstance("pluginlib/foobar");
00013 foo->initialize(10.0);
00014 }
00015 catch(pluginlib::LibraryLoadException& ex)
00016 {
00017 SUCCEED();
00018 return;
00019 }
00020 catch(...)
00021 {
00022 FAIL() << "Uncaught exception";
00023 }
00024 ADD_FAILURE() << "Didn't throw exception as expected";
00025
00026 }
00027
00028
00029 TEST(PluginlibTest, misspelledPlugin)
00030 {
00031 pluginlib::ClassLoader<test_base::Fubar> bad_test_loader("pluginlib", "test_base::Fuba");
00032 test_base::Fubar* foo = NULL;
00033
00034 try
00035 {
00036 foo = bad_test_loader.createClassInstance("pluginlib/foo");
00037 foo->initialize(10.0);
00038 }
00039 catch(pluginlib::LibraryLoadException& ex)
00040 {
00041 SUCCEED();
00042 return;
00043 }
00044 catch(...)
00045 {
00046 FAIL() << "Uncaught exception";
00047 }
00048 ADD_FAILURE() << "Didn't throw exception as expected";
00049
00050 }
00051
00052 TEST(PluginlibTest, invalidPackage)
00053 {
00054 try
00055 {
00056 pluginlib::ClassLoader<test_base::Fubar> bad_test_loader("pluginlib_bad", "test_base::Fubar");
00057 }
00058 catch(pluginlib::LibraryLoadException& ex)
00059 {
00060 SUCCEED();
00061 return;
00062 }
00063 catch(...)
00064 {
00065 FAIL() << "Uncaught exception";
00066 }
00067 ADD_FAILURE() << "Didn't throw exception as expected";
00068
00069 }
00070
00071 TEST(PluginlibTest, brokenPlugin)
00072 {
00073 pluginlib::ClassLoader<test_base::Fubar> test_loader("pluginlib", "test_base::Fubar");
00074 test_base::Fubar* none = NULL;
00075
00076 try
00077 {
00078 none = test_loader.createClassInstance("pluginlib/none");
00079 none->initialize(10.0);
00080 }
00081 catch(pluginlib::PluginlibException& ex)
00082 {
00083 SUCCEED();
00084 return;
00085 }
00086 catch(...)
00087 {
00088 FAIL() << "Uncaught exception";
00089 }
00090 ADD_FAILURE() << "Didn't throw exception as expected";
00091
00092 }
00093
00094 TEST(PluginlibTest, workingPlugin)
00095 {
00096 pluginlib::ClassLoader<test_base::Fubar> test_loader("pluginlib", "test_base::Fubar");
00097 test_base::Fubar* foo = NULL;
00098
00099 try
00100 {
00101 foo = test_loader.createClassInstance("pluginlib/foo");
00102 foo->initialize(10.0);
00103 EXPECT_EQ(foo->result(),100.0);
00104
00105 }
00106 catch(pluginlib::PluginlibException& ex)
00107 {
00108 FAIL() << "Throwing exception";
00109 return;
00110 }
00111 catch(...)
00112 {
00113 FAIL() << "Uncaught exception";
00114 }
00115 }
00116
00117
00118 int main(int argc, char **argv){
00119 testing::InitGoogleTest(&argc, argv);
00120 return RUN_ALL_TESTS();
00121 }
00122
00123