Skip to content

Commit 6c974f2

Browse files
port multi classloader tests to ros2 branch
1 parent 210ea9f commit 6c974f2

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

test/utest.cpp

+60
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <thread>
44

55
#include <class_loader/class_loader.h>
6+
#include <class_loader/multi_library_class_loader.h>
67

78
#include <gtest/gtest.h>
89

@@ -243,3 +244,62 @@ TEST(ClassLoaderTest, loadRefCountingLazy)
243244

244245
FAIL() << "Did not throw exception as expected.\n";
245246
}
247+
248+
void testMultiClassLoader(bool lazy)
249+
{
250+
try
251+
{
252+
class_loader::MultiLibraryClassLoader loader(lazy);
253+
loader.loadLibrary(LIBRARY_1);
254+
loader.loadLibrary(LIBRARY_2);
255+
for (int i=0; i < 2; ++i) {
256+
loader.createInstance<Base>("Cat")->saySomething();
257+
loader.createInstance<Base>("Dog")->saySomething();
258+
loader.createInstance<Base>("Robot")->saySomething();
259+
}
260+
}
261+
catch(class_loader::ClassLoaderException& e)
262+
{
263+
FAIL() << "ClassLoaderException: " << e.what() << "\n";
264+
}
265+
266+
SUCCEED();
267+
}
268+
269+
TEST(MultiClassLoaderTest, lazyLoad)
270+
{
271+
testMultiClassLoader(true);
272+
}
273+
TEST(MultiClassLoaderTest, lazyLoadSecondTime)
274+
{
275+
testMultiClassLoader(true);
276+
}
277+
TEST(MultiClassLoaderTest, nonLazyLoad)
278+
{
279+
testMultiClassLoader(false);
280+
}
281+
TEST(MultiClassLoaderTest, noWarningOnLazyLoad)
282+
{
283+
try
284+
{
285+
std::shared_ptr<Base> cat, dog, rob;
286+
{
287+
class_loader::MultiLibraryClassLoader loader(true);
288+
loader.loadLibrary(LIBRARY_1);
289+
loader.loadLibrary(LIBRARY_2);
290+
291+
cat = loader.createInstance<Base>("Cat");
292+
dog = loader.createInstance<Base>("Dog");
293+
rob = loader.createInstance<Base>("Robot");
294+
}
295+
cat->saySomething();
296+
dog->saySomething();
297+
rob->saySomething();
298+
}
299+
catch(class_loader::ClassLoaderException& e)
300+
{
301+
FAIL() << "ClassLoaderException: " << e.what() << "\n";
302+
}
303+
304+
SUCCEED();
305+
}

0 commit comments

Comments
 (0)