Go to the documentation of this file.
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();
int main(int argc, char **argv)
const std::string LIBRARY_1
const std::string LIBRARY_2
An exception class thrown when class_loader is unable to load a runtime library.
CLASS_LOADER_PUBLIC std::string systemLibraryFormat(const std::string &library_name)
Returns a platform specific version of a basic library name.
A ClassLoader that can bind more than one runtime library.
TEST(ClassLoaderTest, basicLoad)
CLASS_LOADER_PUBLIC bool isLibraryLoadedByAnybody(const std::string &library_path)
Indicates if passed library has been loaded by ANY ClassLoader.
CLASS_LOADER_PUBLIC void loadLibrary()
Attempts to load a library on behalf of the ClassLoader. If the library is already opened,...
void loadLibrary(const std::string &library_path)
Loads a library into memory for this class loader.
CLASS_LOADER_PUBLIC int unloadLibrary()
Attempts to unload a library loaded within scope of the ClassLoader. If the library is not opened,...
This class allows loading and unloading of dynamically linked libraries which contain class definitio...
void testMultiClassLoader(bool lazy)
void run(class_loader::ClassLoader *loader)
std::vector< std::string > getAvailableClasses()
Indicates which classes (i.e. class_loader) that can be loaded by this object.
virtual void saySomething()=0
bool isClassAvailable(const std::string &class_name)
Indicates if a plugin class is available.
boost::shared_ptr< Base > createInstance(const std::string &derived_class_name)
Generates an instance of loadable classes (i.e. class_loader).
An exception class thrown when class_loader is unable to create a plugin.
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...
CLASS_LOADER_PUBLIC bool isLibraryLoaded()
Indicates if a library is loaded within the scope of this ClassLoader. Note that the library may alre...
class_loader
Author(s): Mirza Shah, Steven! Ragnarök
autogenerated on Fri Jan 12 2024 04:01:32