Mercurial > hg > orthanc
annotate OrthancServer/UnitTestsSources/PluginsTests.cpp @ 4988:8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
author | Alain Mazy <am@osimis.io> |
---|---|
date | Sat, 30 Apr 2022 19:39:40 +0200 |
parents | df86d2505df8 |
children | 0ea402b4d901 |
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 |
4870
43e613a7756b
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4854
diff
changeset
|
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium |
43e613a7756b
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4854
diff
changeset
|
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
885 | 7 * |
8 * This program is free software: you can redistribute it and/or | |
9 * modify it under the terms of the GNU General Public License as | |
10 * published by the Free Software Foundation, either version 3 of the | |
11 * License, or (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, but | |
14 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 * General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License | |
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 **/ | |
21 | |
22 | |
23 #include "PrecompiledHeadersUnitTests.h" | |
4062 | 24 #include <gtest/gtest.h> |
885 | 25 |
4813
15f9cc6c11f0
fix unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
26 #include "../../OrthancFramework/Sources/Compatibility.h" |
4045 | 27 #include "../../OrthancFramework/Sources/OrthancException.h" |
887 | 28 #include "../Plugins/Engine/PluginsManager.h" |
885 | 29 |
30 using namespace Orthanc; | |
31 | |
1578 | 32 |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1976
diff
changeset
|
33 #if ORTHANC_ENABLE_PLUGINS == 1 |
1578 | 34 |
35 TEST(SharedLibrary, Enumerations) | |
36 { | |
37 // The plugin engine cannot work if the size of an enumeration does | |
38 // not correspond to the size of "int32_t" | |
39 ASSERT_EQ(sizeof(int32_t), sizeof(OrthancPluginErrorCode)); | |
40 } | |
41 | |
42 | |
885 | 43 TEST(SharedLibrary, Basic) |
44 { | |
45 #if defined(_WIN32) | |
893
f57802f8b4dc
plugins for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
888
diff
changeset
|
46 SharedLibrary l("kernel32.dll"); |
f57802f8b4dc
plugins for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
888
diff
changeset
|
47 ASSERT_THROW(l.GetFunction("world"), OrthancException); |
f57802f8b4dc
plugins for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
888
diff
changeset
|
48 ASSERT_TRUE(l.GetFunction("GetVersionExW") != NULL); |
f57802f8b4dc
plugins for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
888
diff
changeset
|
49 ASSERT_TRUE(l.HasFunction("GetVersionExW")); |
f57802f8b4dc
plugins for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
888
diff
changeset
|
50 ASSERT_FALSE(l.HasFunction("world")); |
885 | 51 |
2451 | 52 #elif defined(__LSB_VERSION__) |
53 // For Linux Standard Base, we use a low-level shared library coming | |
54 // with glibc: | |
55 // http://www.linuxfromscratch.org/lfs/view/6.5/chapter06/glibc.html | |
56 SharedLibrary l("libSegFault.so"); | |
57 ASSERT_THROW(l.GetFunction("world"), OrthancException); | |
58 ASSERT_FALSE(l.HasFunction("world")); | |
59 | |
3035
3254b36a5f9b
fix lsb compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2463
diff
changeset
|
60 /** |
3254b36a5f9b
fix lsb compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2463
diff
changeset
|
61 * On the Docker image "debian:buster-slim", the "libSegFault.so" |
3254b36a5f9b
fix lsb compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2463
diff
changeset
|
62 * library does exist, but does not contain any public symbol: |
3254b36a5f9b
fix lsb compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2463
diff
changeset
|
63 * |
3254b36a5f9b
fix lsb compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2463
diff
changeset
|
64 * $ 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
|
65 * # apt-get update && apt-get install -y binutils |
3254b36a5f9b
fix lsb compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2463
diff
changeset
|
66 * # nm -C /lib/x86_64-linux-gnu/libSegFault.so |
3254b36a5f9b
fix lsb compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2463
diff
changeset
|
67 * nm: /lib/x86_64-linux-gnu/libSegFault.so: no symbols |
3254b36a5f9b
fix lsb compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2463
diff
changeset
|
68 * |
3254b36a5f9b
fix lsb compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2463
diff
changeset
|
69 * 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
|
70 * 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
|
71 * spread. Reference: |
3254b36a5f9b
fix lsb compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2463
diff
changeset
|
72 * 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
|
73 **/ |
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 //ASSERT_TRUE(l.GetFunction("_init") != NULL); |
3254b36a5f9b
fix lsb compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2463
diff
changeset
|
76 //ASSERT_TRUE(l.HasFunction("_init")); |
3254b36a5f9b
fix lsb compatibility
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2463
diff
changeset
|
77 |
1976
325772dadcd6
Macro "__linux" (now obsolete) replaced by macro "__linux__"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
78 #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
|
79 /** |
4902
df86d2505df8
Orthanc 1.9.8 is now known as Orthanc 1.10.0
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4892
diff
changeset
|
80 * 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
|
81 * "libdl.so", as discussed here: |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
82 * 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
|
83 * 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
|
84 * 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
|
85 **/ |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
86 |
4813
15f9cc6c11f0
fix unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
87 try |
15f9cc6c11f0
fix unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
88 { |
4854
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
89 SharedLibrary l("libdl.so.2"); |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
90 ASSERT_THROW(l.GetFunction("world"), OrthancException); |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
91 ASSERT_TRUE(l.GetFunction("dlopen") != NULL); |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
92 ASSERT_TRUE(l.HasFunction("dlclose")); |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
93 ASSERT_FALSE(l.HasFunction("world")); |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
94 return; // Success |
4813
15f9cc6c11f0
fix unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
95 } |
15f9cc6c11f0
fix unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
96 catch (OrthancException&) |
15f9cc6c11f0
fix unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
97 { |
4854
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
98 } |
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 try |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
101 { |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
102 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
|
103 ASSERT_THROW(l.GetFunction("world"), OrthancException); |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
104 ASSERT_TRUE(l.GetFunction("dlopen") != NULL); |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
105 ASSERT_TRUE(l.HasFunction("dlclose")); |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
106 ASSERT_FALSE(l.HasFunction("world")); |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
107 return; // Success |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
108 } |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
109 catch (OrthancException&) |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
110 { |
4813
15f9cc6c11f0
fix unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
111 } |
15f9cc6c11f0
fix unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
112 |
4854
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
113 try |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
114 { |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
115 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
|
116 ASSERT_THROW(l.GetFunction("world"), OrthancException); |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
117 ASSERT_TRUE(l.GetFunction("munmap") != NULL); |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
118 ASSERT_TRUE(l.HasFunction("free")); |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
119 ASSERT_FALSE(l.HasFunction("world")); |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
120 return; // Success |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
121 } |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
122 catch (OrthancException&) |
8bd1f0d9506e
improved fix of unit test SharedLibrary.Basic
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
123 { |
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 ASSERT_TRUE(0); |
885 | 127 |
2364 | 128 #elif defined(__FreeBSD__) || defined(__OpenBSD__) |
129 // dlopen() in FreeBSD/OpenBSD is supplied by libc, libc.so is | |
1337 | 130 // a ldscript, so we can't actually use it. Use thread |
131 // library instead - if it works - dlopen() is good. | |
132 SharedLibrary l("libpthread.so"); | |
133 ASSERT_THROW(l.GetFunction("world"), OrthancException); | |
134 ASSERT_TRUE(l.GetFunction("pthread_create") != NULL); | |
135 ASSERT_TRUE(l.HasFunction("pthread_cancel")); | |
136 ASSERT_FALSE(l.HasFunction("world")); | |
137 | |
1026 | 138 #elif defined(__APPLE__) && defined(__MACH__) |
139 SharedLibrary l("libdl.dylib"); | |
140 ASSERT_THROW(l.GetFunction("world"), OrthancException); | |
141 ASSERT_TRUE(l.GetFunction("dlopen") != NULL); | |
142 ASSERT_TRUE(l.HasFunction("dlclose")); | |
143 ASSERT_FALSE(l.HasFunction("world")); | |
144 | |
885 | 145 #else |
146 #error Support your platform here | |
147 #endif | |
148 } | |
1578 | 149 |
150 #endif |