34 #include <gtest/gtest.h> 51 TEST(ClassLoaderUniquePtrTest, basicLoad) {
57 FAIL() <<
"ClassLoaderException: " << e.what() <<
"\n";
61 TEST(ClassLoaderUniquePtrTest, correctLazyLoadUnload) {
78 FAIL() <<
"ClassLoaderException: " << e.what() <<
"\n";
80 FAIL() <<
"Unhandled exception";
84 TEST(ClassLoaderUniquePtrTest, nonExistentPlugin) {
90 FAIL() <<
"Null object being returned instead of exception thrown.";
98 FAIL() <<
"Unknown exception caught.\n";
101 FAIL() <<
"Did not throw exception as expected.\n";
106 std::this_thread::sleep_for(std::chrono::seconds(seconds));
112 for (
auto & class_ : classes) {
117 TEST(ClassLoaderUniquePtrTest, threadSafety) {
125 std::vector<std::thread> client_threads;
127 for (
size_t c = 0; c < 1000; c++) {
128 client_threads.emplace_back(std::bind(&
run, &loader1));
131 for (
auto & client_thread : client_threads) {
132 client_thread.join();
138 FAIL() <<
"Unexpected ClassLoaderException.";
140 FAIL() <<
"Unknown exception.";
144 TEST(ClassLoaderUniquePtrTest, loadRefCountingLazy) {
176 FAIL() <<
"Unexpected exception.\n";
178 FAIL() <<
"Unknown exception caught.\n";
181 FAIL() <<
"Did not throw exception as expected.\n";
190 for (
int i = 0; i < 2; ++i) {
196 FAIL() <<
"ClassLoaderException: " << e.what() <<
"\n";
202 TEST(MultiClassLoaderUniquePtrTest, lazyLoad) {
205 TEST(MultiClassLoaderUniquePtrTest, lazyLoadSecondTime) {
208 TEST(MultiClassLoaderUniquePtrTest, nonLazyLoad) {
211 TEST(MultiClassLoaderUniquePtrTest, noWarningOnLazyLoad) {
213 ClassLoader::UniquePtr<Base> cat =
nullptr, dog =
nullptr, rob =
nullptr;
227 FAIL() <<
"ClassLoaderException: " << e.what() <<
"\n";
234 int main(
int argc,
char ** argv)
236 testing::InitGoogleTest(&argc, argv);
237 return RUN_ALL_TESTS();
std::vector< std::string > getAvailableClasses()
Indicates which classes (i.e. class_loader) that can be loaded by this object.
ClassLoader::UniquePtr< Base > createUniqueInstance(const std::string &class_name)
Creates an instance of an object of given class name with ancestor class Base Same as createSharedIns...
A ClassLoader that can bind more than one runtime library.
UniquePtr< Base > createUniqueInstance(const std::string &derived_class_name)
Generates an instance of loadable classes (i.e. class_loader).
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_PUBLIC std::string systemLibraryFormat(const std::string &library_name)
Returns a platform specific version of a basic library name.
const std::string LIBRARY_1
An exception class thrown when class_loader is unable to create a plugin.
int main(int argc, char **argv)
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.
CLASS_LOADER_PUBLIC int unloadLibrary()
Attempts to unload a library loaded within scope of the ClassLoader. If the library is not opened...
TEST(ClassLoaderUniquePtrTest, basicLoad)
const std::string LIBRARY_2
void testMultiClassLoader(bool lazy)
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.
void run(ClassLoader *loader)