Mercurial > hg > orthanc
annotate OrthancFramework/UnitTestsSources/FrameworkTests.cpp @ 5537:a85e49dcb63e
added ORTHANC_PLUGIN_DEPRECATED in plugin SDK
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sat, 16 Mar 2024 11:23:02 +0100 |
parents | 48b8dae6dc77 |
children | d7eaa568da15 |
rev | line source |
---|---|
3987 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5485
48b8dae6dc77
upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5377
diff
changeset
|
5 * Copyright (C) 2017-2024 Osimis S.A., Belgium |
48b8dae6dc77
upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5377
diff
changeset
|
6 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
3987 | 7 * |
8 * This program is free software: you can redistribute it and/or | |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
9 * modify it under the terms of the GNU Lesser General Public License |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
10 * as published by the Free Software Foundation, either version 3 of |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
11 * the License, or (at your option) any later version. |
3987 | 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 | |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
16 * Lesser General Public License for more details. |
3987 | 17 * |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
18 * You should have received a copy of the GNU Lesser General Public |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
19 * License along with this program. If not, see |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
20 * <http://www.gnu.org/licenses/>. |
3987 | 21 **/ |
22 | |
23 | |
3992
f9863630ec7f
working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3987
diff
changeset
|
24 #if ORTHANC_UNIT_TESTS_LINK_FRAMEWORK == 1 |
4063
e00f3d089991
shared library of orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4062
diff
changeset
|
25 // Must be the first to be sure to use the Orthanc framework shared library |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3992
diff
changeset
|
26 # include <OrthancFramework.h> |
3992
f9863630ec7f
working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3987
diff
changeset
|
27 #endif |
f9863630ec7f
working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3987
diff
changeset
|
28 |
4063
e00f3d089991
shared library of orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4062
diff
changeset
|
29 #if !defined(ORTHANC_ENABLE_PUGIXML) |
e00f3d089991
shared library of orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4062
diff
changeset
|
30 # error ORTHANC_ENABLE_PUGIXML is not defined |
e00f3d089991
shared library of orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4062
diff
changeset
|
31 #endif |
e00f3d089991
shared library of orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4062
diff
changeset
|
32 |
4045 | 33 #include "../Sources/EnumerationDictionary.h" |
3987 | 34 |
4062 | 35 #include <gtest/gtest.h> |
3987 | 36 |
4045 | 37 #include "../Sources/DicomFormat/DicomTag.h" |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4327
diff
changeset
|
38 #include "../Sources/HttpServer/HttpToolbox.h" |
4045 | 39 #include "../Sources/Logging.h" |
40 #include "../Sources/OrthancException.h" | |
41 #include "../Sources/Toolbox.h" | |
3987 | 42 |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4234
diff
changeset
|
43 #if ORTHANC_SANDBOXED != 1 |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4234
diff
changeset
|
44 # include "../Sources/FileBuffer.h" |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4234
diff
changeset
|
45 # include "../Sources/MetricsRegistry.h" |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4234
diff
changeset
|
46 # include "../Sources/SystemToolbox.h" |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4234
diff
changeset
|
47 # include "../Sources/TemporaryFile.h" |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4234
diff
changeset
|
48 #endif |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4234
diff
changeset
|
49 |
4062 | 50 #include <ctype.h> |
51 | |
3987 | 52 |
53 using namespace Orthanc; | |
54 | |
55 | |
56 TEST(Uuid, Generation) | |
57 { | |
58 for (int i = 0; i < 10; i++) | |
59 { | |
60 std::string s = Toolbox::GenerateUuid(); | |
61 ASSERT_TRUE(Toolbox::IsUuid(s)); | |
62 } | |
63 } | |
64 | |
65 TEST(Uuid, Test) | |
66 { | |
67 ASSERT_FALSE(Toolbox::IsUuid("")); | |
68 ASSERT_FALSE(Toolbox::IsUuid("012345678901234567890123456789012345")); | |
69 ASSERT_TRUE(Toolbox::IsUuid("550e8400-e29b-41d4-a716-446655440000")); | |
70 ASSERT_FALSE(Toolbox::IsUuid("550e8400-e29b-41d4-a716-44665544000_")); | |
71 ASSERT_FALSE(Toolbox::IsUuid("01234567890123456789012345678901234_")); | |
72 ASSERT_FALSE(Toolbox::StartsWithUuid("550e8400-e29b-41d4-a716-44665544000")); | |
73 ASSERT_TRUE(Toolbox::StartsWithUuid("550e8400-e29b-41d4-a716-446655440000")); | |
74 ASSERT_TRUE(Toolbox::StartsWithUuid("550e8400-e29b-41d4-a716-446655440000 ok")); | |
75 ASSERT_FALSE(Toolbox::StartsWithUuid("550e8400-e29b-41d4-a716-446655440000ok")); | |
76 } | |
77 | |
78 TEST(Toolbox, IsSHA1) | |
79 { | |
80 ASSERT_FALSE(Toolbox::IsSHA1("")); | |
81 ASSERT_FALSE(Toolbox::IsSHA1("01234567890123456789012345678901234567890123")); | |
82 ASSERT_FALSE(Toolbox::IsSHA1("012345678901234567890123456789012345678901234")); | |
83 ASSERT_TRUE(Toolbox::IsSHA1("b5ed549f-956400ce-69a8c063-bf5b78be-2732a4b9")); | |
84 | |
85 std::string sha = " b5ed549f-956400ce-69a8c063-bf5b78be-2732a4b9 "; | |
86 ASSERT_TRUE(Toolbox::IsSHA1(sha)); | |
87 sha[3] = '\0'; | |
88 sha[53] = '\0'; | |
89 ASSERT_TRUE(Toolbox::IsSHA1(sha)); | |
90 sha[40] = '\0'; | |
91 ASSERT_FALSE(Toolbox::IsSHA1(sha)); | |
92 ASSERT_FALSE(Toolbox::IsSHA1(" ")); | |
93 | |
94 ASSERT_TRUE(Toolbox::IsSHA1("16738bc3-e47ed42a-43ce044c-a3414a45-cb069bd0")); | |
95 | |
96 std::string s; | |
97 Toolbox::ComputeSHA1(s, "The quick brown fox jumps over the lazy dog"); | |
98 ASSERT_TRUE(Toolbox::IsSHA1(s)); | |
99 ASSERT_EQ("2fd4e1c6-7a2d28fc-ed849ee1-bb76e739-1b93eb12", s); | |
100 | |
101 ASSERT_FALSE(Toolbox::IsSHA1("b5ed549f-956400ce-69a8c063-bf5b78be-2732a4b_")); | |
102 } | |
103 | |
104 | |
105 TEST(ParseGetArguments, Basic) | |
106 { | |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4327
diff
changeset
|
107 HttpToolbox::GetArguments b; |
3987 | 108 HttpToolbox::ParseGetArguments(b, "aaa=baaa&bb=a&aa=c"); |
109 | |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4327
diff
changeset
|
110 HttpToolbox::Arguments a; |
3987 | 111 HttpToolbox::CompileGetArguments(a, b); |
112 | |
113 ASSERT_EQ(3u, a.size()); | |
114 ASSERT_EQ(a["aaa"], "baaa"); | |
115 ASSERT_EQ(a["bb"], "a"); | |
116 ASSERT_EQ(a["aa"], "c"); | |
117 } | |
118 | |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4327
diff
changeset
|
119 |
3987 | 120 TEST(ParseGetArguments, BasicEmpty) |
121 { | |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4327
diff
changeset
|
122 HttpToolbox::GetArguments b; |
3987 | 123 HttpToolbox::ParseGetArguments(b, "aaa&bb=aa&aa"); |
124 | |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4327
diff
changeset
|
125 HttpToolbox::Arguments a; |
3987 | 126 HttpToolbox::CompileGetArguments(a, b); |
127 | |
128 ASSERT_EQ(3u, a.size()); | |
129 ASSERT_EQ(a["aaa"], ""); | |
130 ASSERT_EQ(a["bb"], "aa"); | |
131 ASSERT_EQ(a["aa"], ""); | |
132 } | |
133 | |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4327
diff
changeset
|
134 |
3987 | 135 TEST(ParseGetArguments, Single) |
136 { | |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4327
diff
changeset
|
137 HttpToolbox::GetArguments b; |
3987 | 138 HttpToolbox::ParseGetArguments(b, "aaa=baaa"); |
139 | |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4327
diff
changeset
|
140 HttpToolbox::Arguments a; |
3987 | 141 HttpToolbox::CompileGetArguments(a, b); |
142 | |
143 ASSERT_EQ(1u, a.size()); | |
144 ASSERT_EQ(a["aaa"], "baaa"); | |
145 } | |
146 | |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4327
diff
changeset
|
147 |
3987 | 148 TEST(ParseGetArguments, SingleEmpty) |
149 { | |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4327
diff
changeset
|
150 HttpToolbox::GetArguments b; |
3987 | 151 HttpToolbox::ParseGetArguments(b, "aaa"); |
152 | |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4327
diff
changeset
|
153 HttpToolbox::Arguments a; |
3987 | 154 HttpToolbox::CompileGetArguments(a, b); |
155 | |
156 ASSERT_EQ(1u, a.size()); | |
157 ASSERT_EQ(a["aaa"], ""); | |
158 } | |
159 | |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4327
diff
changeset
|
160 |
3987 | 161 TEST(ParseGetQuery, Test1) |
162 { | |
163 UriComponents uri; | |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4327
diff
changeset
|
164 HttpToolbox::GetArguments b; |
3987 | 165 HttpToolbox::ParseGetQuery(uri, b, "/instances/test/world?aaa=baaa&bb=a&aa=c"); |
166 | |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4327
diff
changeset
|
167 HttpToolbox::Arguments a; |
3987 | 168 HttpToolbox::CompileGetArguments(a, b); |
169 | |
170 ASSERT_EQ(3u, uri.size()); | |
171 ASSERT_EQ("instances", uri[0]); | |
172 ASSERT_EQ("test", uri[1]); | |
173 ASSERT_EQ("world", uri[2]); | |
174 ASSERT_EQ(3u, a.size()); | |
175 ASSERT_EQ(a["aaa"], "baaa"); | |
176 ASSERT_EQ(a["bb"], "a"); | |
177 ASSERT_EQ(a["aa"], "c"); | |
178 } | |
179 | |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4327
diff
changeset
|
180 |
3987 | 181 TEST(ParseGetQuery, Test2) |
182 { | |
183 UriComponents uri; | |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4327
diff
changeset
|
184 HttpToolbox::GetArguments b; |
3987 | 185 HttpToolbox::ParseGetQuery(uri, b, "/instances/test/world"); |
186 | |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4327
diff
changeset
|
187 HttpToolbox::Arguments a; |
3987 | 188 HttpToolbox::CompileGetArguments(a, b); |
189 | |
190 ASSERT_EQ(3u, uri.size()); | |
191 ASSERT_EQ("instances", uri[0]); | |
192 ASSERT_EQ("test", uri[1]); | |
193 ASSERT_EQ("world", uri[2]); | |
194 ASSERT_EQ(0u, a.size()); | |
195 } | |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4327
diff
changeset
|
196 |
3987 | 197 |
198 TEST(Uri, SplitUriComponents) | |
199 { | |
200 UriComponents c, d; | |
201 Toolbox::SplitUriComponents(c, "/cou/hello/world"); | |
202 ASSERT_EQ(3u, c.size()); | |
203 ASSERT_EQ("cou", c[0]); | |
204 ASSERT_EQ("hello", c[1]); | |
205 ASSERT_EQ("world", c[2]); | |
206 | |
207 Toolbox::SplitUriComponents(c, "/cou/hello/world/"); | |
208 ASSERT_EQ(3u, c.size()); | |
209 ASSERT_EQ("cou", c[0]); | |
210 ASSERT_EQ("hello", c[1]); | |
211 ASSERT_EQ("world", c[2]); | |
212 | |
213 Toolbox::SplitUriComponents(c, "/cou/hello/world/a"); | |
214 ASSERT_EQ(4u, c.size()); | |
215 ASSERT_EQ("cou", c[0]); | |
216 ASSERT_EQ("hello", c[1]); | |
217 ASSERT_EQ("world", c[2]); | |
218 ASSERT_EQ("a", c[3]); | |
219 | |
220 Toolbox::SplitUriComponents(c, "/"); | |
221 ASSERT_EQ(0u, c.size()); | |
222 | |
223 Toolbox::SplitUriComponents(c, "/hello"); | |
224 ASSERT_EQ(1u, c.size()); | |
225 ASSERT_EQ("hello", c[0]); | |
226 | |
227 Toolbox::SplitUriComponents(c, "/hello/"); | |
228 ASSERT_EQ(1u, c.size()); | |
229 ASSERT_EQ("hello", c[0]); | |
230 | |
231 ASSERT_THROW(Toolbox::SplitUriComponents(c, ""), OrthancException); | |
232 ASSERT_THROW(Toolbox::SplitUriComponents(c, "a"), OrthancException); | |
233 ASSERT_THROW(Toolbox::SplitUriComponents(c, "/coucou//coucou"), OrthancException); | |
234 | |
235 c.clear(); | |
236 c.push_back("test"); | |
237 ASSERT_EQ("/", Toolbox::FlattenUri(c, 10)); | |
238 } | |
239 | |
240 | |
241 TEST(Uri, Truncate) | |
242 { | |
243 UriComponents c, d; | |
244 Toolbox::SplitUriComponents(c, "/cou/hello/world"); | |
245 | |
246 Toolbox::TruncateUri(d, c, 0); | |
247 ASSERT_EQ(3u, d.size()); | |
248 ASSERT_EQ("cou", d[0]); | |
249 ASSERT_EQ("hello", d[1]); | |
250 ASSERT_EQ("world", d[2]); | |
251 | |
252 Toolbox::TruncateUri(d, c, 1); | |
253 ASSERT_EQ(2u, d.size()); | |
254 ASSERT_EQ("hello", d[0]); | |
255 ASSERT_EQ("world", d[1]); | |
256 | |
257 Toolbox::TruncateUri(d, c, 2); | |
258 ASSERT_EQ(1u, d.size()); | |
259 ASSERT_EQ("world", d[0]); | |
260 | |
261 Toolbox::TruncateUri(d, c, 3); | |
262 ASSERT_EQ(0u, d.size()); | |
263 | |
264 Toolbox::TruncateUri(d, c, 4); | |
265 ASSERT_EQ(0u, d.size()); | |
266 | |
267 Toolbox::TruncateUri(d, c, 5); | |
268 ASSERT_EQ(0u, d.size()); | |
269 } | |
270 | |
271 | |
272 TEST(Uri, Child) | |
273 { | |
274 UriComponents c1; Toolbox::SplitUriComponents(c1, "/hello/world"); | |
275 UriComponents c2; Toolbox::SplitUriComponents(c2, "/hello/hello"); | |
276 UriComponents c3; Toolbox::SplitUriComponents(c3, "/hello"); | |
277 UriComponents c4; Toolbox::SplitUriComponents(c4, "/world"); | |
278 UriComponents c5; Toolbox::SplitUriComponents(c5, "/"); | |
279 | |
280 ASSERT_TRUE(Toolbox::IsChildUri(c1, c1)); | |
281 ASSERT_FALSE(Toolbox::IsChildUri(c1, c2)); | |
282 ASSERT_FALSE(Toolbox::IsChildUri(c1, c3)); | |
283 ASSERT_FALSE(Toolbox::IsChildUri(c1, c4)); | |
284 ASSERT_FALSE(Toolbox::IsChildUri(c1, c5)); | |
285 | |
286 ASSERT_FALSE(Toolbox::IsChildUri(c2, c1)); | |
287 ASSERT_TRUE(Toolbox::IsChildUri(c2, c2)); | |
288 ASSERT_FALSE(Toolbox::IsChildUri(c2, c3)); | |
289 ASSERT_FALSE(Toolbox::IsChildUri(c2, c4)); | |
290 ASSERT_FALSE(Toolbox::IsChildUri(c2, c5)); | |
291 | |
292 ASSERT_TRUE(Toolbox::IsChildUri(c3, c1)); | |
293 ASSERT_TRUE(Toolbox::IsChildUri(c3, c2)); | |
294 ASSERT_TRUE(Toolbox::IsChildUri(c3, c3)); | |
295 ASSERT_FALSE(Toolbox::IsChildUri(c3, c4)); | |
296 ASSERT_FALSE(Toolbox::IsChildUri(c3, c5)); | |
297 | |
298 ASSERT_FALSE(Toolbox::IsChildUri(c4, c1)); | |
299 ASSERT_FALSE(Toolbox::IsChildUri(c4, c2)); | |
300 ASSERT_FALSE(Toolbox::IsChildUri(c4, c3)); | |
301 ASSERT_TRUE(Toolbox::IsChildUri(c4, c4)); | |
302 ASSERT_FALSE(Toolbox::IsChildUri(c4, c5)); | |
303 | |
304 ASSERT_TRUE(Toolbox::IsChildUri(c5, c1)); | |
305 ASSERT_TRUE(Toolbox::IsChildUri(c5, c2)); | |
306 ASSERT_TRUE(Toolbox::IsChildUri(c5, c3)); | |
307 ASSERT_TRUE(Toolbox::IsChildUri(c5, c4)); | |
308 ASSERT_TRUE(Toolbox::IsChildUri(c5, c5)); | |
309 } | |
310 | |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4234
diff
changeset
|
311 |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4234
diff
changeset
|
312 #if ORTHANC_SANDBOXED != 1 |
3987 | 313 TEST(Uri, AutodetectMimeType) |
314 { | |
315 ASSERT_EQ(MimeType_Binary, SystemToolbox::AutodetectMimeType("../NOTES")); | |
316 ASSERT_EQ(MimeType_Binary, SystemToolbox::AutodetectMimeType("")); | |
317 ASSERT_EQ(MimeType_Binary, SystemToolbox::AutodetectMimeType("/")); | |
318 ASSERT_EQ(MimeType_Binary, SystemToolbox::AutodetectMimeType("a/a")); | |
319 ASSERT_EQ(MimeType_Binary, SystemToolbox::AutodetectMimeType("..\\a\\")); | |
320 ASSERT_EQ(MimeType_Binary, SystemToolbox::AutodetectMimeType("..\\a\\a")); | |
321 | |
322 ASSERT_EQ(MimeType_PlainText, SystemToolbox::AutodetectMimeType("../NOTES.txt")); | |
323 ASSERT_EQ(MimeType_PlainText, SystemToolbox::AutodetectMimeType("../coucou.xml/NOTES.txt")); | |
324 ASSERT_EQ(MimeType_Xml, SystemToolbox::AutodetectMimeType("..\\coucou.\\NOTES.xml")); | |
325 ASSERT_EQ(MimeType_Xml, SystemToolbox::AutodetectMimeType("../.xml")); | |
326 ASSERT_EQ(MimeType_Xml, SystemToolbox::AutodetectMimeType("../.XmL")); | |
327 | |
328 ASSERT_EQ(MimeType_JavaScript, SystemToolbox::AutodetectMimeType("NOTES.js")); | |
329 ASSERT_EQ(MimeType_Json, SystemToolbox::AutodetectMimeType("NOTES.json")); | |
330 ASSERT_EQ(MimeType_Pdf, SystemToolbox::AutodetectMimeType("NOTES.pdf")); | |
331 ASSERT_EQ(MimeType_Css, SystemToolbox::AutodetectMimeType("NOTES.css")); | |
332 ASSERT_EQ(MimeType_Html, SystemToolbox::AutodetectMimeType("NOTES.html")); | |
333 ASSERT_EQ(MimeType_PlainText, SystemToolbox::AutodetectMimeType("NOTES.txt")); | |
334 ASSERT_EQ(MimeType_Xml, SystemToolbox::AutodetectMimeType("NOTES.xml")); | |
335 ASSERT_EQ(MimeType_Gif, SystemToolbox::AutodetectMimeType("NOTES.gif")); | |
336 ASSERT_EQ(MimeType_Jpeg, SystemToolbox::AutodetectMimeType("NOTES.jpg")); | |
337 ASSERT_EQ(MimeType_Jpeg, SystemToolbox::AutodetectMimeType("NOTES.jpeg")); | |
338 ASSERT_EQ(MimeType_Png, SystemToolbox::AutodetectMimeType("NOTES.png")); | |
339 ASSERT_EQ(MimeType_NaCl, SystemToolbox::AutodetectMimeType("NOTES.nexe")); | |
340 ASSERT_EQ(MimeType_Json, SystemToolbox::AutodetectMimeType("NOTES.nmf")); | |
341 ASSERT_EQ(MimeType_PNaCl, SystemToolbox::AutodetectMimeType("NOTES.pexe")); | |
342 ASSERT_EQ(MimeType_Svg, SystemToolbox::AutodetectMimeType("NOTES.svg")); | |
343 ASSERT_EQ(MimeType_Woff, SystemToolbox::AutodetectMimeType("NOTES.woff")); | |
344 ASSERT_EQ(MimeType_Woff2, SystemToolbox::AutodetectMimeType("NOTES.woff2")); | |
4887 | 345 ASSERT_EQ(MimeType_Ico, SystemToolbox::AutodetectMimeType("NOTES.ico")); |
3987 | 346 |
347 // Test primitives from the "RegisterDefaultExtensions()" that was | |
348 // present in the sample "Serve Folders plugin" of Orthanc 1.4.2 | |
349 ASSERT_STREQ("application/javascript", EnumerationToString(SystemToolbox::AutodetectMimeType(".js"))); | |
350 ASSERT_STREQ("application/json", EnumerationToString(SystemToolbox::AutodetectMimeType(".json"))); | |
351 ASSERT_STREQ("application/json", EnumerationToString(SystemToolbox::AutodetectMimeType(".nmf"))); | |
352 ASSERT_STREQ("application/octet-stream", EnumerationToString(SystemToolbox::AutodetectMimeType(""))); | |
353 ASSERT_STREQ("application/wasm", EnumerationToString(SystemToolbox::AutodetectMimeType(".wasm"))); | |
354 ASSERT_STREQ("application/x-font-woff", EnumerationToString(SystemToolbox::AutodetectMimeType(".woff"))); | |
355 ASSERT_STREQ("application/x-nacl", EnumerationToString(SystemToolbox::AutodetectMimeType(".nexe"))); | |
356 ASSERT_STREQ("application/x-pnacl", EnumerationToString(SystemToolbox::AutodetectMimeType(".pexe"))); | |
357 ASSERT_STREQ("application/xml", EnumerationToString(SystemToolbox::AutodetectMimeType(".xml"))); | |
358 ASSERT_STREQ("font/woff2", EnumerationToString(SystemToolbox::AutodetectMimeType(".woff2"))); | |
359 ASSERT_STREQ("image/gif", EnumerationToString(SystemToolbox::AutodetectMimeType(".gif"))); | |
360 ASSERT_STREQ("image/jpeg", EnumerationToString(SystemToolbox::AutodetectMimeType(".jpeg"))); | |
361 ASSERT_STREQ("image/jpeg", EnumerationToString(SystemToolbox::AutodetectMimeType(".jpg"))); | |
362 ASSERT_STREQ("image/png", EnumerationToString(SystemToolbox::AutodetectMimeType(".png"))); | |
363 ASSERT_STREQ("image/svg+xml", EnumerationToString(SystemToolbox::AutodetectMimeType(".svg"))); | |
364 ASSERT_STREQ("text/css", EnumerationToString(SystemToolbox::AutodetectMimeType(".css"))); | |
365 ASSERT_STREQ("text/html", EnumerationToString(SystemToolbox::AutodetectMimeType(".html"))); | |
5348
303e930fff0f
"/tools/create-dicom" can now be used to create Encapsulated 3D Manufacturing Model IODs (MTL, OBJ, or STL)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5337
diff
changeset
|
366 |
303e930fff0f
"/tools/create-dicom" can now be used to create Encapsulated 3D Manufacturing Model IODs (MTL, OBJ, or STL)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5337
diff
changeset
|
367 ASSERT_STREQ("model/obj", EnumerationToString(SystemToolbox::AutodetectMimeType(".obj"))); |
303e930fff0f
"/tools/create-dicom" can now be used to create Encapsulated 3D Manufacturing Model IODs (MTL, OBJ, or STL)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5337
diff
changeset
|
368 ASSERT_STREQ("model/mtl", EnumerationToString(SystemToolbox::AutodetectMimeType(".mtl"))); |
303e930fff0f
"/tools/create-dicom" can now be used to create Encapsulated 3D Manufacturing Model IODs (MTL, OBJ, or STL)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5337
diff
changeset
|
369 ASSERT_STREQ("model/stl", EnumerationToString(SystemToolbox::AutodetectMimeType(".stl"))); |
3987 | 370 } |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4234
diff
changeset
|
371 #endif |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4234
diff
changeset
|
372 |
3987 | 373 |
374 TEST(Toolbox, ComputeMD5) | |
375 { | |
376 std::string s; | |
377 | |
378 // # echo -n "Hello" | md5sum | |
379 | |
380 Toolbox::ComputeMD5(s, "Hello"); | |
381 ASSERT_EQ("8b1a9953c4611296a827abf8c47804d7", s); | |
382 Toolbox::ComputeMD5(s, ""); | |
383 ASSERT_EQ("d41d8cd98f00b204e9800998ecf8427e", s); | |
5377 | 384 |
385 Toolbox::ComputeMD5(s, "aaabbbccc"); | |
386 ASSERT_EQ("d1aaf4767a3c10a473407a4e47b02da6", s); | |
387 | |
388 std::set<std::string> set; | |
389 | |
390 Toolbox::ComputeMD5(s, set); | |
391 ASSERT_EQ("d41d8cd98f00b204e9800998ecf8427e", s); // empty set same as empty string | |
392 | |
393 set.insert("bbb"); | |
394 set.insert("ccc"); | |
395 set.insert("aaa"); | |
396 | |
397 Toolbox::ComputeMD5(s, set); | |
398 ASSERT_EQ("d1aaf4767a3c10a473407a4e47b02da6", s); // set md5 same as string with the values sorted | |
3987 | 399 } |
400 | |
401 TEST(Toolbox, ComputeSHA1) | |
402 { | |
403 std::string s; | |
404 | |
405 Toolbox::ComputeSHA1(s, "The quick brown fox jumps over the lazy dog"); | |
406 ASSERT_EQ("2fd4e1c6-7a2d28fc-ed849ee1-bb76e739-1b93eb12", s); | |
407 Toolbox::ComputeSHA1(s, ""); | |
408 ASSERT_EQ("da39a3ee-5e6b4b0d-3255bfef-95601890-afd80709", s); | |
409 } | |
410 | |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4234
diff
changeset
|
411 #if ORTHANC_SANDBOXED != 1 |
3987 | 412 TEST(Toolbox, PathToExecutable) |
413 { | |
414 printf("[%s]\n", SystemToolbox::GetPathToExecutable().c_str()); | |
415 printf("[%s]\n", SystemToolbox::GetDirectoryOfExecutable().c_str()); | |
416 } | |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4234
diff
changeset
|
417 #endif |
3987 | 418 |
419 TEST(Toolbox, StripSpaces) | |
420 { | |
421 ASSERT_EQ("", Toolbox::StripSpaces(" \t \r \n ")); | |
422 ASSERT_EQ("coucou", Toolbox::StripSpaces(" coucou \t \r \n ")); | |
423 ASSERT_EQ("cou cou", Toolbox::StripSpaces(" cou cou \n ")); | |
424 ASSERT_EQ("c", Toolbox::StripSpaces(" \n\t c\r \n ")); | |
4622
9086aeb9d9d2
RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4538
diff
changeset
|
425 |
9086aeb9d9d2
RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4538
diff
changeset
|
426 std::string s = "\" abd \""; |
9086aeb9d9d2
RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4538
diff
changeset
|
427 Toolbox::RemoveSurroundingQuotes(s); ASSERT_EQ(" abd ", s); |
9086aeb9d9d2
RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4538
diff
changeset
|
428 |
9086aeb9d9d2
RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4538
diff
changeset
|
429 s = " \" abd \" "; |
9086aeb9d9d2
RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4538
diff
changeset
|
430 Toolbox::RemoveSurroundingQuotes(s); ASSERT_EQ(" \" abd \" ", s); |
9086aeb9d9d2
RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4538
diff
changeset
|
431 |
9086aeb9d9d2
RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4538
diff
changeset
|
432 s = Toolbox::StripSpaces(s); |
9086aeb9d9d2
RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4538
diff
changeset
|
433 Toolbox::RemoveSurroundingQuotes(s); ASSERT_EQ(" abd ", s); |
9086aeb9d9d2
RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4538
diff
changeset
|
434 |
9086aeb9d9d2
RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4538
diff
changeset
|
435 s = "\""; |
9086aeb9d9d2
RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4538
diff
changeset
|
436 Toolbox::RemoveSurroundingQuotes(s); ASSERT_EQ("", s); |
9086aeb9d9d2
RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4538
diff
changeset
|
437 |
9086aeb9d9d2
RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4538
diff
changeset
|
438 s = "\"\""; |
9086aeb9d9d2
RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4538
diff
changeset
|
439 Toolbox::RemoveSurroundingQuotes(s); ASSERT_EQ("", s); |
9086aeb9d9d2
RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4538
diff
changeset
|
440 |
9086aeb9d9d2
RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4538
diff
changeset
|
441 s = "\"_\""; |
9086aeb9d9d2
RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4538
diff
changeset
|
442 Toolbox::RemoveSurroundingQuotes(s); ASSERT_EQ("_", s); |
9086aeb9d9d2
RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4538
diff
changeset
|
443 |
9086aeb9d9d2
RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4538
diff
changeset
|
444 s = "\"\"\""; |
9086aeb9d9d2
RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4538
diff
changeset
|
445 Toolbox::RemoveSurroundingQuotes(s); ASSERT_EQ("\"", s); |
3987 | 446 } |
447 | |
448 TEST(Toolbox, Case) | |
449 { | |
450 std::string s = "CoU"; | |
451 std::string ss; | |
452 | |
453 Toolbox::ToUpperCase(ss, s); | |
454 ASSERT_EQ("COU", ss); | |
455 Toolbox::ToLowerCase(ss, s); | |
456 ASSERT_EQ("cou", ss); | |
457 | |
458 s = "CoU"; | |
459 Toolbox::ToUpperCase(s); | |
460 ASSERT_EQ("COU", s); | |
461 | |
462 s = "CoU"; | |
463 Toolbox::ToLowerCase(s); | |
464 ASSERT_EQ("cou", s); | |
465 } | |
466 | |
467 | |
468 TEST(Logger, Basic) | |
469 { | |
470 LOG(INFO) << "I say hello"; | |
471 } | |
472 | |
473 TEST(Toolbox, ConvertFromLatin1) | |
474 { | |
475 // This is a Latin-1 test string | |
476 const unsigned char data[10] = { 0xe0, 0xe9, 0xea, 0xe7, 0x26, 0xc6, 0x61, 0x62, 0x63, 0x00 }; | |
477 | |
478 std::string s((char*) &data[0], 10); | |
479 ASSERT_EQ("&abc", Toolbox::ConvertToAscii(s)); | |
480 | |
481 // Open in Emacs, then save with UTF-8 encoding, then "hexdump -C" | |
482 std::string utf8 = Toolbox::ConvertToUtf8(s, Encoding_Latin1, false); | |
483 ASSERT_EQ(15u, utf8.size()); | |
484 ASSERT_EQ(0xc3, static_cast<unsigned char>(utf8[0])); | |
485 ASSERT_EQ(0xa0, static_cast<unsigned char>(utf8[1])); | |
486 ASSERT_EQ(0xc3, static_cast<unsigned char>(utf8[2])); | |
487 ASSERT_EQ(0xa9, static_cast<unsigned char>(utf8[3])); | |
488 ASSERT_EQ(0xc3, static_cast<unsigned char>(utf8[4])); | |
489 ASSERT_EQ(0xaa, static_cast<unsigned char>(utf8[5])); | |
490 ASSERT_EQ(0xc3, static_cast<unsigned char>(utf8[6])); | |
491 ASSERT_EQ(0xa7, static_cast<unsigned char>(utf8[7])); | |
492 ASSERT_EQ(0x26, static_cast<unsigned char>(utf8[8])); | |
493 ASSERT_EQ(0xc3, static_cast<unsigned char>(utf8[9])); | |
494 ASSERT_EQ(0x86, static_cast<unsigned char>(utf8[10])); | |
495 ASSERT_EQ(0x61, static_cast<unsigned char>(utf8[11])); | |
496 ASSERT_EQ(0x62, static_cast<unsigned char>(utf8[12])); | |
497 ASSERT_EQ(0x63, static_cast<unsigned char>(utf8[13])); | |
498 ASSERT_EQ(0x00, static_cast<unsigned char>(utf8[14])); // Null-terminated string | |
499 } | |
500 | |
501 | |
502 TEST(Toolbox, FixUtf8) | |
503 { | |
504 // This is a Latin-1 test string: "crane" with a circumflex accent | |
505 const unsigned char latin1[] = { 0x63, 0x72, 0xe2, 0x6e, 0x65 }; | |
506 | |
507 std::string s((char*) &latin1[0], sizeof(latin1) / sizeof(char)); | |
508 | |
509 ASSERT_EQ(s, Toolbox::ConvertFromUtf8(Toolbox::ConvertToUtf8(s, Encoding_Latin1, false), Encoding_Latin1)); | |
510 ASSERT_EQ("cre", Toolbox::ConvertToUtf8(s, Encoding_Utf8, false)); | |
511 } | |
512 | |
513 | |
514 static int32_t GetUnicode(const uint8_t* data, | |
515 size_t size, | |
516 size_t expectedLength) | |
517 { | |
518 std::string s((char*) &data[0], size); | |
519 uint32_t unicode; | |
520 size_t length; | |
521 Toolbox::Utf8ToUnicodeCharacter(unicode, length, s, 0); | |
522 if (length != expectedLength) | |
523 { | |
524 return -1; // Error case | |
525 } | |
526 else | |
527 { | |
528 return unicode; | |
529 } | |
530 } | |
531 | |
532 | |
533 TEST(Toolbox, Utf8ToUnicode) | |
534 { | |
535 // https://en.wikipedia.org/wiki/UTF-8 | |
536 | |
537 ASSERT_EQ(1u, sizeof(char)); | |
538 ASSERT_EQ(1u, sizeof(uint8_t)); | |
539 | |
540 { | |
541 const uint8_t data[] = { 0x24 }; | |
542 ASSERT_EQ(0x24, GetUnicode(data, 1, 1)); | |
543 ASSERT_THROW(GetUnicode(data, 0, 1), OrthancException); | |
544 } | |
545 | |
546 { | |
547 const uint8_t data[] = { 0xc2, 0xa2 }; | |
548 ASSERT_EQ(0xa2, GetUnicode(data, 2, 2)); | |
549 ASSERT_THROW(GetUnicode(data, 1, 2), OrthancException); | |
550 } | |
551 | |
552 { | |
553 const uint8_t data[] = { 0xe0, 0xa4, 0xb9 }; | |
554 ASSERT_EQ(0x0939, GetUnicode(data, 3, 3)); | |
555 ASSERT_THROW(GetUnicode(data, 2, 3), OrthancException); | |
556 } | |
557 | |
558 { | |
559 const uint8_t data[] = { 0xe2, 0x82, 0xac }; | |
560 ASSERT_EQ(0x20ac, GetUnicode(data, 3, 3)); | |
561 ASSERT_THROW(GetUnicode(data, 2, 3), OrthancException); | |
562 } | |
563 | |
564 { | |
565 const uint8_t data[] = { 0xf0, 0x90, 0x8d, 0x88 }; | |
566 ASSERT_EQ(0x010348, GetUnicode(data, 4, 4)); | |
567 ASSERT_THROW(GetUnicode(data, 3, 4), OrthancException); | |
568 } | |
569 | |
570 { | |
571 const uint8_t data[] = { 0xe0 }; | |
572 ASSERT_THROW(GetUnicode(data, 1, 1), OrthancException); | |
573 } | |
574 } | |
575 | |
576 | |
577 TEST(Toolbox, UrlDecode) | |
578 { | |
579 std::string s; | |
580 | |
581 s = "Hello%20World"; | |
582 Toolbox::UrlDecode(s); | |
583 ASSERT_EQ("Hello World", s); | |
584 | |
585 s = "%21%23%24%26%27%28%29%2A%2B%2c%2f%3A%3b%3d%3f%40%5B%5D%90%ff"; | |
586 Toolbox::UrlDecode(s); | |
587 std::string ss = "!#$&'()*+,/:;=?@[]"; | |
588 ss.push_back((char) 144); | |
589 ss.push_back((char) 255); | |
590 ASSERT_EQ(ss, s); | |
591 | |
592 s = "(2000%2C00A4)+Other"; | |
593 Toolbox::UrlDecode(s); | |
594 ASSERT_EQ("(2000,00A4) Other", s); | |
595 } | |
596 | |
597 | |
598 TEST(Toolbox, IsAsciiString) | |
599 { | |
600 std::string s = "Hello 12 /"; | |
601 ASSERT_EQ(10u, s.size()); | |
602 ASSERT_TRUE(Toolbox::IsAsciiString(s)); | |
603 ASSERT_TRUE(Toolbox::IsAsciiString(s.c_str(), 10)); | |
604 ASSERT_FALSE(Toolbox::IsAsciiString(s.c_str(), 11)); // Taking the trailing hidden '\0' | |
605 | |
606 s[2] = '\0'; | |
607 ASSERT_EQ(10u, s.size()); | |
608 ASSERT_FALSE(Toolbox::IsAsciiString(s)); | |
609 | |
610 ASSERT_TRUE(Toolbox::IsAsciiString("Hello\nworld")); | |
611 ASSERT_FALSE(Toolbox::IsAsciiString("Hello\rworld")); | |
612 | |
613 ASSERT_EQ("Hello\nworld", Toolbox::ConvertToAscii("Hello\nworld")); | |
614 ASSERT_EQ("Helloworld", Toolbox::ConvertToAscii("Hello\r\tworld")); | |
615 } | |
616 | |
617 | |
618 #if defined(__linux__) | |
619 TEST(Toolbox, AbsoluteDirectory) | |
620 { | |
621 ASSERT_EQ("/tmp/hello", SystemToolbox::InterpretRelativePath("/tmp", "hello")); | |
622 ASSERT_EQ("/tmp", SystemToolbox::InterpretRelativePath("/tmp", "/tmp")); | |
623 } | |
624 #endif | |
625 | |
626 | |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4234
diff
changeset
|
627 #if ORTHANC_SANDBOXED != 1 |
3987 | 628 TEST(Toolbox, WriteFile) |
629 { | |
630 std::string path; | |
631 | |
632 { | |
633 TemporaryFile tmp; | |
634 path = tmp.GetPath(); | |
635 | |
636 std::string s; | |
637 s.append("Hello"); | |
638 s.push_back('\0'); | |
639 s.append("World"); | |
640 ASSERT_EQ(11u, s.size()); | |
641 | |
642 SystemToolbox::WriteFile(s, path.c_str()); | |
643 | |
644 std::string t; | |
645 SystemToolbox::ReadFile(t, path.c_str()); | |
646 | |
647 ASSERT_EQ(11u, t.size()); | |
648 ASSERT_EQ(0, t[5]); | |
649 ASSERT_EQ(0, memcmp(s.c_str(), t.c_str(), s.size())); | |
650 | |
651 std::string h; | |
652 ASSERT_EQ(true, SystemToolbox::ReadHeader(h, path.c_str(), 1)); | |
653 ASSERT_EQ(1u, h.size()); | |
654 ASSERT_EQ('H', h[0]); | |
655 ASSERT_TRUE(SystemToolbox::ReadHeader(h, path.c_str(), 0)); | |
656 ASSERT_EQ(0u, h.size()); | |
657 ASSERT_FALSE(SystemToolbox::ReadHeader(h, path.c_str(), 32)); | |
658 ASSERT_EQ(11u, h.size()); | |
659 ASSERT_EQ(0, memcmp(s.c_str(), h.c_str(), s.size())); | |
660 } | |
661 | |
662 std::string u; | |
663 ASSERT_THROW(SystemToolbox::ReadFile(u, path.c_str()), OrthancException); | |
4186 | 664 |
665 { | |
666 TemporaryFile tmp; | |
667 std::string s = "Hello"; | |
668 SystemToolbox::WriteFile(s, tmp.GetPath(), true /* call fsync() */); | |
669 std::string t; | |
670 SystemToolbox::ReadFile(t, tmp.GetPath()); | |
671 ASSERT_EQ(s, t); | |
672 } | |
3987 | 673 } |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4234
diff
changeset
|
674 #endif |
3987 | 675 |
676 | |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4234
diff
changeset
|
677 #if ORTHANC_SANDBOXED != 1 |
3987 | 678 TEST(Toolbox, FileBuffer) |
679 { | |
680 FileBuffer f; | |
681 f.Append("a", 1); | |
682 f.Append("", 0); | |
683 f.Append("bc", 2); | |
684 | |
685 std::string s; | |
686 f.Read(s); | |
687 ASSERT_EQ("abc", s); | |
688 | |
689 ASSERT_THROW(f.Append("d", 1), OrthancException); // File is closed | |
690 } | |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4234
diff
changeset
|
691 #endif |
3987 | 692 |
693 | |
694 TEST(Toolbox, Wildcard) | |
695 { | |
696 ASSERT_EQ("abcd", Toolbox::WildcardToRegularExpression("abcd")); | |
697 ASSERT_EQ("ab.*cd", Toolbox::WildcardToRegularExpression("ab*cd")); | |
698 ASSERT_EQ("ab..cd", Toolbox::WildcardToRegularExpression("ab??cd")); | |
699 ASSERT_EQ("a.*b.c.*d", Toolbox::WildcardToRegularExpression("a*b?c*d")); | |
700 ASSERT_EQ("a\\{b\\]", Toolbox::WildcardToRegularExpression("a{b]")); | |
701 } | |
702 | |
703 | |
704 TEST(Toolbox, Tokenize) | |
705 { | |
706 std::vector<std::string> t; | |
707 | |
708 Toolbox::TokenizeString(t, "", ','); | |
709 ASSERT_EQ(1u, t.size()); | |
710 ASSERT_EQ("", t[0]); | |
711 | |
712 Toolbox::TokenizeString(t, "abc", ','); | |
713 ASSERT_EQ(1u, t.size()); | |
714 ASSERT_EQ("abc", t[0]); | |
715 | |
716 Toolbox::TokenizeString(t, "ab,cd,ef,", ','); | |
717 ASSERT_EQ(4u, t.size()); | |
718 ASSERT_EQ("ab", t[0]); | |
719 ASSERT_EQ("cd", t[1]); | |
720 ASSERT_EQ("ef", t[2]); | |
721 ASSERT_EQ("", t[3]); | |
722 } | |
723 | |
5373 | 724 TEST(Toolbox, SplitString) |
725 { | |
726 { | |
727 std::set<std::string> result; | |
728 Toolbox::SplitString(result, "", ';'); | |
729 ASSERT_EQ(0u, result.size()); | |
730 } | |
731 | |
732 { | |
733 std::set<std::string> result; | |
734 Toolbox::SplitString(result, "a", ';'); | |
735 ASSERT_EQ(1u, result.size()); | |
736 ASSERT_TRUE(result.end() != result.find("a")); | |
737 } | |
738 | |
739 { | |
740 std::set<std::string> result; | |
741 Toolbox::SplitString(result, "a;b", ';'); | |
742 ASSERT_EQ(2u, result.size()); | |
743 ASSERT_TRUE(result.end() != result.find("a")); | |
744 ASSERT_TRUE(result.end() != result.find("b")); | |
745 } | |
746 | |
747 { | |
748 std::set<std::string> result; | |
749 Toolbox::SplitString(result, "a;b;", ';'); | |
750 ASSERT_EQ(2u, result.size()); | |
751 ASSERT_TRUE(result.end() != result.find("a")); | |
752 ASSERT_TRUE(result.end() != result.find("b")); | |
753 } | |
754 | |
755 { | |
756 std::set<std::string> result; | |
757 Toolbox::SplitString(result, "a;a", ';'); | |
758 ASSERT_EQ(1u, result.size()); | |
759 ASSERT_TRUE(result.end() != result.find("a")); | |
760 } | |
761 | |
762 { | |
763 std::vector<std::string> result; | |
764 Toolbox::SplitString(result, "", ';'); | |
765 ASSERT_EQ(0u, result.size()); | |
766 } | |
767 | |
768 { | |
769 std::vector<std::string> result; | |
770 Toolbox::SplitString(result, "a", ';'); | |
771 ASSERT_EQ(1u, result.size()); | |
772 ASSERT_EQ("a", result[0]); | |
773 } | |
774 | |
775 { | |
776 std::vector<std::string> result; | |
777 Toolbox::SplitString(result, "a;b", ';'); | |
778 ASSERT_EQ(2u, result.size()); | |
779 ASSERT_EQ("a", result[0]); | |
780 ASSERT_EQ("b", result[1]); | |
781 } | |
782 | |
783 { | |
784 std::vector<std::string> result; | |
785 Toolbox::SplitString(result, "a;b;", ';'); | |
786 ASSERT_EQ(2u, result.size()); | |
787 ASSERT_EQ("a", result[0]); | |
788 ASSERT_EQ("b", result[1]); | |
789 } | |
790 | |
791 { | |
792 std::vector<std::string> result; | |
793 Toolbox::TokenizeString(result, "a;a", ';'); | |
794 ASSERT_EQ(2u, result.size()); | |
795 ASSERT_EQ("a", result[0]); | |
796 ASSERT_EQ("a", result[1]); | |
797 } | |
798 } | |
799 | |
3987 | 800 TEST(Toolbox, Enumerations) |
801 { | |
802 ASSERT_EQ(Encoding_Utf8, StringToEncoding(EnumerationToString(Encoding_Utf8))); | |
803 ASSERT_EQ(Encoding_Ascii, StringToEncoding(EnumerationToString(Encoding_Ascii))); | |
804 ASSERT_EQ(Encoding_Latin1, StringToEncoding(EnumerationToString(Encoding_Latin1))); | |
805 ASSERT_EQ(Encoding_Latin2, StringToEncoding(EnumerationToString(Encoding_Latin2))); | |
806 ASSERT_EQ(Encoding_Latin3, StringToEncoding(EnumerationToString(Encoding_Latin3))); | |
807 ASSERT_EQ(Encoding_Latin4, StringToEncoding(EnumerationToString(Encoding_Latin4))); | |
808 ASSERT_EQ(Encoding_Latin5, StringToEncoding(EnumerationToString(Encoding_Latin5))); | |
809 ASSERT_EQ(Encoding_Cyrillic, StringToEncoding(EnumerationToString(Encoding_Cyrillic))); | |
810 ASSERT_EQ(Encoding_Arabic, StringToEncoding(EnumerationToString(Encoding_Arabic))); | |
811 ASSERT_EQ(Encoding_Greek, StringToEncoding(EnumerationToString(Encoding_Greek))); | |
812 ASSERT_EQ(Encoding_Hebrew, StringToEncoding(EnumerationToString(Encoding_Hebrew))); | |
813 ASSERT_EQ(Encoding_Japanese, StringToEncoding(EnumerationToString(Encoding_Japanese))); | |
814 ASSERT_EQ(Encoding_Chinese, StringToEncoding(EnumerationToString(Encoding_Chinese))); | |
815 ASSERT_EQ(Encoding_Thai, StringToEncoding(EnumerationToString(Encoding_Thai))); | |
816 ASSERT_EQ(Encoding_Korean, StringToEncoding(EnumerationToString(Encoding_Korean))); | |
817 ASSERT_EQ(Encoding_JapaneseKanji, StringToEncoding(EnumerationToString(Encoding_JapaneseKanji))); | |
818 ASSERT_EQ(Encoding_SimplifiedChinese, StringToEncoding(EnumerationToString(Encoding_SimplifiedChinese))); | |
819 | |
820 ASSERT_EQ(ResourceType_Patient, StringToResourceType(EnumerationToString(ResourceType_Patient))); | |
821 ASSERT_EQ(ResourceType_Study, StringToResourceType(EnumerationToString(ResourceType_Study))); | |
822 ASSERT_EQ(ResourceType_Series, StringToResourceType(EnumerationToString(ResourceType_Series))); | |
823 ASSERT_EQ(ResourceType_Instance, StringToResourceType(EnumerationToString(ResourceType_Instance))); | |
824 | |
825 ASSERT_EQ(ImageFormat_Png, StringToImageFormat(EnumerationToString(ImageFormat_Png))); | |
826 | |
827 ASSERT_EQ(PhotometricInterpretation_ARGB, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_ARGB))); | |
828 ASSERT_EQ(PhotometricInterpretation_CMYK, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_CMYK))); | |
829 ASSERT_EQ(PhotometricInterpretation_HSV, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_HSV))); | |
830 ASSERT_EQ(PhotometricInterpretation_Monochrome1, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_Monochrome1))); | |
831 ASSERT_EQ(PhotometricInterpretation_Monochrome2, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_Monochrome2))); | |
832 ASSERT_EQ(PhotometricInterpretation_Palette, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_Palette))); | |
833 ASSERT_EQ(PhotometricInterpretation_RGB, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_RGB))); | |
834 ASSERT_EQ(PhotometricInterpretation_YBRFull, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_YBRFull))); | |
835 ASSERT_EQ(PhotometricInterpretation_YBRFull422, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_YBRFull422))); | |
836 ASSERT_EQ(PhotometricInterpretation_YBRPartial420, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_YBRPartial420))); | |
837 ASSERT_EQ(PhotometricInterpretation_YBRPartial422, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_YBRPartial422))); | |
838 ASSERT_EQ(PhotometricInterpretation_YBR_ICT, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_YBR_ICT))); | |
839 ASSERT_EQ(PhotometricInterpretation_YBR_RCT, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_YBR_RCT))); | |
840 | |
841 ASSERT_STREQ("Unknown", EnumerationToString(PhotometricInterpretation_Unknown)); | |
842 ASSERT_THROW(StringToPhotometricInterpretation("Unknown"), OrthancException); | |
843 | |
844 ASSERT_EQ(DicomVersion_2008, StringToDicomVersion(EnumerationToString(DicomVersion_2008))); | |
845 ASSERT_EQ(DicomVersion_2017c, StringToDicomVersion(EnumerationToString(DicomVersion_2017c))); | |
4677
521e39b3f2c0
Fix issue #146 (Update Anonyization to 2019c) - was actually updated to 2021b
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4668
diff
changeset
|
846 ASSERT_EQ(DicomVersion_2021b, StringToDicomVersion(EnumerationToString(DicomVersion_2021b))); |
5334
5b2a5cc64cb1
upgraded anonymization to Basic Profile of PS 3.15-2023b Table E.1-1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5326
diff
changeset
|
847 ASSERT_EQ(DicomVersion_2023b, StringToDicomVersion(EnumerationToString(DicomVersion_2023b))); |
3987 | 848 |
849 for (int i = static_cast<int>(ValueRepresentation_ApplicationEntity); | |
850 i < static_cast<int>(ValueRepresentation_NotSupported); i += 1) | |
851 { | |
852 ValueRepresentation vr = static_cast<ValueRepresentation>(i); | |
853 ASSERT_EQ(vr, StringToValueRepresentation(EnumerationToString(vr), true)); | |
854 } | |
855 | |
856 ASSERT_THROW(StringToValueRepresentation("nope", true), OrthancException); | |
857 | |
858 ASSERT_EQ(JobState_Pending, StringToJobState(EnumerationToString(JobState_Pending))); | |
859 ASSERT_EQ(JobState_Running, StringToJobState(EnumerationToString(JobState_Running))); | |
860 ASSERT_EQ(JobState_Success, StringToJobState(EnumerationToString(JobState_Success))); | |
861 ASSERT_EQ(JobState_Failure, StringToJobState(EnumerationToString(JobState_Failure))); | |
862 ASSERT_EQ(JobState_Paused, StringToJobState(EnumerationToString(JobState_Paused))); | |
863 ASSERT_EQ(JobState_Retry, StringToJobState(EnumerationToString(JobState_Retry))); | |
864 ASSERT_THROW(StringToJobState("nope"), OrthancException); | |
865 | |
866 ASSERT_EQ(MimeType_Binary, StringToMimeType(EnumerationToString(MimeType_Binary))); | |
867 ASSERT_EQ(MimeType_Css, StringToMimeType(EnumerationToString(MimeType_Css))); | |
868 ASSERT_EQ(MimeType_Dicom, StringToMimeType(EnumerationToString(MimeType_Dicom))); | |
869 ASSERT_EQ(MimeType_Gif, StringToMimeType(EnumerationToString(MimeType_Gif))); | |
870 ASSERT_EQ(MimeType_Gzip, StringToMimeType(EnumerationToString(MimeType_Gzip))); | |
871 ASSERT_EQ(MimeType_Html, StringToMimeType(EnumerationToString(MimeType_Html))); | |
872 ASSERT_EQ(MimeType_JavaScript, StringToMimeType(EnumerationToString(MimeType_JavaScript))); | |
873 ASSERT_EQ(MimeType_Jpeg, StringToMimeType(EnumerationToString(MimeType_Jpeg))); | |
874 ASSERT_EQ(MimeType_Jpeg2000, StringToMimeType(EnumerationToString(MimeType_Jpeg2000))); | |
875 ASSERT_EQ(MimeType_Json, StringToMimeType(EnumerationToString(MimeType_Json))); | |
876 ASSERT_EQ(MimeType_NaCl, StringToMimeType(EnumerationToString(MimeType_NaCl))); | |
877 ASSERT_EQ(MimeType_PNaCl, StringToMimeType(EnumerationToString(MimeType_PNaCl))); | |
878 ASSERT_EQ(MimeType_Pam, StringToMimeType(EnumerationToString(MimeType_Pam))); | |
879 ASSERT_EQ(MimeType_Pdf, StringToMimeType(EnumerationToString(MimeType_Pdf))); | |
880 ASSERT_EQ(MimeType_PlainText, StringToMimeType(EnumerationToString(MimeType_PlainText))); | |
881 ASSERT_EQ(MimeType_Png, StringToMimeType(EnumerationToString(MimeType_Png))); | |
882 ASSERT_EQ(MimeType_Svg, StringToMimeType(EnumerationToString(MimeType_Svg))); | |
883 ASSERT_EQ(MimeType_WebAssembly, StringToMimeType(EnumerationToString(MimeType_WebAssembly))); | |
884 ASSERT_EQ(MimeType_Xml, StringToMimeType("application/xml")); | |
885 ASSERT_EQ(MimeType_Xml, StringToMimeType("text/xml")); | |
886 ASSERT_EQ(MimeType_Xml, StringToMimeType(EnumerationToString(MimeType_Xml))); | |
887 ASSERT_EQ(MimeType_DicomWebJson, StringToMimeType(EnumerationToString(MimeType_DicomWebJson))); | |
888 ASSERT_EQ(MimeType_DicomWebXml, StringToMimeType(EnumerationToString(MimeType_DicomWebXml))); | |
5348
303e930fff0f
"/tools/create-dicom" can now be used to create Encapsulated 3D Manufacturing Model IODs (MTL, OBJ, or STL)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5337
diff
changeset
|
889 ASSERT_EQ(MimeType_Mtl, StringToMimeType(EnumerationToString(MimeType_Mtl))); |
303e930fff0f
"/tools/create-dicom" can now be used to create Encapsulated 3D Manufacturing Model IODs (MTL, OBJ, or STL)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5337
diff
changeset
|
890 ASSERT_EQ(MimeType_Obj, StringToMimeType(EnumerationToString(MimeType_Obj))); |
303e930fff0f
"/tools/create-dicom" can now be used to create Encapsulated 3D Manufacturing Model IODs (MTL, OBJ, or STL)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5337
diff
changeset
|
891 ASSERT_EQ(MimeType_Stl, StringToMimeType(EnumerationToString(MimeType_Stl))); |
3987 | 892 ASSERT_THROW(StringToMimeType("nope"), OrthancException); |
893 | |
894 ASSERT_TRUE(IsResourceLevelAboveOrEqual(ResourceType_Patient, ResourceType_Patient)); | |
895 ASSERT_TRUE(IsResourceLevelAboveOrEqual(ResourceType_Patient, ResourceType_Study)); | |
896 ASSERT_TRUE(IsResourceLevelAboveOrEqual(ResourceType_Patient, ResourceType_Series)); | |
897 ASSERT_TRUE(IsResourceLevelAboveOrEqual(ResourceType_Patient, ResourceType_Instance)); | |
898 | |
899 ASSERT_FALSE(IsResourceLevelAboveOrEqual(ResourceType_Study, ResourceType_Patient)); | |
900 ASSERT_TRUE(IsResourceLevelAboveOrEqual(ResourceType_Study, ResourceType_Study)); | |
901 ASSERT_TRUE(IsResourceLevelAboveOrEqual(ResourceType_Study, ResourceType_Series)); | |
902 ASSERT_TRUE(IsResourceLevelAboveOrEqual(ResourceType_Study, ResourceType_Instance)); | |
903 | |
904 ASSERT_FALSE(IsResourceLevelAboveOrEqual(ResourceType_Series, ResourceType_Patient)); | |
905 ASSERT_FALSE(IsResourceLevelAboveOrEqual(ResourceType_Series, ResourceType_Study)); | |
906 ASSERT_TRUE(IsResourceLevelAboveOrEqual(ResourceType_Series, ResourceType_Series)); | |
907 ASSERT_TRUE(IsResourceLevelAboveOrEqual(ResourceType_Series, ResourceType_Instance)); | |
908 | |
909 ASSERT_FALSE(IsResourceLevelAboveOrEqual(ResourceType_Instance, ResourceType_Patient)); | |
910 ASSERT_FALSE(IsResourceLevelAboveOrEqual(ResourceType_Instance, ResourceType_Study)); | |
911 ASSERT_FALSE(IsResourceLevelAboveOrEqual(ResourceType_Instance, ResourceType_Series)); | |
912 ASSERT_TRUE(IsResourceLevelAboveOrEqual(ResourceType_Instance, ResourceType_Instance)); | |
4399
80fd140b12ba
New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4342
diff
changeset
|
913 |
80fd140b12ba
New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4342
diff
changeset
|
914 ASSERT_STREQ("Patients", GetResourceTypeText(ResourceType_Patient, true /* plural */, true /* upper case */)); |
80fd140b12ba
New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4342
diff
changeset
|
915 ASSERT_STREQ("patients", GetResourceTypeText(ResourceType_Patient, true, false)); |
80fd140b12ba
New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4342
diff
changeset
|
916 ASSERT_STREQ("Patient", GetResourceTypeText(ResourceType_Patient, false, true)); |
80fd140b12ba
New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4342
diff
changeset
|
917 ASSERT_STREQ("patient", GetResourceTypeText(ResourceType_Patient, false, false)); |
80fd140b12ba
New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4342
diff
changeset
|
918 ASSERT_STREQ("Studies", GetResourceTypeText(ResourceType_Study, true, true)); |
80fd140b12ba
New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4342
diff
changeset
|
919 ASSERT_STREQ("studies", GetResourceTypeText(ResourceType_Study, true, false)); |
80fd140b12ba
New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4342
diff
changeset
|
920 ASSERT_STREQ("Study", GetResourceTypeText(ResourceType_Study, false, true)); |
80fd140b12ba
New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4342
diff
changeset
|
921 ASSERT_STREQ("study", GetResourceTypeText(ResourceType_Study, false, false)); |
80fd140b12ba
New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4342
diff
changeset
|
922 ASSERT_STREQ("Series", GetResourceTypeText(ResourceType_Series, true, true)); |
80fd140b12ba
New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4342
diff
changeset
|
923 ASSERT_STREQ("series", GetResourceTypeText(ResourceType_Series, true, false)); |
80fd140b12ba
New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4342
diff
changeset
|
924 ASSERT_STREQ("Series", GetResourceTypeText(ResourceType_Series, false, true)); |
80fd140b12ba
New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4342
diff
changeset
|
925 ASSERT_STREQ("series", GetResourceTypeText(ResourceType_Series, false, false)); |
80fd140b12ba
New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4342
diff
changeset
|
926 ASSERT_STREQ("Instances", GetResourceTypeText(ResourceType_Instance, true, true)); |
80fd140b12ba
New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4342
diff
changeset
|
927 ASSERT_STREQ("instances", GetResourceTypeText(ResourceType_Instance, true, false)); |
80fd140b12ba
New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4342
diff
changeset
|
928 ASSERT_STREQ("Instance", GetResourceTypeText(ResourceType_Instance, false, true)); |
80fd140b12ba
New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4342
diff
changeset
|
929 ASSERT_STREQ("instance", GetResourceTypeText(ResourceType_Instance, false, false)); |
4668
9210e196cd98
unit test for transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4622
diff
changeset
|
930 |
9210e196cd98
unit test for transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4622
diff
changeset
|
931 DicomTransferSyntax ts; |
9210e196cd98
unit test for transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4622
diff
changeset
|
932 ASSERT_FALSE(LookupTransferSyntax(ts, "nope")); |
9210e196cd98
unit test for transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4622
diff
changeset
|
933 ASSERT_TRUE(LookupTransferSyntax(ts, "1.2.840.10008.1.2")); ASSERT_EQ(DicomTransferSyntax_LittleEndianImplicit, ts); |
9210e196cd98
unit test for transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4622
diff
changeset
|
934 ASSERT_STREQ("1.2.840.10008.1.2", GetTransferSyntaxUid(ts)); |
3987 | 935 } |
936 | |
937 | |
938 #if defined(__linux__) || defined(__OpenBSD__) | |
939 #include <endian.h> | |
940 #elif defined(__FreeBSD__) | |
941 #include <machine/endian.h> | |
942 #endif | |
943 | |
944 | |
945 TEST(Toolbox, Endianness) | |
946 { | |
947 // Parts of this test come from Adam Conrad | |
948 // http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=728822#5 | |
949 | |
950 | |
951 /** | |
952 * Windows and OS X are assumed to always little-endian. | |
953 **/ | |
954 | |
955 #if defined(_WIN32) || defined(__APPLE__) | |
956 ASSERT_EQ(Endianness_Little, Toolbox::DetectEndianness()); | |
957 | |
958 | |
959 /** | |
960 * FreeBSD. | |
961 **/ | |
962 | |
963 #elif defined(__FreeBSD__) || defined(__OpenBSD__) | |
964 # if _BYTE_ORDER == _BIG_ENDIAN | |
965 ASSERT_EQ(Endianness_Big, Toolbox::DetectEndianness()); | |
966 # else // _LITTLE_ENDIAN | |
967 ASSERT_EQ(Endianness_Little, Toolbox::DetectEndianness()); | |
968 # endif | |
969 | |
970 | |
971 /** | |
972 * Linux. | |
973 **/ | |
974 | |
975 #elif defined(__linux__) || defined(__FreeBSD_kernel__) | |
976 | |
977 #if !defined(__BYTE_ORDER) | |
978 # error Support your platform here | |
979 #endif | |
980 | |
981 # if __BYTE_ORDER == __BIG_ENDIAN | |
982 ASSERT_EQ(Endianness_Big, Toolbox::DetectEndianness()); | |
983 # else // __LITTLE_ENDIAN | |
984 ASSERT_EQ(Endianness_Little, Toolbox::DetectEndianness()); | |
985 # endif | |
986 | |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4234
diff
changeset
|
987 |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4234
diff
changeset
|
988 /** |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4234
diff
changeset
|
989 * WebAssembly is always little-endian. |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4234
diff
changeset
|
990 **/ |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4234
diff
changeset
|
991 |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4234
diff
changeset
|
992 #elif defined(__EMSCRIPTEN__) |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4234
diff
changeset
|
993 ASSERT_EQ(Endianness_Little, Toolbox::DetectEndianness()); |
3987 | 994 #else |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4234
diff
changeset
|
995 # error Support your platform here |
3987 | 996 #endif |
997 } | |
998 | |
999 | |
4045 | 1000 #include "../Sources/Endianness.h" |
3987 | 1001 |
1002 static void ASSERT_EQ16(uint16_t a, uint16_t b) | |
1003 { | |
1004 #ifdef __MINGW32__ | |
1005 // This cast solves a linking problem with MinGW | |
1006 ASSERT_EQ(static_cast<unsigned int>(a), static_cast<unsigned int>(b)); | |
1007 #else | |
1008 ASSERT_EQ(a, b); | |
1009 #endif | |
1010 } | |
1011 | |
1012 static void ASSERT_NE16(uint16_t a, uint16_t b) | |
1013 { | |
1014 #ifdef __MINGW32__ | |
1015 // This cast solves a linking problem with MinGW | |
1016 ASSERT_NE(static_cast<unsigned int>(a), static_cast<unsigned int>(b)); | |
1017 #else | |
1018 ASSERT_NE(a, b); | |
1019 #endif | |
1020 } | |
1021 | |
1022 static void ASSERT_EQ32(uint32_t a, uint32_t b) | |
1023 { | |
1024 #ifdef __MINGW32__ | |
1025 // This cast solves a linking problem with MinGW | |
1026 ASSERT_EQ(static_cast<unsigned int>(a), static_cast<unsigned int>(b)); | |
1027 #else | |
1028 ASSERT_EQ(a, b); | |
1029 #endif | |
1030 } | |
1031 | |
1032 static void ASSERT_NE32(uint32_t a, uint32_t b) | |
1033 { | |
1034 #ifdef __MINGW32__ | |
1035 // This cast solves a linking problem with MinGW | |
1036 ASSERT_NE(static_cast<unsigned int>(a), static_cast<unsigned int>(b)); | |
1037 #else | |
1038 ASSERT_NE(a, b); | |
1039 #endif | |
1040 } | |
1041 | |
1042 static void ASSERT_EQ64(uint64_t a, uint64_t b) | |
1043 { | |
1044 #ifdef __MINGW32__ | |
1045 // This cast solves a linking problem with MinGW | |
1046 ASSERT_EQ(static_cast<unsigned int>(a), static_cast<unsigned int>(b)); | |
1047 #else | |
1048 ASSERT_EQ(a, b); | |
1049 #endif | |
1050 } | |
1051 | |
1052 static void ASSERT_NE64(uint64_t a, uint64_t b) | |
1053 { | |
1054 #ifdef __MINGW32__ | |
1055 // This cast solves a linking problem with MinGW | |
1056 ASSERT_NE(static_cast<unsigned long long>(a), static_cast<unsigned long long>(b)); | |
1057 #else | |
1058 ASSERT_NE(a, b); | |
1059 #endif | |
1060 } | |
1061 | |
1062 | |
1063 | |
1064 TEST(Toolbox, EndiannessConversions16) | |
1065 { | |
1066 Endianness e = Toolbox::DetectEndianness(); | |
1067 | |
1068 for (unsigned int i = 0; i < 65536; i += 17) | |
1069 { | |
1070 uint16_t v = static_cast<uint16_t>(i); | |
1071 ASSERT_EQ16(v, be16toh(htobe16(v))); | |
1072 ASSERT_EQ16(v, le16toh(htole16(v))); | |
1073 | |
1074 const uint8_t* bytes = reinterpret_cast<const uint8_t*>(&v); | |
1075 if (bytes[0] != bytes[1]) | |
1076 { | |
1077 ASSERT_NE16(v, le16toh(htobe16(v))); | |
1078 ASSERT_NE16(v, be16toh(htole16(v))); | |
1079 } | |
1080 else | |
1081 { | |
1082 ASSERT_EQ16(v, le16toh(htobe16(v))); | |
1083 ASSERT_EQ16(v, be16toh(htole16(v))); | |
1084 } | |
1085 | |
1086 switch (e) | |
1087 { | |
1088 case Endianness_Little: | |
1089 ASSERT_EQ16(v, htole16(v)); | |
1090 if (bytes[0] != bytes[1]) | |
1091 { | |
1092 ASSERT_NE16(v, htobe16(v)); | |
1093 } | |
1094 else | |
1095 { | |
1096 ASSERT_EQ16(v, htobe16(v)); | |
1097 } | |
1098 break; | |
1099 | |
1100 case Endianness_Big: | |
1101 ASSERT_EQ16(v, htobe16(v)); | |
1102 if (bytes[0] != bytes[1]) | |
1103 { | |
1104 ASSERT_NE16(v, htole16(v)); | |
1105 } | |
1106 else | |
1107 { | |
1108 ASSERT_EQ16(v, htole16(v)); | |
1109 } | |
1110 break; | |
1111 | |
1112 default: | |
1113 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
1114 } | |
1115 } | |
1116 } | |
1117 | |
1118 | |
1119 TEST(Toolbox, EndiannessConversions32) | |
1120 { | |
1121 const uint32_t v = 0xff010203u; | |
1122 const uint32_t r = 0x030201ffu; | |
1123 ASSERT_EQ32(v, be32toh(htobe32(v))); | |
1124 ASSERT_EQ32(v, le32toh(htole32(v))); | |
1125 ASSERT_NE32(v, be32toh(htole32(v))); | |
1126 ASSERT_NE32(v, le32toh(htobe32(v))); | |
1127 | |
1128 switch (Toolbox::DetectEndianness()) | |
1129 { | |
1130 case Endianness_Little: | |
1131 ASSERT_EQ32(r, htobe32(v)); | |
1132 ASSERT_EQ32(v, htole32(v)); | |
1133 ASSERT_EQ32(r, be32toh(v)); | |
1134 ASSERT_EQ32(v, le32toh(v)); | |
1135 break; | |
1136 | |
1137 case Endianness_Big: | |
1138 ASSERT_EQ32(v, htobe32(v)); | |
1139 ASSERT_EQ32(r, htole32(v)); | |
1140 ASSERT_EQ32(v, be32toh(v)); | |
1141 ASSERT_EQ32(r, le32toh(v)); | |
1142 break; | |
1143 | |
1144 default: | |
1145 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
1146 } | |
1147 } | |
1148 | |
1149 | |
1150 TEST(Toolbox, EndiannessConversions64) | |
1151 { | |
1152 const uint64_t v = 0xff01020304050607LL; | |
1153 const uint64_t r = 0x07060504030201ffLL; | |
1154 ASSERT_EQ64(v, be64toh(htobe64(v))); | |
1155 ASSERT_EQ64(v, le64toh(htole64(v))); | |
1156 ASSERT_NE64(v, be64toh(htole64(v))); | |
1157 ASSERT_NE64(v, le64toh(htobe64(v))); | |
1158 | |
1159 switch (Toolbox::DetectEndianness()) | |
1160 { | |
1161 case Endianness_Little: | |
1162 ASSERT_EQ64(r, htobe64(v)); | |
1163 ASSERT_EQ64(v, htole64(v)); | |
1164 ASSERT_EQ64(r, be64toh(v)); | |
1165 ASSERT_EQ64(v, le64toh(v)); | |
1166 break; | |
1167 | |
1168 case Endianness_Big: | |
1169 ASSERT_EQ64(v, htobe64(v)); | |
1170 ASSERT_EQ64(r, htole64(v)); | |
1171 ASSERT_EQ64(v, be64toh(v)); | |
1172 ASSERT_EQ64(r, le64toh(v)); | |
1173 break; | |
1174 | |
1175 default: | |
1176 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
1177 } | |
1178 } | |
1179 | |
1180 | |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4234
diff
changeset
|
1181 #if ORTHANC_SANDBOXED != 1 |
3987 | 1182 TEST(Toolbox, Now) |
1183 { | |
1184 LOG(WARNING) << "Local time: " << SystemToolbox::GetNowIsoString(false); | |
1185 LOG(WARNING) << "Universal time: " << SystemToolbox::GetNowIsoString(true); | |
1186 | |
1187 std::string date, time; | |
1188 SystemToolbox::GetNowDicom(date, time, false); | |
1189 LOG(WARNING) << "Local DICOM time: [" << date << "] [" << time << "]"; | |
1190 | |
1191 SystemToolbox::GetNowDicom(date, time, true); | |
1192 LOG(WARNING) << "Universal DICOM time: [" << date << "] [" << time << "]"; | |
1193 } | |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4234
diff
changeset
|
1194 #endif |
3987 | 1195 |
1196 | |
1197 #if ORTHANC_ENABLE_PUGIXML == 1 | |
1198 TEST(Toolbox, Xml) | |
1199 { | |
1200 Json::Value a; | |
1201 a["hello"] = "world"; | |
1202 a["42"] = 43; | |
1203 a["b"] = Json::arrayValue; | |
1204 a["b"].append("test"); | |
1205 a["b"].append("test2"); | |
1206 | |
1207 std::string s; | |
1208 Toolbox::JsonToXml(s, a); | |
1209 | |
1210 std::cout << s; | |
1211 } | |
1212 #endif | |
1213 | |
1214 | |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4234
diff
changeset
|
1215 #if !defined(_WIN32) && (ORTHANC_SANDBOXED != 1) |
3987 | 1216 TEST(Toolbox, ExecuteSystemCommand) |
1217 { | |
1218 std::vector<std::string> args(2); | |
1219 args[0] = "Hello"; | |
1220 args[1] = "World"; | |
1221 | |
1222 SystemToolbox::ExecuteSystemCommand("echo", args); | |
1223 } | |
1224 #endif | |
1225 | |
1226 | |
1227 TEST(Toolbox, IsInteger) | |
1228 { | |
1229 ASSERT_TRUE(Toolbox::IsInteger("00236")); | |
1230 ASSERT_TRUE(Toolbox::IsInteger("-0042")); | |
1231 ASSERT_TRUE(Toolbox::IsInteger("0")); | |
1232 ASSERT_TRUE(Toolbox::IsInteger("-0")); | |
1233 | |
1234 ASSERT_FALSE(Toolbox::IsInteger("")); | |
1235 ASSERT_FALSE(Toolbox::IsInteger("42a")); | |
1236 ASSERT_FALSE(Toolbox::IsInteger("42-")); | |
1237 } | |
1238 | |
1239 | |
1240 TEST(Toolbox, StartsWith) | |
1241 { | |
1242 ASSERT_TRUE(Toolbox::StartsWith("hello world", "")); | |
1243 ASSERT_TRUE(Toolbox::StartsWith("hello world", "hello")); | |
1244 ASSERT_TRUE(Toolbox::StartsWith("hello world", "h")); | |
1245 ASSERT_FALSE(Toolbox::StartsWith("hello world", "H")); | |
1246 ASSERT_FALSE(Toolbox::StartsWith("h", "hello")); | |
1247 ASSERT_TRUE(Toolbox::StartsWith("h", "h")); | |
1248 ASSERT_FALSE(Toolbox::StartsWith("", "h")); | |
1249 } | |
1250 | |
1251 | |
1252 TEST(Toolbox, UriEncode) | |
1253 { | |
1254 std::string s; | |
1255 | |
1256 // Unreserved characters must not be modified | |
1257 std::string t = "aAzZ09.-~_"; | |
1258 Toolbox::UriEncode(s, t); | |
1259 ASSERT_EQ(t, s); | |
1260 | |
4234
a38376b80cd1
WebDAV: by-studies and by-patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4186
diff
changeset
|
1261 Toolbox::UriEncode(s, "!#$&'()*+,/:;=?@[]"); ASSERT_EQ("%21%23%24%26%27%28%29%2A%2B%2C/%3A%3B%3D%3F%40%5B%5D", s); |
3987 | 1262 Toolbox::UriEncode(s, "%"); ASSERT_EQ("%25", s); |
1263 | |
1264 // Encode characters from UTF-8. This is the test string from the | |
1265 // file "../Resources/EncodingTests.py" | |
1266 Toolbox::UriEncode(s, "\x54\x65\x73\x74\xc3\xa9\xc3\xa4\xc3\xb6\xc3\xb2\xd0\x94\xce\x98\xc4\x9d\xd7\x93\xd8\xb5\xc4\xb7\xd1\x9b\xe0\xb9\x9b\xef\xbe\x88\xc4\xb0"); | |
1267 ASSERT_EQ("Test%C3%A9%C3%A4%C3%B6%C3%B2%D0%94%CE%98%C4%9D%D7%93%D8%B5%C4%B7%D1%9B%E0%B9%9B%EF%BE%88%C4%B0", s); | |
1268 } | |
1269 | |
1270 | |
1271 TEST(Toolbox, AccessJson) | |
1272 { | |
1273 Json::Value v = Json::arrayValue; | |
1274 ASSERT_EQ("nope", Toolbox::GetJsonStringField(v, "hello", "nope")); | |
1275 | |
1276 v = Json::objectValue; | |
1277 ASSERT_EQ("nope", Toolbox::GetJsonStringField(v, "hello", "nope")); | |
1278 ASSERT_EQ(-10, Toolbox::GetJsonIntegerField(v, "hello", -10)); | |
1279 ASSERT_EQ(10u, Toolbox::GetJsonUnsignedIntegerField(v, "hello", 10)); | |
1280 ASSERT_TRUE(Toolbox::GetJsonBooleanField(v, "hello", true)); | |
1281 | |
1282 v["hello"] = "world"; | |
1283 ASSERT_EQ("world", Toolbox::GetJsonStringField(v, "hello", "nope")); | |
1284 ASSERT_THROW(Toolbox::GetJsonIntegerField(v, "hello", -10), OrthancException); | |
1285 ASSERT_THROW(Toolbox::GetJsonUnsignedIntegerField(v, "hello", 10), OrthancException); | |
1286 ASSERT_THROW(Toolbox::GetJsonBooleanField(v, "hello", true), OrthancException); | |
1287 | |
1288 v["hello"] = -42; | |
1289 ASSERT_THROW(Toolbox::GetJsonStringField(v, "hello", "nope"), OrthancException); | |
1290 ASSERT_EQ(-42, Toolbox::GetJsonIntegerField(v, "hello", -10)); | |
1291 ASSERT_THROW(Toolbox::GetJsonUnsignedIntegerField(v, "hello", 10), OrthancException); | |
1292 ASSERT_THROW(Toolbox::GetJsonBooleanField(v, "hello", true), OrthancException); | |
1293 | |
1294 v["hello"] = 42; | |
1295 ASSERT_THROW(Toolbox::GetJsonStringField(v, "hello", "nope"), OrthancException); | |
1296 ASSERT_EQ(42, Toolbox::GetJsonIntegerField(v, "hello", -10)); | |
1297 ASSERT_EQ(42u, Toolbox::GetJsonUnsignedIntegerField(v, "hello", 10)); | |
1298 ASSERT_THROW(Toolbox::GetJsonBooleanField(v, "hello", true), OrthancException); | |
1299 | |
1300 v["hello"] = false; | |
1301 ASSERT_THROW(Toolbox::GetJsonStringField(v, "hello", "nope"), OrthancException); | |
1302 ASSERT_THROW(Toolbox::GetJsonIntegerField(v, "hello", -10), OrthancException); | |
1303 ASSERT_THROW(Toolbox::GetJsonUnsignedIntegerField(v, "hello", 10), OrthancException); | |
1304 ASSERT_FALSE(Toolbox::GetJsonBooleanField(v, "hello", true)); | |
1305 } | |
1306 | |
1307 | |
1308 TEST(Toolbox, LinesIterator) | |
1309 { | |
1310 std::string s; | |
1311 | |
1312 { | |
1313 std::string content; | |
1314 Toolbox::LinesIterator it(content); | |
1315 ASSERT_FALSE(it.GetLine(s)); | |
1316 } | |
1317 | |
1318 { | |
1319 std::string content = "\n\r"; | |
1320 Toolbox::LinesIterator it(content); | |
1321 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s); | |
1322 ASSERT_FALSE(it.GetLine(s)); | |
1323 } | |
1324 | |
1325 { | |
1326 std::string content = "\n Hello \n\nWorld\n\n"; | |
1327 Toolbox::LinesIterator it(content); | |
1328 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s); | |
1329 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ(" Hello ", s); | |
1330 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s); | |
1331 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("World", s); | |
1332 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s); | |
1333 ASSERT_FALSE(it.GetLine(s)); it.Next(); | |
1334 ASSERT_FALSE(it.GetLine(s)); | |
1335 } | |
1336 | |
1337 { | |
1338 std::string content = "\r Hello \r\rWorld\r\r"; | |
1339 Toolbox::LinesIterator it(content); | |
1340 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s); | |
1341 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ(" Hello ", s); | |
1342 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s); | |
1343 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("World", s); | |
1344 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s); | |
1345 ASSERT_FALSE(it.GetLine(s)); it.Next(); | |
1346 ASSERT_FALSE(it.GetLine(s)); | |
1347 } | |
1348 | |
1349 { | |
1350 std::string content = "\n\r Hello \n\r\n\rWorld\n\r\n\r"; | |
1351 Toolbox::LinesIterator it(content); | |
1352 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s); | |
1353 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ(" Hello ", s); | |
1354 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s); | |
1355 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("World", s); | |
1356 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s); | |
1357 ASSERT_FALSE(it.GetLine(s)); it.Next(); | |
1358 ASSERT_FALSE(it.GetLine(s)); | |
1359 } | |
1360 | |
1361 { | |
1362 std::string content = "\r\n Hello \r\n\r\nWorld\r\n\r\n"; | |
1363 Toolbox::LinesIterator it(content); | |
1364 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s); | |
1365 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ(" Hello ", s); | |
1366 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s); | |
1367 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("World", s); | |
1368 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s); | |
1369 ASSERT_FALSE(it.GetLine(s)); it.Next(); | |
1370 ASSERT_FALSE(it.GetLine(s)); | |
1371 } | |
1372 } | |
1373 | |
1374 | |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4234
diff
changeset
|
1375 #if ORTHANC_SANDBOXED != 1 |
3987 | 1376 TEST(Toolbox, SubstituteVariables) |
1377 { | |
1378 std::map<std::string, std::string> env; | |
1379 env["NOPE"] = "nope"; | |
1380 env["WORLD"] = "world"; | |
1381 | |
1382 ASSERT_EQ("Hello world\r\nWorld \r\nDone world\r\n", | |
1383 Toolbox::SubstituteVariables( | |
1384 "Hello ${WORLD}\r\nWorld ${HELLO}\r\nDone ${WORLD}\r\n", | |
1385 env)); | |
1386 | |
1387 ASSERT_EQ("world A a B world C 'c' D {\"a\":\"b\"} E ", | |
1388 Toolbox::SubstituteVariables( | |
1389 "${WORLD} A ${WORLD2:-a} B ${WORLD:-b} C ${WORLD2:-\"'c'\"} D ${WORLD2:-'{\"a\":\"b\"}'} E ${WORLD2:-}", | |
1390 env)); | |
1391 | |
1392 SystemToolbox::GetEnvironmentVariables(env); | |
1393 ASSERT_TRUE(env.find("NOPE") == env.end()); | |
1394 | |
1395 // The "PATH" environment variable should always be available on | |
1396 // machines running the unit tests | |
1397 ASSERT_TRUE(env.find("PATH") != env.end() /* Case used by UNIX */ || | |
1398 env.find("Path") != env.end() /* Case used by Windows */); | |
1399 | |
1400 env["PATH"] = "hello"; | |
1401 ASSERT_EQ("AhelloB", | |
1402 Toolbox::SubstituteVariables("A${PATH}B", env)); | |
1403 } | |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4234
diff
changeset
|
1404 #endif |
3987 | 1405 |
1406 | |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4234
diff
changeset
|
1407 #if ORTHANC_SANDBOXED != 1 |
3987 | 1408 TEST(MetricsRegistry, Basic) |
1409 { | |
1410 { | |
1411 MetricsRegistry m; | |
1412 m.SetEnabled(false); | |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1413 m.SetIntegerValue("hello.world", 42); |
3987 | 1414 |
1415 std::string s; | |
1416 m.ExportPrometheusText(s); | |
1417 ASSERT_TRUE(s.empty()); | |
1418 } | |
1419 | |
1420 { | |
1421 MetricsRegistry m; | |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1422 m.Register("hello.world", MetricsUpdatePolicy_Directly, MetricsDataType_Integer); |
3987 | 1423 |
1424 std::string s; | |
1425 m.ExportPrometheusText(s); | |
1426 ASSERT_TRUE(s.empty()); | |
1427 } | |
1428 | |
1429 { | |
1430 MetricsRegistry m; | |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1431 m.SetIntegerValue("hello.world", -42); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1432 ASSERT_EQ(MetricsUpdatePolicy_Directly, m.GetUpdatePolicy("hello.world")); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1433 ASSERT_THROW(m.GetUpdatePolicy("nope"), OrthancException); |
3987 | 1434 |
1435 std::string s; | |
1436 m.ExportPrometheusText(s); | |
1437 | |
1438 std::vector<std::string> t; | |
1439 Toolbox::TokenizeString(t, s, '\n'); | |
1440 ASSERT_EQ(2u, t.size()); | |
5326
fbe857e942cd
store metrics as integers instead of floats to avoid precision loss in increments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
1441 ASSERT_EQ("hello.world -42 ", t[0].substr(0, 16)); |
3987 | 1442 ASSERT_TRUE(t[1].empty()); |
1443 } | |
1444 | |
1445 { | |
1446 MetricsRegistry m; | |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1447 m.Register("hello.max", MetricsUpdatePolicy_MaxOver10Seconds, MetricsDataType_Integer); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1448 m.SetIntegerValue("hello.max", 10); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1449 m.SetIntegerValue("hello.max", 20); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1450 m.SetIntegerValue("hello.max", -10); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1451 m.SetIntegerValue("hello.max", 5); |
3987 | 1452 |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1453 m.Register("hello.min", MetricsUpdatePolicy_MinOver10Seconds, MetricsDataType_Integer); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1454 m.SetIntegerValue("hello.min", 10); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1455 m.SetIntegerValue("hello.min", 20); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1456 m.SetIntegerValue("hello.min", -10); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1457 m.SetIntegerValue("hello.min", 5); |
3987 | 1458 |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1459 m.Register("hello.directly", MetricsUpdatePolicy_Directly, MetricsDataType_Integer); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1460 m.SetIntegerValue("hello.directly", 10); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1461 m.SetIntegerValue("hello.directly", 20); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1462 m.SetIntegerValue("hello.directly", -10); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1463 m.SetIntegerValue("hello.directly", 5); |
3987 | 1464 |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1465 ASSERT_EQ(MetricsUpdatePolicy_MaxOver10Seconds, m.GetUpdatePolicy("hello.max")); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1466 ASSERT_EQ(MetricsUpdatePolicy_MinOver10Seconds, m.GetUpdatePolicy("hello.min")); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1467 ASSERT_EQ(MetricsUpdatePolicy_Directly, m.GetUpdatePolicy("hello.directly")); |
3987 | 1468 |
1469 std::string s; | |
1470 m.ExportPrometheusText(s); | |
1471 | |
1472 std::vector<std::string> t; | |
1473 Toolbox::TokenizeString(t, s, '\n'); | |
1474 ASSERT_EQ(4u, t.size()); | |
1475 ASSERT_TRUE(t[3].empty()); | |
1476 | |
1477 std::map<std::string, std::string> u; | |
1478 for (size_t i = 0; i < t.size() - 1; i++) | |
1479 { | |
1480 std::vector<std::string> v; | |
1481 Toolbox::TokenizeString(v, t[i], ' '); | |
1482 u[v[0]] = v[1]; | |
1483 } | |
1484 | |
1485 ASSERT_EQ("20", u["hello.max"]); | |
1486 ASSERT_EQ("-10", u["hello.min"]); | |
5336
dd9795dc380d
renamed MetricsType as MetricsUpdate to clarify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5334
diff
changeset
|
1487 ASSERT_EQ("5", u["hello.directly"]); |
3987 | 1488 } |
1489 | |
1490 { | |
1491 MetricsRegistry m; | |
1492 | |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1493 m.SetIntegerValue("a", 10); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1494 m.SetIntegerValue("b", 10, MetricsUpdatePolicy_MinOver10Seconds); |
3987 | 1495 |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1496 m.Register("c", MetricsUpdatePolicy_MaxOver10Seconds, MetricsDataType_Integer); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1497 m.SetIntegerValue("c", 10, MetricsUpdatePolicy_MinOver10Seconds); |
3987 | 1498 |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1499 m.Register("d", MetricsUpdatePolicy_MaxOver10Seconds, MetricsDataType_Integer); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1500 ASSERT_THROW(m.Register("d", MetricsUpdatePolicy_Directly, MetricsDataType_Integer), OrthancException); |
3987 | 1501 |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1502 ASSERT_EQ(MetricsUpdatePolicy_Directly, m.GetUpdatePolicy("a")); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1503 ASSERT_EQ(MetricsUpdatePolicy_MinOver10Seconds, m.GetUpdatePolicy("b")); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1504 ASSERT_EQ(MetricsUpdatePolicy_MaxOver10Seconds, m.GetUpdatePolicy("c")); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1505 ASSERT_EQ(MetricsUpdatePolicy_MaxOver10Seconds, m.GetUpdatePolicy("d")); |
3987 | 1506 } |
1507 | |
1508 { | |
1509 MetricsRegistry m; | |
1510 | |
1511 { | |
1512 MetricsRegistry::Timer t1(m, "a"); | |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1513 MetricsRegistry::Timer t2(m, "b", MetricsUpdatePolicy_MinOver10Seconds); |
3987 | 1514 } |
1515 | |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1516 ASSERT_EQ(MetricsUpdatePolicy_MaxOver10Seconds, m.GetUpdatePolicy("a")); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1517 ASSERT_EQ(MetricsUpdatePolicy_MinOver10Seconds, m.GetUpdatePolicy("b")); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1518 } |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1519 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1520 { |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1521 MetricsRegistry m; |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1522 m.Register("c", MetricsUpdatePolicy_MaxOver10Seconds, MetricsDataType_Integer); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1523 m.SetFloatValue("c", 100, MetricsUpdatePolicy_MinOver10Seconds); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1524 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1525 ASSERT_EQ(MetricsUpdatePolicy_MaxOver10Seconds, m.GetUpdatePolicy("c")); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1526 ASSERT_EQ(MetricsDataType_Integer, m.GetDataType("c")); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1527 } |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1528 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1529 { |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1530 MetricsRegistry m; |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1531 m.Register("c", MetricsUpdatePolicy_MaxOver10Seconds, MetricsDataType_Float); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1532 m.SetIntegerValue("c", 100, MetricsUpdatePolicy_MinOver10Seconds); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1533 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1534 ASSERT_EQ(MetricsUpdatePolicy_MaxOver10Seconds, m.GetUpdatePolicy("c")); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1535 ASSERT_EQ(MetricsDataType_Float, m.GetDataType("c")); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1536 } |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1537 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1538 { |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1539 MetricsRegistry m; |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1540 m.SetIntegerValue("c", 100, MetricsUpdatePolicy_MinOver10Seconds); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1541 m.SetFloatValue("c", 101, MetricsUpdatePolicy_MaxOver10Seconds); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1542 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1543 ASSERT_EQ(MetricsUpdatePolicy_MinOver10Seconds, m.GetUpdatePolicy("c")); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1544 ASSERT_EQ(MetricsDataType_Integer, m.GetDataType("c")); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1545 } |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1546 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1547 { |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1548 MetricsRegistry m; |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1549 m.SetIntegerValue("c", 100); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1550 m.SetFloatValue("c", 101, MetricsUpdatePolicy_MaxOver10Seconds); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1551 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1552 ASSERT_EQ(MetricsUpdatePolicy_Directly, m.GetUpdatePolicy("c")); |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1553 ASSERT_EQ(MetricsDataType_Integer, m.GetDataType("c")); |
3987 | 1554 } |
1555 } | |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4234
diff
changeset
|
1556 #endif |
4342
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1557 |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1558 |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1559 #if ORTHANC_SANDBOXED != 1 |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1560 TEST(Toolbox, ReadFileRange) |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1561 { |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1562 TemporaryFile tmp; |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1563 std::string s; |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1564 |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1565 tmp.Write(""); |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1566 tmp.Read(s); ASSERT_TRUE(s.empty()); |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1567 tmp.ReadRange(s, 0, 0, true); ASSERT_TRUE(s.empty()); |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1568 tmp.ReadRange(s, 0, 10, false); ASSERT_TRUE(s.empty()); |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1569 |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1570 ASSERT_THROW(tmp.ReadRange(s, 0, 1, true), OrthancException); |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1571 |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1572 tmp.Write("Hello"); |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1573 tmp.Read(s); ASSERT_EQ("Hello", s); |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1574 tmp.ReadRange(s, 0, 5, true); ASSERT_EQ("Hello", s); |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1575 tmp.ReadRange(s, 0, 1, true); ASSERT_EQ("H", s); |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1576 tmp.ReadRange(s, 1, 2, true); ASSERT_EQ("e", s); |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1577 tmp.ReadRange(s, 2, 3, true); ASSERT_EQ("l", s); |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1578 tmp.ReadRange(s, 3, 4, true); ASSERT_EQ("l", s); |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1579 tmp.ReadRange(s, 4, 5, true); ASSERT_EQ("o", s); |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1580 tmp.ReadRange(s, 2, 5, true); ASSERT_EQ("llo", s); |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1581 tmp.ReadRange(s, 2, 50, false); ASSERT_EQ("llo", s); |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1582 tmp.ReadRange(s, 2, 2, false); ASSERT_TRUE(s.empty()); |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1583 tmp.ReadRange(s, 10, 50, false); ASSERT_TRUE(s.empty()); |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1584 |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1585 ASSERT_THROW(tmp.ReadRange(s, 5, 10, true), OrthancException); |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1586 ASSERT_THROW(tmp.ReadRange(s, 10, 50, true), OrthancException); |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1587 ASSERT_THROW(tmp.ReadRange(s, 50, 10, true), OrthancException); |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1588 ASSERT_THROW(tmp.ReadRange(s, 2, 1, true), OrthancException); |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1589 } |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1590 #endif |
4538
8a7523da6a9b
added SystemToolbox::GetMacAddresses()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1591 |
8a7523da6a9b
added SystemToolbox::GetMacAddresses()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1592 |
8a7523da6a9b
added SystemToolbox::GetMacAddresses()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1593 #if ORTHANC_SANDBOXED != 1 |
8a7523da6a9b
added SystemToolbox::GetMacAddresses()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1594 TEST(Toolbox, GetMacAddressess) |
8a7523da6a9b
added SystemToolbox::GetMacAddresses()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1595 { |
8a7523da6a9b
added SystemToolbox::GetMacAddresses()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1596 std::set<std::string> mac; |
8a7523da6a9b
added SystemToolbox::GetMacAddresses()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1597 SystemToolbox::GetMacAddresses(mac); |
8a7523da6a9b
added SystemToolbox::GetMacAddresses()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1598 |
8a7523da6a9b
added SystemToolbox::GetMacAddresses()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1599 for (std::set<std::string>::const_iterator it = mac.begin(); it != mac.end(); ++it) |
8a7523da6a9b
added SystemToolbox::GetMacAddresses()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1600 { |
8a7523da6a9b
added SystemToolbox::GetMacAddresses()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1601 printf("MAC address: [%s]\n", it->c_str()); |
8a7523da6a9b
added SystemToolbox::GetMacAddresses()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1602 } |
8a7523da6a9b
added SystemToolbox::GetMacAddresses()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1603 } |
8a7523da6a9b
added SystemToolbox::GetMacAddresses()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1604 #endif |