|
3 | 3 | #include <thread>
|
4 | 4 |
|
5 | 5 | #include <class_loader/class_loader.h>
|
| 6 | +#include <class_loader/multi_library_class_loader.h> |
6 | 7 |
|
7 | 8 | #include <gtest/gtest.h>
|
8 | 9 |
|
@@ -243,3 +244,62 @@ TEST(ClassLoaderTest, loadRefCountingLazy)
|
243 | 244 |
|
244 | 245 | FAIL() << "Did not throw exception as expected.\n";
|
245 | 246 | }
|
| 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