41 #include "gtest/gtest.h"
48 TEST(ClassLoaderSharedPtrTest, basicLoad) {
53 FAIL() <<
"ClassLoaderException: " << e.what() <<
"\n";
59 TEST(ClassLoaderSharedPtrTest, correctNonLazyLoadUnload) {
70 FAIL() <<
"ClassLoaderException: " << e.what() <<
"\n";
72 FAIL() <<
"Unhandled exception";
76 TEST(ClassLoaderSharedPtrTest, correctLazyLoadUnload) {
93 FAIL() <<
"ClassLoaderException: " << e.what() <<
"\n";
95 FAIL() <<
"Unhandled exception";
99 TEST(ClassLoaderSharedPtrTest, 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(ClassLoaderSharedPtrTest, nonExistentLibrary) {
126 FAIL() <<
"Unknown exception caught.\n";
129 FAIL() <<
"Did not throw exception as expected.\n";
136 TEST(ClassLoaderSharedPtrTest, 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(ClassLoaderSharedPtrTest, 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(ClassLoaderSharedPtrTest, loadRefCountingNonLazy) {
224 FAIL() <<
"Unexpected exception.\n";
226 FAIL() <<
"Unknown exception caught.\n";
229 FAIL() <<
"Did not throw exception as expected.\n";
232 TEST(ClassLoaderSharedPtrTest, 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 std::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();