Skip to content

Commit 1709ee3

Browse files
Multi class loader tests (#61)
* port multi classloader tests to ros2 branch * match style of the rest of the file
1 parent 3411f8d commit 1709ee3

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

test/utest.cpp

+54
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,56 @@ TEST(ClassLoaderTest, loadRefCountingLazy)
243244

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

0 commit comments

Comments
 (0)