Skip to content

Commit 2de2fb4

Browse files
committed
added MultiLibraryClassLoader unittest
1 parent 8123cd3 commit 2de2fb4

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

test/utest.cpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <boost/bind.hpp>
33
#include <iostream>
44
#include <class_loader/class_loader.h>
5+
#include <class_loader/multi_library_class_loader.h>
56
#include "base.h"
67
#include <gtest/gtest.h>
78

@@ -297,8 +298,65 @@ TEST(ClassLoaderTest, loadRefCountingLazy)
297298
FAIL() << "Did not throw exception as expected.\n";
298299
}
299300

301+
300302
/*****************************************************************************/
301303

304+
void testMultiClassLoader(bool lazy)
305+
{
306+
try
307+
{
308+
class_loader::MultiLibraryClassLoader loader(lazy);
309+
loader.loadLibrary(LIBRARY_1);
310+
loader.loadLibrary(LIBRARY_2);
311+
for (int i=0; i < 2; ++i) {
312+
loader.createInstance<Base>("Cat")->saySomething();
313+
loader.createInstance<Base>("Dog")->saySomething();
314+
loader.createInstance<Base>("Robot")->saySomething();
315+
}
316+
}
317+
catch(class_loader::ClassLoaderException& e)
318+
{
319+
FAIL() << "ClassLoaderException: " << e.what() << "\n";
320+
}
321+
322+
SUCCEED();
323+
}
324+
325+
TEST(MultiClassLoaderTest, lazyLoad)
326+
{
327+
testMultiClassLoader(true);
328+
}
329+
TEST(MultiClassLoaderTest, nonLazyLoad)
330+
{
331+
testMultiClassLoader(false);
332+
}
333+
TEST(MultiClassLoaderTest, noWarningOnLazyLoad)
334+
{
335+
try
336+
{
337+
boost::shared_ptr<Base> cat, dog, rob;
338+
{
339+
class_loader::MultiLibraryClassLoader loader(true);
340+
loader.loadLibrary(LIBRARY_1);
341+
loader.loadLibrary(LIBRARY_2);
342+
343+
cat = loader.createInstance<Base>("Cat");
344+
dog = loader.createInstance<Base>("Dog");
345+
rob = loader.createInstance<Base>("Robot");
346+
}
347+
cat->saySomething();
348+
dog->saySomething();
349+
rob->saySomething();
350+
}
351+
catch(class_loader::ClassLoaderException& e)
352+
{
353+
FAIL() << "ClassLoaderException: " << e.what() << "\n";
354+
}
355+
356+
SUCCEED();
357+
}
358+
359+
/*****************************************************************************/
302360

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

0 commit comments

Comments
 (0)