diff --git a/test/utest.cpp b/test/utest.cpp index c4e9d882..fbe5b5be 100644 --- a/test/utest.cpp +++ b/test/utest.cpp @@ -3,6 +3,7 @@ #include #include +#include #include @@ -243,3 +244,56 @@ 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("Cat")->saySomething(); + loader.createInstance("Dog")->saySomething(); + loader.createInstance("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 { + std::shared_ptr cat, dog, rob; + { + class_loader::MultiLibraryClassLoader loader(true); + loader.loadLibrary(LIBRARY_1); + loader.loadLibrary(LIBRARY_2); + + cat = loader.createInstance("Cat"); + dog = loader.createInstance("Dog"); + rob = loader.createInstance("Robot"); + } + cat->saySomething(); + dog->saySomething(); + rob->saySomething(); + } catch (class_loader::ClassLoaderException & e) { + FAIL() << "ClassLoaderException: " << e.what() << "\n"; + } + + SUCCEED(); +}