|
2 | 2 | #include <boost/bind.hpp>
|
3 | 3 | #include <iostream>
|
4 | 4 | #include <class_loader/class_loader.h>
|
| 5 | +#include <class_loader/multi_library_class_loader.h> |
5 | 6 | #include "base.h"
|
6 | 7 | #include <gtest/gtest.h>
|
7 | 8 |
|
@@ -297,8 +298,69 @@ TEST(ClassLoaderTest, loadRefCountingLazy)
|
297 | 298 | FAIL() << "Did not throw exception as expected.\n";
|
298 | 299 | }
|
299 | 300 |
|
| 301 | + |
300 | 302 | /*****************************************************************************/
|
301 | 303 |
|
| 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, lazyLoadSecondTime) |
| 330 | +{ |
| 331 | + testMultiClassLoader(true); |
| 332 | +} |
| 333 | +TEST(MultiClassLoaderTest, nonLazyLoad) |
| 334 | +{ |
| 335 | + testMultiClassLoader(false); |
| 336 | +} |
| 337 | +TEST(MultiClassLoaderTest, noWarningOnLazyLoad) |
| 338 | +{ |
| 339 | + try |
| 340 | + { |
| 341 | + boost::shared_ptr<Base> cat, dog, rob; |
| 342 | + { |
| 343 | + class_loader::MultiLibraryClassLoader loader(true); |
| 344 | + loader.loadLibrary(LIBRARY_1); |
| 345 | + loader.loadLibrary(LIBRARY_2); |
| 346 | + |
| 347 | + cat = loader.createInstance<Base>("Cat"); |
| 348 | + dog = loader.createInstance<Base>("Dog"); |
| 349 | + rob = loader.createInstance<Base>("Robot"); |
| 350 | + } |
| 351 | + cat->saySomething(); |
| 352 | + dog->saySomething(); |
| 353 | + rob->saySomething(); |
| 354 | + } |
| 355 | + catch(class_loader::ClassLoaderException& e) |
| 356 | + { |
| 357 | + FAIL() << "ClassLoaderException: " << e.what() << "\n"; |
| 358 | + } |
| 359 | + |
| 360 | + SUCCEED(); |
| 361 | +} |
| 362 | + |
| 363 | +/*****************************************************************************/ |
302 | 364 |
|
303 | 365 | // Run all the tests that were declared with TEST()
|
304 | 366 | int main(int argc, char **argv){
|
|
0 commit comments