41 #include "gtest/gtest.h" 48 TEST(ClassLoaderTest, basicLoad) {
53 FAIL() <<
"ClassLoaderException: " << e.what() <<
"\n";
59 TEST(ClassLoaderTest, correctNonLazyLoadUnload) {
70 FAIL() <<
"ClassLoaderException: " << e.what() <<
"\n";
72 FAIL() <<
"Unhandled exception";
76 TEST(ClassLoaderTest, correctLazyLoadUnload) {
93 FAIL() <<
"ClassLoaderException: " << e.what() <<
"\n";
95 FAIL() <<
"Unhandled exception";
99 TEST(ClassLoaderTest, nonExistentPlugin) {
104 if (
nullptr == obj) {
105 FAIL() <<
"Null object being returned instead of exception thrown.";
113 FAIL() <<
"Unknown exception caught.\n";
116 FAIL() <<
"Did not throw exception as expected.\n";
119 TEST(ClassLoaderTest, nonExistentLibrary) {
126 FAIL() <<
"Unknown exception caught.\n";
129 FAIL() <<
"Did not throw exception as expected.\n";
136 TEST(ClassLoaderTest, invalidBase) {
140 FAIL() <<
"Cat should not be available for InvalidBase";
145 FAIL() <<
"Class not available for correct base class.";
148 FAIL() <<
"Unexpected exception";
150 FAIL() <<
"Unexpected and unknown exception caught.\n";
156 std::this_thread::sleep_for(std::chrono::seconds(seconds));
162 for (
auto & class_ : classes) {
167 TEST(ClassLoaderTest, threadSafety) {
175 std::vector<std::thread *> client_threads;
177 for (
size_t c = 0; c < 1000; c++) {
178 client_threads.push_back(
new std::thread(std::bind(&
run, &loader1)));
181 for (
auto & client_thread : client_threads) {
182 client_thread->join();
185 for (
auto & client_thread : client_threads) {
186 delete (client_thread);
192 FAIL() <<
"Unexpected ClassLoaderException.";
194 FAIL() <<
"Unknown exception.";
198 TEST(ClassLoaderTest, loadRefCountingNonLazy) {
224 FAIL() <<
"Unexpected exception.\n";
226 FAIL() <<
"Unknown exception caught.\n";
229 FAIL() <<
"Did not throw exception as expected.\n";
232 TEST(ClassLoaderTest, loadRefCountingLazy) {
264 FAIL() <<
"Unexpected exception.\n";
266 FAIL() <<
"Unknown exception caught.\n";
269 FAIL() <<
"Did not throw exception as expected.\n";
278 for (
int i = 0; i < 2; ++i) {
284 FAIL() <<
"ClassLoaderException: " << e.what() <<
"\n";
290 TEST(MultiClassLoaderTest, lazyLoad) {
293 TEST(MultiClassLoaderTest, lazyLoadSecondTime) {
296 TEST(MultiClassLoaderTest, nonLazyLoad) {
299 TEST(MultiClassLoaderTest, noWarningOnLazyLoad) {
301 boost::shared_ptr<Base> cat, dog, rob;
315 FAIL() <<
"ClassLoaderException: " << e.what() <<
"\n";
322 int main(
int argc,
char ** argv)
324 testing::InitGoogleTest(&argc, argv);
325 return RUN_ALL_TESTS();
std::vector< std::string > getAvailableClasses()
Indicates which classes (i.e. class_loader) that can be loaded by this object.
An exception class thrown when class_loader is unable to load a runtime library.
A ClassLoader that can bind more than one runtime library.
CLASS_LOADER_PUBLIC bool isLibraryLoaded()
Indicates if a library is loaded within the scope of this ClassLoader. Note that the library may alre...
const std::string LIBRARY_2
CLASS_LOADER_PUBLIC std::string systemLibraryFormat(const std::string &library_name)
Returns a platform specific version of a basic library name.
void testMultiClassLoader(bool lazy)
An exception class thrown when class_loader is unable to create a plugin.
This class allows loading and unloading of dynamically linked libraries which contain class definitio...
virtual void saySomething()=0
void loadLibrary(const std::string &library_path)
Loads a library into memory for this class loader.
int main(int argc, char **argv)
bool isClassAvailable(const std::string &class_name)
Indicates if a plugin class is available.
CLASS_LOADER_PUBLIC int unloadLibrary()
Attempts to unload a library loaded within scope of the ClassLoader. If the library is not opened...
void run(class_loader::ClassLoader *loader)
boost::shared_ptr< Base > createInstance(const std::string &derived_class_name)
Generates an instance of loadable classes (i.e. class_loader).
const std::string LIBRARY_1
CLASS_LOADER_PUBLIC void loadLibrary()
Attempts to load a library on behalf of the ClassLoader. If the library is already opened...
CLASS_LOADER_PUBLIC bool isLibraryLoadedByAnybody(const std::string &library_path)
Indicates if passed library has been loaded by ANY ClassLoader.
boost::shared_ptr< Base > createInstance(const std::string &class_name)
Creates an instance of an object of given class name with ancestor class Base Same as createSharedIns...
TEST(ClassLoaderTest, basicLoad)