Mercurial > hg > orthanc
annotate OrthancServer/UnitTestsSources/PluginsTests.cpp @ 5654:b89439c14916
back to mainline
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 05 Jun 2024 17:53:00 +0200 |
parents | f7adfb22e20e |
children |
rev | line source |
---|---|
885 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1032
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
5640
f7adfb22e20e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
f7adfb22e20e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium |
5485
48b8dae6dc77
upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
885 | 8 * |
9 * This program is free software: you can redistribute it and/or | |
10 * modify it under the terms of the GNU General Public License as | |
11 * published by the Free Software Foundation, either version 3 of the | |
12 * License, or (at your option) any later version. | |
13 * | |
14 * This program is distributed in the hope that it will be useful, but | |
15 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
17 * General Public License for more details. | |
18 * | |
19 * You should have received a copy of the GNU General Public License | |
20 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
21 **/ | |
22 | |
23 | |
24 #include "PrecompiledHeadersUnitTests.h" | |
4062 | 25 #include <gtest/gtest.h> |
885 | 26 |
4813
15f9cc6c11f0
fix unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
27 #include "../../OrthancFramework/Sources/Compatibility.h" |
4045 | 28 #include "../../OrthancFramework/Sources/OrthancException.h" |
887 | 29 #include "../Plugins/Engine/PluginsManager.h" |
885 | 30 |
31 using namespace Orthanc; | |
32 | |
1578 | 33 |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1976
diff
changeset
|
34 #if ORTHANC_ENABLE_PLUGINS == 1 |
1578 | 35 |
36 TEST(SharedLibrary, Enumerations) | |
37 { | |
38 // The plugin engine cannot work if the size of an enumeration does | |
39 // not correspond to the size of "int32_t" | |
40 ASSERT_EQ(sizeof(int32_t), sizeof(OrthancPluginErrorCode)); | |
41 } | |
42 | |
43 | |
885 | 44 TEST(SharedLibrary, Basic) |
45 { | |
46 #if defined(_WIN32) | |
893
f57802f8b4dc
plugins for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
888
diff
changeset
|
47 SharedLibrary l("kernel32.dll"); |
f57802f8b4dc
plugins for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
888
diff
changeset
|
48 ASSERT_THROW(l.GetFunction("world"), OrthancException); |
f57802f8b4dc
plugins for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
888
diff
changeset
|
49 ASSERT_TRUE(l.GetFunction("GetVersionExW") != NULL); |
f57802f8b4dc
plugins for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
888
diff
changeset
|
50 ASSERT_TRUE(l.HasFunction("GetVersionExW")); |
f57802f8b4dc
plugins for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
888
diff
changeset
|
51 ASSERT_FALSE(l.HasFunction("world")); |
885 | 52 |
2451 | 53 #elif defined(__LSB_VERSION__) |
54 // For Linux Standard Base, we use a low-level shared library coming | |
55 // with glibc: | |
56 // http://www.linuxfromscratch.org/lfs/view/6.5/chapter06/glibc.html | |
57 SharedLibrary l("libSegFault.so"); | |
58 ASSERT_THROW(l.GetFunction("world"), OrthancException); | |
59 ASSERT_FALSE(l.HasFunction("world")); | |
60 | |
3035
3254b36a5f9b
fix lsb compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2463
diff
changeset
|
61 /** |
3254b36a5f9b
fix lsb compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2463
diff
changeset
|
62 * On the Docker image "debian:buster-slim", the "libSegFault.so" |
3254b36a5f9b
fix lsb compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2463
diff
changeset
|
63 * library does exist, but does not contain any public symbol: |
3254b36a5f9b
fix lsb compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2463
diff
changeset
|
64 * |
3254b36a5f9b
fix lsb compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2463
diff
changeset
|
65 * $ sudo docker run -i -t --rm --entrypoint=bash debian:buster-slim |
3254b36a5f9b
fix lsb compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2463
diff
changeset
|
66 * # apt-get update && apt-get install -y binutils |
3254b36a5f9b
fix lsb compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2463
diff
changeset
|
67 * # nm -C /lib/x86_64-linux-gnu/libSegFault.so |
3254b36a5f9b
fix lsb compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2463
diff
changeset
|
68 * nm: /lib/x86_64-linux-gnu/libSegFault.so: no symbols |
3254b36a5f9b
fix lsb compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2463
diff
changeset
|
69 * |
3254b36a5f9b
fix lsb compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2463
diff
changeset
|
70 * As a consequence, this part of the test is disabled since Orthanc |
3254b36a5f9b
fix lsb compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2463
diff
changeset
|
71 * 1.5.1, until we locate another shared library that is widely |
3254b36a5f9b
fix lsb compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2463
diff
changeset
|
72 * spread. Reference: |
3254b36a5f9b
fix lsb compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2463
diff
changeset
|
73 * https://groups.google.com/d/msg/orthanc-users/v-QFzpOzgJY/4Hm5NgxKBwAJ |
3254b36a5f9b
fix lsb compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2463
diff
changeset
|
74 **/ |
3254b36a5f9b
fix lsb compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2463
diff
changeset
|
75 |
3254b36a5f9b
fix lsb compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2463
diff
changeset
|
76 //ASSERT_TRUE(l.GetFunction("_init") != NULL); |
3254b36a5f9b
fix lsb compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2463
diff
changeset
|
77 //ASSERT_TRUE(l.HasFunction("_init")); |
3254b36a5f9b
fix lsb compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2463
diff
changeset
|
78 |
1976
325772dadcd6
Macro "__linux" (now obsolete) replaced by macro "__linux__"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
79 #elif defined(__linux__) || defined(__FreeBSD_kernel__) |
4854
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
80 /** |
4902
df86d2505df8
Orthanc 1.9.8 is now known as Orthanc 1.10.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4892
diff
changeset
|
81 * Since Orthanc 1.10.0, we test the "libdl.so.2" instead of the |
4854
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
82 * "libdl.so", as discussed here: |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
83 * https://groups.google.com/g/orthanc-users/c/I5g1fN6MCvg/m/JVdvRyjJAAAJ |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
84 * https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1001305 |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
85 * https://salsa.debian.org/med-team/orthanc/-/blob/master/debian/patches/glibc-2.34.patch |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
86 **/ |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
87 |
4813
15f9cc6c11f0
fix unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
88 try |
15f9cc6c11f0
fix unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
89 { |
4854
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
90 SharedLibrary l("libdl.so.2"); |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
91 ASSERT_THROW(l.GetFunction("world"), OrthancException); |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
92 ASSERT_TRUE(l.GetFunction("dlopen") != NULL); |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
93 ASSERT_TRUE(l.HasFunction("dlclose")); |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
94 ASSERT_FALSE(l.HasFunction("world")); |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
95 return; // Success |
4813
15f9cc6c11f0
fix unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
96 } |
15f9cc6c11f0
fix unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
97 catch (OrthancException&) |
15f9cc6c11f0
fix unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
98 { |
4854
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
99 } |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
100 |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
101 try |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
102 { |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
103 SharedLibrary l("libdl.so"); // Fallback for backward compat |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
104 ASSERT_THROW(l.GetFunction("world"), OrthancException); |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
105 ASSERT_TRUE(l.GetFunction("dlopen") != NULL); |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
106 ASSERT_TRUE(l.HasFunction("dlclose")); |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
107 ASSERT_FALSE(l.HasFunction("world")); |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
108 return; // Success |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
109 } |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
110 catch (OrthancException&) |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
111 { |
4813
15f9cc6c11f0
fix unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
112 } |
15f9cc6c11f0
fix unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
113 |
4854
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
114 try |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
115 { |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
116 SharedLibrary l("libmemusage.so"); // Try another common library |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
117 ASSERT_THROW(l.GetFunction("world"), OrthancException); |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
118 ASSERT_TRUE(l.GetFunction("munmap") != NULL); |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
119 ASSERT_TRUE(l.HasFunction("free")); |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
120 ASSERT_FALSE(l.HasFunction("world")); |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
121 return; // Success |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
122 } |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
123 catch (OrthancException&) |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
124 { |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
125 } |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
126 |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
127 ASSERT_TRUE(0); |
885 | 128 |
2364 | 129 #elif defined(__FreeBSD__) || defined(__OpenBSD__) |
130 // dlopen() in FreeBSD/OpenBSD is supplied by libc, libc.so is | |
1337 | 131 // a ldscript, so we can't actually use it. Use thread |
132 // library instead - if it works - dlopen() is good. | |
133 SharedLibrary l("libpthread.so"); | |
134 ASSERT_THROW(l.GetFunction("world"), OrthancException); | |
135 ASSERT_TRUE(l.GetFunction("pthread_create") != NULL); | |
136 ASSERT_TRUE(l.HasFunction("pthread_cancel")); | |
137 ASSERT_FALSE(l.HasFunction("world")); | |
138 | |
1026 | 139 #elif defined(__APPLE__) && defined(__MACH__) |
140 SharedLibrary l("libdl.dylib"); | |
141 ASSERT_THROW(l.GetFunction("world"), OrthancException); | |
142 ASSERT_TRUE(l.GetFunction("dlopen") != NULL); | |
143 ASSERT_TRUE(l.HasFunction("dlclose")); | |
144 ASSERT_FALSE(l.HasFunction("world")); | |
145 | |
885 | 146 #else |
147 #error Support your platform here | |
148 #endif | |
149 } | |
1578 | 150 |
151 #endif |