30 #include <boost/thread.hpp> 31 #include <boost/bind.hpp> 39 #include "gtest/gtest.h" 43 const char LIBRARY_1[] =
"libclass_loader_TestPlugins1.so";
44 const char LIBRARY_2[] =
"libclass_loader_TestPlugins2.so";
47 TEST(ClassLoaderTest, basicLoad) {
52 FAIL() <<
"ClassLoaderException: " << e.what() <<
"\n";
59 TEST(ClassLoaderTest, correctNonLazyLoadUnload) {
70 FAIL() <<
"ClassLoaderException: " << e.what() <<
"\n";
72 FAIL() <<
"Unhandled exception";
77 TEST(ClassLoaderTest, correctLazyLoadUnload) {
94 FAIL() <<
"ClassLoaderException: " << e.what() <<
"\n";
96 FAIL() <<
"Unhandled exception";
102 TEST(ClassLoaderTest, nonExistentPlugin) {
108 FAIL() <<
"Null object being returned instead of exception thrown.";
116 FAIL() <<
"Unknown exception caught.\n";
119 FAIL() <<
"Did not throw exception as expected.\n";
123 TEST(ClassLoaderTest, nonExistentLibrary) {
130 FAIL() <<
"Unknown exception caught.\n";
133 FAIL() <<
"Did not throw exception as expected.\n";
142 TEST(ClassLoaderTest, invalidBase) {
146 FAIL() <<
"Cat should not be available for InvalidBase";
151 FAIL() <<
"Class not available for correct base class.";
154 FAIL() <<
"Unexpected exception";
156 FAIL() <<
"Unexpected and unknown exception caught.\n";
164 boost::this_thread::sleep(boost::posix_time::seconds(seconds));
170 for (
unsigned int c = 0; c < classes.size(); c++) {
175 TEST(ClassLoaderTest, threadSafety) {
183 std::vector<boost::thread *> client_threads;
185 for (
unsigned int c = 0; c < 1000; c++) {
186 client_threads.push_back(
new boost::thread(boost::bind(&
run, &loader1)));
189 for (
unsigned int c = 0; c < client_threads.size(); c++) {
190 client_threads.at(c)->join();
193 for (
unsigned int c = 0; c < client_threads.size(); c++) {
194 delete (client_threads.at(c));
200 FAIL() <<
"Unexpected ClassLoaderException.";
202 FAIL() <<
"Unknown exception.";
208 TEST(ClassLoaderTest, loadRefCountingNonLazy) {
234 FAIL() <<
"Unexpected exception.\n";
236 FAIL() <<
"Unknown exception caught.\n";
239 FAIL() <<
"Did not throw exception as expected.\n";
244 TEST(ClassLoaderTest, loadRefCountingLazy) {
276 FAIL() <<
"Unexpected exception.\n";
278 FAIL() <<
"Unknown exception caught.\n";
281 FAIL() <<
"Did not throw exception as expected.\n";
293 for (
int i = 0; i < 2; ++i) {
299 FAIL() <<
"ClassLoaderException: " << e.what() <<
"\n";
305 TEST(MultiClassLoaderTest, lazyLoad) {
308 TEST(MultiClassLoaderTest, lazyLoadSecondTime) {
311 TEST(MultiClassLoaderTest, nonLazyLoad) {
314 TEST(MultiClassLoaderTest, noWarningOnLazyLoad) {
316 boost::shared_ptr<Base> cat, dog, rob;
330 FAIL() <<
"ClassLoaderException: " << e.what() <<
"\n";
339 int main(
int argc,
char ** argv)
341 testing::InitGoogleTest(&argc, argv);
342 return RUN_ALL_TESTS();
std::vector< std::string > getAvailableClasses()
Indicates which classes (i.e. class_loader) that can be loaded by this object.
An exception class thrown when class_loader is unable to load a runtime library.
A ClassLoader that can bind more than one runtime library.
bool isLibraryLoaded()
Indicates if a library is loaded within the scope of this ClassLoader. Note that the library may alre...
void testMultiClassLoader(bool lazy)
An exception class thrown when class_loader is unable to create a plugin.
This class allows loading and unloading of dynamically linked libraries which contain class definitio...
virtual void saySomething()=0
void loadLibrary(const std::string &library_path)
Loads a library into memory for this class loader.
int main(int argc, char **argv)
bool isClassAvailable(const std::string &class_name)
Indicates if a plugin class is available.
int unloadLibrary()
Attempts to unload a library loaded within scope of the ClassLoader. If the library is not opened...
void run(class_loader::ClassLoader *loader)
boost::shared_ptr< Base > createInstance(const std::string &derived_class_name)
Generates an instance of loadable classes (i.e. class_loader).
bool isLibraryLoadedByAnybody(const std::string &library_path)
Indicates if passed library has been loaded by ANY ClassLoader.
void loadLibrary()
Attempts to load a library on behalf of the ClassLoader. If the library is already opened...
boost::shared_ptr< Base > createInstance(const std::string &class_name)
Creates an instance of an object of given class name with ancestor class Base This version does not l...
TEST(ClassLoaderTest, basicLoad)