Skip to content
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
4 changes: 4 additions & 0 deletions include/class_loader/multi_library_class_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ class MultiLibraryClassLoader
for(unsigned int c = 0; c < active_loaders.size(); c++)
{
ClassLoader* current = active_loaders.at(c);
if (!current->isLibraryLoaded())
current->loadLibrary();
if(current->isClassAvailable<Base>(class_name))
return(current->createInstance<Base>(class_name));
}
Expand Down Expand Up @@ -113,6 +115,8 @@ class MultiLibraryClassLoader
for(unsigned int c = 0; c < active_loaders.size(); c++)
{
ClassLoader* current = active_loaders.at(c);
if (!current->isLibraryLoaded())
current->loadLibrary();
if(current->isClassAvailable<Base>(class_name))
return(current->createUnmanagedInstance<Base>(class_name));
}
Expand Down
62 changes: 62 additions & 0 deletions test/utest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <boost/bind.hpp>
#include <iostream>
#include <class_loader/class_loader.h>
#include <class_loader/multi_library_class_loader.h>
#include "base.h"
#include <gtest/gtest.h>

Expand Down Expand Up @@ -297,8 +298,69 @@ TEST(ClassLoaderTest, loadRefCountingLazy)
FAIL() << "Did not throw exception as expected.\n";
}


/*****************************************************************************/

void testMultiClassLoader(bool lazy)
{
try
{
class_loader::MultiLibraryClassLoader loader(lazy);
loader.loadLibrary(LIBRARY_1);
loader.loadLibrary(LIBRARY_2);
for (int i=0; i < 2; ++i) {
loader.createInstance<Base>("Cat")->saySomething();
loader.createInstance<Base>("Dog")->saySomething();
loader.createInstance<Base>("Robot")->saySomething();
}
}
catch(class_loader::ClassLoaderException& e)
{
FAIL() << "ClassLoaderException: " << e.what() << "\n";
}

SUCCEED();
}

TEST(MultiClassLoaderTest, lazyLoad)
{
testMultiClassLoader(true);
}
TEST(MultiClassLoaderTest, lazyLoadSecondTime)
{
testMultiClassLoader(true);
}
TEST(MultiClassLoaderTest, nonLazyLoad)
{
testMultiClassLoader(false);
}
TEST(MultiClassLoaderTest, noWarningOnLazyLoad)
{
try
{
boost::shared_ptr<Base> cat, dog, rob;
{
class_loader::MultiLibraryClassLoader loader(true);
loader.loadLibrary(LIBRARY_1);
loader.loadLibrary(LIBRARY_2);

cat = loader.createInstance<Base>("Cat");
dog = loader.createInstance<Base>("Dog");
rob = loader.createInstance<Base>("Robot");
}
cat->saySomething();
dog->saySomething();
rob->saySomething();
}
catch(class_loader::ClassLoaderException& e)
{
FAIL() << "ClassLoaderException: " << e.what() << "\n";
}

SUCCEED();
}

/*****************************************************************************/

// Run all the tests that were declared with TEST()
int main(int argc, char **argv){
Expand Down