comparison OrthancServer/UnitTestsSources/PluginsTests.cpp @ 4813:15f9cc6c11f0

fix unit test SharedLibrary.Basic
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 24 Nov 2021 17:38:36 +0100
parents d9473bd5ed43
children 70d2a97ca8cb 7053502fbf97
comparison
equal deleted inserted replaced
4812:6290a0b34aad 4813:15f9cc6c11f0
32 32
33 33
34 #include "PrecompiledHeadersUnitTests.h" 34 #include "PrecompiledHeadersUnitTests.h"
35 #include <gtest/gtest.h> 35 #include <gtest/gtest.h>
36 36
37 #include "../../OrthancFramework/Sources/Compatibility.h"
37 #include "../../OrthancFramework/Sources/OrthancException.h" 38 #include "../../OrthancFramework/Sources/OrthancException.h"
38 #include "../Plugins/Engine/PluginsManager.h" 39 #include "../Plugins/Engine/PluginsManager.h"
39 40
40 using namespace Orthanc; 41 using namespace Orthanc;
41 42
84 85
85 //ASSERT_TRUE(l.GetFunction("_init") != NULL); 86 //ASSERT_TRUE(l.GetFunction("_init") != NULL);
86 //ASSERT_TRUE(l.HasFunction("_init")); 87 //ASSERT_TRUE(l.HasFunction("_init"));
87 88
88 #elif defined(__linux__) || defined(__FreeBSD_kernel__) 89 #elif defined(__linux__) || defined(__FreeBSD_kernel__)
89 SharedLibrary l("libdl.so"); 90 std::unique_ptr<SharedLibrary> l;
90 ASSERT_THROW(l.GetFunction("world"), OrthancException); 91 try
91 ASSERT_TRUE(l.GetFunction("dlopen") != NULL); 92 {
92 ASSERT_TRUE(l.HasFunction("dlclose")); 93 /**
93 ASSERT_FALSE(l.HasFunction("world")); 94 * Since Orthanc 1.9.8, we test the "libdl.so.2" instead of the
95 * "libdl.so", as discussed here:
96 * https://groups.google.com/g/orthanc-users/c/I5g1fN6MCvg/m/JVdvRyjJAAAJ
97 **/
98 l.reset(new SharedLibrary("libdl.so.2"));
99 }
100 catch (OrthancException&)
101 {
102 l.reset(new SharedLibrary("libdl.so")); // Fallback for backward compat
103 }
104
105 ASSERT_THROW(l->GetFunction("world"), OrthancException);
106 ASSERT_TRUE(l->GetFunction("dlopen") != NULL);
107 ASSERT_TRUE(l->HasFunction("dlclose"));
108 ASSERT_FALSE(l->HasFunction("world"));
94 109
95 #elif defined(__FreeBSD__) || defined(__OpenBSD__) 110 #elif defined(__FreeBSD__) || defined(__OpenBSD__)
96 // dlopen() in FreeBSD/OpenBSD is supplied by libc, libc.so is 111 // dlopen() in FreeBSD/OpenBSD is supplied by libc, libc.so is
97 // a ldscript, so we can't actually use it. Use thread 112 // a ldscript, so we can't actually use it. Use thread
98 // library instead - if it works - dlopen() is good. 113 // library instead - if it works - dlopen() is good.