Mercurial > hg > orthanc
annotate OrthancFramework/UnitTestsSources/FrameworkTests.cpp @ 5361:1e3e7c61640b
fix for wasm
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 11 Jul 2023 15:54:57 +0200 |
parents | 303e930fff0f |
children | 123a94dd57df |
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 | |
5185
0ea402b4d901
upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4887
diff
changeset
|
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
0ea402b4d901
upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4887
diff
changeset
|
6 * Copyright (C) 2021-2023 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); | |
384 } | |
385 | |
386 TEST(Toolbox, ComputeSHA1) | |
387 { | |
388 std::string s; | |
389 | |
390 Toolbox::ComputeSHA1(s, "The quick brown fox jumps over the lazy dog"); | |
391 ASSERT_EQ("2fd4e1c6-7a2d28fc-ed849ee1-bb76e739-1b93eb12", s); | |
392 Toolbox::ComputeSHA1(s, ""); | |
393 ASSERT_EQ("da39a3ee-5e6b4b0d-3255bfef-95601890-afd80709", s); | |
394 } | |
395 | |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4234
diff
changeset
|
396 #if ORTHANC_SANDBOXED != 1 |
3987 | 397 TEST(Toolbox, PathToExecutable) |
398 { | |
399 printf("[%s]\n", SystemToolbox::GetPathToExecutable().c_str()); | |
400 printf("[%s]\n", SystemToolbox::GetDirectoryOfExecutable().c_str()); | |
401 } | |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4234
diff
changeset
|
402 #endif |
3987 | 403 |
404 TEST(Toolbox, StripSpaces) | |
405 { | |
406 ASSERT_EQ("", Toolbox::StripSpaces(" \t \r \n ")); | |
407 ASSERT_EQ("coucou", Toolbox::StripSpaces(" coucou \t \r \n ")); | |
408 ASSERT_EQ("cou cou", Toolbox::StripSpaces(" cou cou \n ")); | |
409 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
|
410 |
9086aeb9d9d2
RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4538
diff
changeset
|
411 std::string s = "\" abd \""; |
9086aeb9d9d2
RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4538
diff
changeset
|
412 Toolbox::RemoveSurroundingQuotes(s); ASSERT_EQ(" abd ", s); |
9086aeb9d9d2
RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4538
diff
changeset
|
413 |
9086aeb9d9d2
RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4538
diff
changeset
|
414 s = " \" abd \" "; |
9086aeb9d9d2
RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4538
diff
changeset
|
415 Toolbox::RemoveSurroundingQuotes(s); ASSERT_EQ(" \" abd \" ", s); |
9086aeb9d9d2
RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4538
diff
changeset
|
416 |
9086aeb9d9d2
RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4538
diff
changeset
|
417 s = Toolbox::StripSpaces(s); |
9086aeb9d9d2
RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4538
diff
changeset
|
418 Toolbox::RemoveSurroundingQuotes(s); ASSERT_EQ(" abd ", s); |
9086aeb9d9d2
RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4538
diff
changeset
|
419 |
9086aeb9d9d2
RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4538
diff
changeset
|
420 s = "\""; |
9086aeb9d9d2
RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4538
diff
changeset
|
421 Toolbox::RemoveSurroundingQuotes(s); ASSERT_EQ("", s); |
9086aeb9d9d2
RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4538
diff
changeset
|
422 |
9086aeb9d9d2
RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4538
diff
changeset
|
423 s = "\"\""; |
9086aeb9d9d2
RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4538
diff
changeset
|
424 Toolbox::RemoveSurroundingQuotes(s); ASSERT_EQ("", s); |
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 s = "\"_\""; |
9086aeb9d9d2
RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4538
diff
changeset
|
427 Toolbox::RemoveSurroundingQuotes(s); ASSERT_EQ("_", 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 = "\"\"\""; |
9086aeb9d9d2
RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4538
diff
changeset
|
430 Toolbox::RemoveSurroundingQuotes(s); ASSERT_EQ("\"", s); |
3987 | 431 } |
432 | |
433 TEST(Toolbox, Case) | |
434 { | |
435 std::string s = "CoU"; | |
436 std::string ss; | |
437 | |
438 Toolbox::ToUpperCase(ss, s); | |
439 ASSERT_EQ("COU", ss); | |
440 Toolbox::ToLowerCase(ss, s); | |
441 ASSERT_EQ("cou", ss); | |
442 | |
443 s = "CoU"; | |
444 Toolbox::ToUpperCase(s); | |
445 ASSERT_EQ("COU", s); | |
446 | |
447 s = "CoU"; | |
448 Toolbox::ToLowerCase(s); | |
449 ASSERT_EQ("cou", s); | |
450 } | |
451 | |
452 | |
453 TEST(Logger, Basic) | |
454 { | |
455 LOG(INFO) << "I say hello"; | |
456 } | |
457 | |
458 TEST(Toolbox, ConvertFromLatin1) | |
459 { | |
460 // This is a Latin-1 test string | |
461 const unsigned char data[10] = { 0xe0, 0xe9, 0xea, 0xe7, 0x26, 0xc6, 0x61, 0x62, 0x63, 0x00 }; | |
462 | |
463 std::string s((char*) &data[0], 10); | |
464 ASSERT_EQ("&abc", Toolbox::ConvertToAscii(s)); | |
465 | |
466 // Open in Emacs, then save with UTF-8 encoding, then "hexdump -C" | |
467 std::string utf8 = Toolbox::ConvertToUtf8(s, Encoding_Latin1, false); | |
468 ASSERT_EQ(15u, utf8.size()); | |
469 ASSERT_EQ(0xc3, static_cast<unsigned char>(utf8[0])); | |
470 ASSERT_EQ(0xa0, static_cast<unsigned char>(utf8[1])); | |
471 ASSERT_EQ(0xc3, static_cast<unsigned char>(utf8[2])); | |
472 ASSERT_EQ(0xa9, static_cast<unsigned char>(utf8[3])); | |
473 ASSERT_EQ(0xc3, static_cast<unsigned char>(utf8[4])); | |
474 ASSERT_EQ(0xaa, static_cast<unsigned char>(utf8[5])); | |
475 ASSERT_EQ(0xc3, static_cast<unsigned char>(utf8[6])); | |
476 ASSERT_EQ(0xa7, static_cast<unsigned char>(utf8[7])); | |
477 ASSERT_EQ(0x26, static_cast<unsigned char>(utf8[8])); | |
478 ASSERT_EQ(0xc3, static_cast<unsigned char>(utf8[9])); | |
479 ASSERT_EQ(0x86, static_cast<unsigned char>(utf8[10])); | |
480 ASSERT_EQ(0x61, static_cast<unsigned char>(utf8[11])); | |
481 ASSERT_EQ(0x62, static_cast<unsigned char>(utf8[12])); | |
482 ASSERT_EQ(0x63, static_cast<unsigned char>(utf8[13])); | |
483 ASSERT_EQ(0x00, static_cast<unsigned char>(utf8[14])); // Null-terminated string | |
484 } | |
485 | |
486 | |
487 TEST(Toolbox, FixUtf8) | |
488 { | |
489 // This is a Latin-1 test string: "crane" with a circumflex accent | |
490 const unsigned char latin1[] = { 0x63, 0x72, 0xe2, 0x6e, 0x65 }; | |
491 | |
492 std::string s((char*) &latin1[0], sizeof(latin1) / sizeof(char)); | |
493 | |
494 ASSERT_EQ(s, Toolbox::ConvertFromUtf8(Toolbox::ConvertToUtf8(s, Encoding_Latin1, false), Encoding_Latin1)); | |
495 ASSERT_EQ("cre", Toolbox::ConvertToUtf8(s, Encoding_Utf8, false)); | |
496 } | |
497 | |
498 | |
499 static int32_t GetUnicode(const uint8_t* data, | |
500 size_t size, | |
501 size_t expectedLength) | |
502 { | |
503 std::string s((char*) &data[0], size); | |
504 uint32_t unicode; | |
505 size_t length; | |
506 Toolbox::Utf8ToUnicodeCharacter(unicode, length, s, 0); | |
507 if (length != expectedLength) | |
508 { | |
509 return -1; // Error case | |
510 } | |
511 else | |
512 { | |
513 return unicode; | |
514 } | |
515 } | |
516 | |
517 | |
518 TEST(Toolbox, Utf8ToUnicode) | |
519 { | |
520 // https://en.wikipedia.org/wiki/UTF-8 | |
521 | |
522 ASSERT_EQ(1u, sizeof(char)); | |
523 ASSERT_EQ(1u, sizeof(uint8_t)); | |
524 | |
525 { | |
526 const uint8_t data[] = { 0x24 }; | |
527 ASSERT_EQ(0x24, GetUnicode(data, 1, 1)); | |
528 ASSERT_THROW(GetUnicode(data, 0, 1), OrthancException); | |
529 } | |
530 | |
531 { | |
532 const uint8_t data[] = { 0xc2, 0xa2 }; | |
533 ASSERT_EQ(0xa2, GetUnicode(data, 2, 2)); | |
534 ASSERT_THROW(GetUnicode(data, 1, 2), OrthancException); | |
535 } | |
536 | |
537 { | |
538 const uint8_t data[] = { 0xe0, 0xa4, 0xb9 }; | |
539 ASSERT_EQ(0x0939, GetUnicode(data, 3, 3)); | |
540 ASSERT_THROW(GetUnicode(data, 2, 3), OrthancException); | |
541 } | |
542 | |
543 { | |
544 const uint8_t data[] = { 0xe2, 0x82, 0xac }; | |
545 ASSERT_EQ(0x20ac, GetUnicode(data, 3, 3)); | |
546 ASSERT_THROW(GetUnicode(data, 2, 3), OrthancException); | |
547 } | |
548 | |
549 { | |
550 const uint8_t data[] = { 0xf0, 0x90, 0x8d, 0x88 }; | |
551 ASSERT_EQ(0x010348, GetUnicode(data, 4, 4)); | |
552 ASSERT_THROW(GetUnicode(data, 3, 4), OrthancException); | |
553 } | |
554 | |
555 { | |
556 const uint8_t data[] = { 0xe0 }; | |
557 ASSERT_THROW(GetUnicode(data, 1, 1), OrthancException); | |
558 } | |
559 } | |
560 | |
561 | |
562 TEST(Toolbox, UrlDecode) | |
563 { | |
564 std::string s; | |
565 | |
566 s = "Hello%20World"; | |
567 Toolbox::UrlDecode(s); | |
568 ASSERT_EQ("Hello World", s); | |
569 | |
570 s = "%21%23%24%26%27%28%29%2A%2B%2c%2f%3A%3b%3d%3f%40%5B%5D%90%ff"; | |
571 Toolbox::UrlDecode(s); | |
572 std::string ss = "!#$&'()*+,/:;=?@[]"; | |
573 ss.push_back((char) 144); | |
574 ss.push_back((char) 255); | |
575 ASSERT_EQ(ss, s); | |
576 | |
577 s = "(2000%2C00A4)+Other"; | |
578 Toolbox::UrlDecode(s); | |
579 ASSERT_EQ("(2000,00A4) Other", s); | |
580 } | |
581 | |
582 | |
583 TEST(Toolbox, IsAsciiString) | |
584 { | |
585 std::string s = "Hello 12 /"; | |
586 ASSERT_EQ(10u, s.size()); | |
587 ASSERT_TRUE(Toolbox::IsAsciiString(s)); | |
588 ASSERT_TRUE(Toolbox::IsAsciiString(s.c_str(), 10)); | |
589 ASSERT_FALSE(Toolbox::IsAsciiString(s.c_str(), 11)); // Taking the trailing hidden '\0' | |
590 | |
591 s[2] = '\0'; | |
592 ASSERT_EQ(10u, s.size()); | |
593 ASSERT_FALSE(Toolbox::IsAsciiString(s)); | |
594 | |
595 ASSERT_TRUE(Toolbox::IsAsciiString("Hello\nworld")); | |
596 ASSERT_FALSE(Toolbox::IsAsciiString("Hello\rworld")); | |
597 | |
598 ASSERT_EQ("Hello\nworld", Toolbox::ConvertToAscii("Hello\nworld")); | |
599 ASSERT_EQ("Helloworld", Toolbox::ConvertToAscii("Hello\r\tworld")); | |
600 } | |
601 | |
602 | |
603 #if defined(__linux__) | |
604 TEST(Toolbox, AbsoluteDirectory) | |
605 { | |
606 ASSERT_EQ("/tmp/hello", SystemToolbox::InterpretRelativePath("/tmp", "hello")); | |
607 ASSERT_EQ("/tmp", SystemToolbox::InterpretRelativePath("/tmp", "/tmp")); | |
608 } | |
609 #endif | |
610 | |
611 | |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4234
diff
changeset
|
612 #if ORTHANC_SANDBOXED != 1 |
3987 | 613 TEST(Toolbox, WriteFile) |
614 { | |
615 std::string path; | |
616 | |
617 { | |
618 TemporaryFile tmp; | |
619 path = tmp.GetPath(); | |
620 | |
621 std::string s; | |
622 s.append("Hello"); | |
623 s.push_back('\0'); | |
624 s.append("World"); | |
625 ASSERT_EQ(11u, s.size()); | |
626 | |
627 SystemToolbox::WriteFile(s, path.c_str()); | |
628 | |
629 std::string t; | |
630 SystemToolbox::ReadFile(t, path.c_str()); | |
631 | |
632 ASSERT_EQ(11u, t.size()); | |
633 ASSERT_EQ(0, t[5]); | |
634 ASSERT_EQ(0, memcmp(s.c_str(), t.c_str(), s.size())); | |
635 | |
636 std::string h; | |
637 ASSERT_EQ(true, SystemToolbox::ReadHeader(h, path.c_str(), 1)); | |
638 ASSERT_EQ(1u, h.size()); | |
639 ASSERT_EQ('H', h[0]); | |
640 ASSERT_TRUE(SystemToolbox::ReadHeader(h, path.c_str(), 0)); | |
641 ASSERT_EQ(0u, h.size()); | |
642 ASSERT_FALSE(SystemToolbox::ReadHeader(h, path.c_str(), 32)); | |
643 ASSERT_EQ(11u, h.size()); | |
644 ASSERT_EQ(0, memcmp(s.c_str(), h.c_str(), s.size())); | |
645 } | |
646 | |
647 std::string u; | |
648 ASSERT_THROW(SystemToolbox::ReadFile(u, path.c_str()), OrthancException); | |
4186 | 649 |
650 { | |
651 TemporaryFile tmp; | |
652 std::string s = "Hello"; | |
653 SystemToolbox::WriteFile(s, tmp.GetPath(), true /* call fsync() */); | |
654 std::string t; | |
655 SystemToolbox::ReadFile(t, tmp.GetPath()); | |
656 ASSERT_EQ(s, t); | |
657 } | |
3987 | 658 } |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4234
diff
changeset
|
659 #endif |
3987 | 660 |
661 | |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4234
diff
changeset
|
662 #if ORTHANC_SANDBOXED != 1 |
3987 | 663 TEST(Toolbox, FileBuffer) |
664 { | |
665 FileBuffer f; | |
666 f.Append("a", 1); | |
667 f.Append("", 0); | |
668 f.Append("bc", 2); | |
669 | |
670 std::string s; | |
671 f.Read(s); | |
672 ASSERT_EQ("abc", s); | |
673 | |
674 ASSERT_THROW(f.Append("d", 1), OrthancException); // File is closed | |
675 } | |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4234
diff
changeset
|
676 #endif |
3987 | 677 |
678 | |
679 TEST(Toolbox, Wildcard) | |
680 { | |
681 ASSERT_EQ("abcd", Toolbox::WildcardToRegularExpression("abcd")); | |
682 ASSERT_EQ("ab.*cd", Toolbox::WildcardToRegularExpression("ab*cd")); | |
683 ASSERT_EQ("ab..cd", Toolbox::WildcardToRegularExpression("ab??cd")); | |
684 ASSERT_EQ("a.*b.c.*d", Toolbox::WildcardToRegularExpression("a*b?c*d")); | |
685 ASSERT_EQ("a\\{b\\]", Toolbox::WildcardToRegularExpression("a{b]")); | |
686 } | |
687 | |
688 | |
689 TEST(Toolbox, Tokenize) | |
690 { | |
691 std::vector<std::string> t; | |
692 | |
693 Toolbox::TokenizeString(t, "", ','); | |
694 ASSERT_EQ(1u, t.size()); | |
695 ASSERT_EQ("", t[0]); | |
696 | |
697 Toolbox::TokenizeString(t, "abc", ','); | |
698 ASSERT_EQ(1u, t.size()); | |
699 ASSERT_EQ("abc", t[0]); | |
700 | |
701 Toolbox::TokenizeString(t, "ab,cd,ef,", ','); | |
702 ASSERT_EQ(4u, t.size()); | |
703 ASSERT_EQ("ab", t[0]); | |
704 ASSERT_EQ("cd", t[1]); | |
705 ASSERT_EQ("ef", t[2]); | |
706 ASSERT_EQ("", t[3]); | |
707 } | |
708 | |
709 TEST(Toolbox, Enumerations) | |
710 { | |
711 ASSERT_EQ(Encoding_Utf8, StringToEncoding(EnumerationToString(Encoding_Utf8))); | |
712 ASSERT_EQ(Encoding_Ascii, StringToEncoding(EnumerationToString(Encoding_Ascii))); | |
713 ASSERT_EQ(Encoding_Latin1, StringToEncoding(EnumerationToString(Encoding_Latin1))); | |
714 ASSERT_EQ(Encoding_Latin2, StringToEncoding(EnumerationToString(Encoding_Latin2))); | |
715 ASSERT_EQ(Encoding_Latin3, StringToEncoding(EnumerationToString(Encoding_Latin3))); | |
716 ASSERT_EQ(Encoding_Latin4, StringToEncoding(EnumerationToString(Encoding_Latin4))); | |
717 ASSERT_EQ(Encoding_Latin5, StringToEncoding(EnumerationToString(Encoding_Latin5))); | |
718 ASSERT_EQ(Encoding_Cyrillic, StringToEncoding(EnumerationToString(Encoding_Cyrillic))); | |
719 ASSERT_EQ(Encoding_Arabic, StringToEncoding(EnumerationToString(Encoding_Arabic))); | |
720 ASSERT_EQ(Encoding_Greek, StringToEncoding(EnumerationToString(Encoding_Greek))); | |
721 ASSERT_EQ(Encoding_Hebrew, StringToEncoding(EnumerationToString(Encoding_Hebrew))); | |
722 ASSERT_EQ(Encoding_Japanese, StringToEncoding(EnumerationToString(Encoding_Japanese))); | |
723 ASSERT_EQ(Encoding_Chinese, StringToEncoding(EnumerationToString(Encoding_Chinese))); | |
724 ASSERT_EQ(Encoding_Thai, StringToEncoding(EnumerationToString(Encoding_Thai))); | |
725 ASSERT_EQ(Encoding_Korean, StringToEncoding(EnumerationToString(Encoding_Korean))); | |
726 ASSERT_EQ(Encoding_JapaneseKanji, StringToEncoding(EnumerationToString(Encoding_JapaneseKanji))); | |
727 ASSERT_EQ(Encoding_SimplifiedChinese, StringToEncoding(EnumerationToString(Encoding_SimplifiedChinese))); | |
728 | |
729 ASSERT_EQ(ResourceType_Patient, StringToResourceType(EnumerationToString(ResourceType_Patient))); | |
730 ASSERT_EQ(ResourceType_Study, StringToResourceType(EnumerationToString(ResourceType_Study))); | |
731 ASSERT_EQ(ResourceType_Series, StringToResourceType(EnumerationToString(ResourceType_Series))); | |
732 ASSERT_EQ(ResourceType_Instance, StringToResourceType(EnumerationToString(ResourceType_Instance))); | |
733 | |
734 ASSERT_EQ(ImageFormat_Png, StringToImageFormat(EnumerationToString(ImageFormat_Png))); | |
735 | |
736 ASSERT_EQ(PhotometricInterpretation_ARGB, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_ARGB))); | |
737 ASSERT_EQ(PhotometricInterpretation_CMYK, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_CMYK))); | |
738 ASSERT_EQ(PhotometricInterpretation_HSV, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_HSV))); | |
739 ASSERT_EQ(PhotometricInterpretation_Monochrome1, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_Monochrome1))); | |
740 ASSERT_EQ(PhotometricInterpretation_Monochrome2, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_Monochrome2))); | |
741 ASSERT_EQ(PhotometricInterpretation_Palette, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_Palette))); | |
742 ASSERT_EQ(PhotometricInterpretation_RGB, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_RGB))); | |
743 ASSERT_EQ(PhotometricInterpretation_YBRFull, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_YBRFull))); | |
744 ASSERT_EQ(PhotometricInterpretation_YBRFull422, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_YBRFull422))); | |
745 ASSERT_EQ(PhotometricInterpretation_YBRPartial420, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_YBRPartial420))); | |
746 ASSERT_EQ(PhotometricInterpretation_YBRPartial422, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_YBRPartial422))); | |
747 ASSERT_EQ(PhotometricInterpretation_YBR_ICT, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_YBR_ICT))); | |
748 ASSERT_EQ(PhotometricInterpretation_YBR_RCT, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_YBR_RCT))); | |
749 | |
750 ASSERT_STREQ("Unknown", EnumerationToString(PhotometricInterpretation_Unknown)); | |
751 ASSERT_THROW(StringToPhotometricInterpretation("Unknown"), OrthancException); | |
752 | |
753 ASSERT_EQ(DicomVersion_2008, StringToDicomVersion(EnumerationToString(DicomVersion_2008))); | |
754 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
|
755 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
|
756 ASSERT_EQ(DicomVersion_2023b, StringToDicomVersion(EnumerationToString(DicomVersion_2023b))); |
3987 | 757 |
758 for (int i = static_cast<int>(ValueRepresentation_ApplicationEntity); | |
759 i < static_cast<int>(ValueRepresentation_NotSupported); i += 1) | |
760 { | |
761 ValueRepresentation vr = static_cast<ValueRepresentation>(i); | |
762 ASSERT_EQ(vr, StringToValueRepresentation(EnumerationToString(vr), true)); | |
763 } | |
764 | |
765 ASSERT_THROW(StringToValueRepresentation("nope", true), OrthancException); | |
766 | |
767 ASSERT_EQ(JobState_Pending, StringToJobState(EnumerationToString(JobState_Pending))); | |
768 ASSERT_EQ(JobState_Running, StringToJobState(EnumerationToString(JobState_Running))); | |
769 ASSERT_EQ(JobState_Success, StringToJobState(EnumerationToString(JobState_Success))); | |
770 ASSERT_EQ(JobState_Failure, StringToJobState(EnumerationToString(JobState_Failure))); | |
771 ASSERT_EQ(JobState_Paused, StringToJobState(EnumerationToString(JobState_Paused))); | |
772 ASSERT_EQ(JobState_Retry, StringToJobState(EnumerationToString(JobState_Retry))); | |
773 ASSERT_THROW(StringToJobState("nope"), OrthancException); | |
774 | |
775 ASSERT_EQ(MimeType_Binary, StringToMimeType(EnumerationToString(MimeType_Binary))); | |
776 ASSERT_EQ(MimeType_Css, StringToMimeType(EnumerationToString(MimeType_Css))); | |
777 ASSERT_EQ(MimeType_Dicom, StringToMimeType(EnumerationToString(MimeType_Dicom))); | |
778 ASSERT_EQ(MimeType_Gif, StringToMimeType(EnumerationToString(MimeType_Gif))); | |
779 ASSERT_EQ(MimeType_Gzip, StringToMimeType(EnumerationToString(MimeType_Gzip))); | |
780 ASSERT_EQ(MimeType_Html, StringToMimeType(EnumerationToString(MimeType_Html))); | |
781 ASSERT_EQ(MimeType_JavaScript, StringToMimeType(EnumerationToString(MimeType_JavaScript))); | |
782 ASSERT_EQ(MimeType_Jpeg, StringToMimeType(EnumerationToString(MimeType_Jpeg))); | |
783 ASSERT_EQ(MimeType_Jpeg2000, StringToMimeType(EnumerationToString(MimeType_Jpeg2000))); | |
784 ASSERT_EQ(MimeType_Json, StringToMimeType(EnumerationToString(MimeType_Json))); | |
785 ASSERT_EQ(MimeType_NaCl, StringToMimeType(EnumerationToString(MimeType_NaCl))); | |
786 ASSERT_EQ(MimeType_PNaCl, StringToMimeType(EnumerationToString(MimeType_PNaCl))); | |
787 ASSERT_EQ(MimeType_Pam, StringToMimeType(EnumerationToString(MimeType_Pam))); | |
788 ASSERT_EQ(MimeType_Pdf, StringToMimeType(EnumerationToString(MimeType_Pdf))); | |
789 ASSERT_EQ(MimeType_PlainText, StringToMimeType(EnumerationToString(MimeType_PlainText))); | |
790 ASSERT_EQ(MimeType_Png, StringToMimeType(EnumerationToString(MimeType_Png))); | |
791 ASSERT_EQ(MimeType_Svg, StringToMimeType(EnumerationToString(MimeType_Svg))); | |
792 ASSERT_EQ(MimeType_WebAssembly, StringToMimeType(EnumerationToString(MimeType_WebAssembly))); | |
793 ASSERT_EQ(MimeType_Xml, StringToMimeType("application/xml")); | |
794 ASSERT_EQ(MimeType_Xml, StringToMimeType("text/xml")); | |
795 ASSERT_EQ(MimeType_Xml, StringToMimeType(EnumerationToString(MimeType_Xml))); | |
796 ASSERT_EQ(MimeType_DicomWebJson, StringToMimeType(EnumerationToString(MimeType_DicomWebJson))); | |
797 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
|
798 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
|
799 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
|
800 ASSERT_EQ(MimeType_Stl, StringToMimeType(EnumerationToString(MimeType_Stl))); |
3987 | 801 ASSERT_THROW(StringToMimeType("nope"), OrthancException); |
802 | |
803 ASSERT_TRUE(IsResourceLevelAboveOrEqual(ResourceType_Patient, ResourceType_Patient)); | |
804 ASSERT_TRUE(IsResourceLevelAboveOrEqual(ResourceType_Patient, ResourceType_Study)); | |
805 ASSERT_TRUE(IsResourceLevelAboveOrEqual(ResourceType_Patient, ResourceType_Series)); | |
806 ASSERT_TRUE(IsResourceLevelAboveOrEqual(ResourceType_Patient, ResourceType_Instance)); | |
807 | |
808 ASSERT_FALSE(IsResourceLevelAboveOrEqual(ResourceType_Study, ResourceType_Patient)); | |
809 ASSERT_TRUE(IsResourceLevelAboveOrEqual(ResourceType_Study, ResourceType_Study)); | |
810 ASSERT_TRUE(IsResourceLevelAboveOrEqual(ResourceType_Study, ResourceType_Series)); | |
811 ASSERT_TRUE(IsResourceLevelAboveOrEqual(ResourceType_Study, ResourceType_Instance)); | |
812 | |
813 ASSERT_FALSE(IsResourceLevelAboveOrEqual(ResourceType_Series, ResourceType_Patient)); | |
814 ASSERT_FALSE(IsResourceLevelAboveOrEqual(ResourceType_Series, ResourceType_Study)); | |
815 ASSERT_TRUE(IsResourceLevelAboveOrEqual(ResourceType_Series, ResourceType_Series)); | |
816 ASSERT_TRUE(IsResourceLevelAboveOrEqual(ResourceType_Series, ResourceType_Instance)); | |
817 | |
818 ASSERT_FALSE(IsResourceLevelAboveOrEqual(ResourceType_Instance, ResourceType_Patient)); | |
819 ASSERT_FALSE(IsResourceLevelAboveOrEqual(ResourceType_Instance, ResourceType_Study)); | |
820 ASSERT_FALSE(IsResourceLevelAboveOrEqual(ResourceType_Instance, ResourceType_Series)); | |
821 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
|
822 |
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
|
823 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
|
824 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
|
825 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
|
826 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
|
827 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
|
828 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
|
829 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
|
830 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
|
831 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
|
832 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
|
833 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
|
834 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
|
835 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
|
836 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
|
837 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
|
838 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
|
839 |
9210e196cd98
unit test for transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4622
diff
changeset
|
840 DicomTransferSyntax ts; |
9210e196cd98
unit test for transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4622
diff
changeset
|
841 ASSERT_FALSE(LookupTransferSyntax(ts, "nope")); |
9210e196cd98
unit test for transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4622
diff
changeset
|
842 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
|
843 ASSERT_STREQ("1.2.840.10008.1.2", GetTransferSyntaxUid(ts)); |
3987 | 844 } |
845 | |
846 | |
847 #if defined(__linux__) || defined(__OpenBSD__) | |
848 #include <endian.h> | |
849 #elif defined(__FreeBSD__) | |
850 #include <machine/endian.h> | |
851 #endif | |
852 | |
853 | |
854 TEST(Toolbox, Endianness) | |
855 { | |
856 // Parts of this test come from Adam Conrad | |
857 // http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=728822#5 | |
858 | |
859 | |
860 /** | |
861 * Windows and OS X are assumed to always little-endian. | |
862 **/ | |
863 | |
864 #if defined(_WIN32) || defined(__APPLE__) | |
865 ASSERT_EQ(Endianness_Little, Toolbox::DetectEndianness()); | |
866 | |
867 | |
868 /** | |
869 * FreeBSD. | |
870 **/ | |
871 | |
872 #elif defined(__FreeBSD__) || defined(__OpenBSD__) | |
873 # if _BYTE_ORDER == _BIG_ENDIAN | |
874 ASSERT_EQ(Endianness_Big, Toolbox::DetectEndianness()); | |
875 # else // _LITTLE_ENDIAN | |
876 ASSERT_EQ(Endianness_Little, Toolbox::DetectEndianness()); | |
877 # endif | |
878 | |
879 | |
880 /** | |
881 * Linux. | |
882 **/ | |
883 | |
884 #elif defined(__linux__) || defined(__FreeBSD_kernel__) | |
885 | |
886 #if !defined(__BYTE_ORDER) | |
887 # error Support your platform here | |
888 #endif | |
889 | |
890 # if __BYTE_ORDER == __BIG_ENDIAN | |
891 ASSERT_EQ(Endianness_Big, Toolbox::DetectEndianness()); | |
892 # else // __LITTLE_ENDIAN | |
893 ASSERT_EQ(Endianness_Little, Toolbox::DetectEndianness()); | |
894 # endif | |
895 | |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4234
diff
changeset
|
896 |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4234
diff
changeset
|
897 /** |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4234
diff
changeset
|
898 * WebAssembly is always little-endian. |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4234
diff
changeset
|
899 **/ |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4234
diff
changeset
|
900 |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4234
diff
changeset
|
901 #elif defined(__EMSCRIPTEN__) |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4234
diff
changeset
|
902 ASSERT_EQ(Endianness_Little, Toolbox::DetectEndianness()); |
3987 | 903 #else |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4234
diff
changeset
|
904 # error Support your platform here |
3987 | 905 #endif |
906 } | |
907 | |
908 | |
4045 | 909 #include "../Sources/Endianness.h" |
3987 | 910 |
911 static void ASSERT_EQ16(uint16_t a, uint16_t b) | |
912 { | |
913 #ifdef __MINGW32__ | |
914 // This cast solves a linking problem with MinGW | |
915 ASSERT_EQ(static_cast<unsigned int>(a), static_cast<unsigned int>(b)); | |
916 #else | |
917 ASSERT_EQ(a, b); | |
918 #endif | |
919 } | |
920 | |
921 static void ASSERT_NE16(uint16_t a, uint16_t b) | |
922 { | |
923 #ifdef __MINGW32__ | |
924 // This cast solves a linking problem with MinGW | |
925 ASSERT_NE(static_cast<unsigned int>(a), static_cast<unsigned int>(b)); | |
926 #else | |
927 ASSERT_NE(a, b); | |
928 #endif | |
929 } | |
930 | |
931 static void ASSERT_EQ32(uint32_t a, uint32_t b) | |
932 { | |
933 #ifdef __MINGW32__ | |
934 // This cast solves a linking problem with MinGW | |
935 ASSERT_EQ(static_cast<unsigned int>(a), static_cast<unsigned int>(b)); | |
936 #else | |
937 ASSERT_EQ(a, b); | |
938 #endif | |
939 } | |
940 | |
941 static void ASSERT_NE32(uint32_t a, uint32_t b) | |
942 { | |
943 #ifdef __MINGW32__ | |
944 // This cast solves a linking problem with MinGW | |
945 ASSERT_NE(static_cast<unsigned int>(a), static_cast<unsigned int>(b)); | |
946 #else | |
947 ASSERT_NE(a, b); | |
948 #endif | |
949 } | |
950 | |
951 static void ASSERT_EQ64(uint64_t a, uint64_t b) | |
952 { | |
953 #ifdef __MINGW32__ | |
954 // This cast solves a linking problem with MinGW | |
955 ASSERT_EQ(static_cast<unsigned int>(a), static_cast<unsigned int>(b)); | |
956 #else | |
957 ASSERT_EQ(a, b); | |
958 #endif | |
959 } | |
960 | |
961 static void ASSERT_NE64(uint64_t a, uint64_t b) | |
962 { | |
963 #ifdef __MINGW32__ | |
964 // This cast solves a linking problem with MinGW | |
965 ASSERT_NE(static_cast<unsigned long long>(a), static_cast<unsigned long long>(b)); | |
966 #else | |
967 ASSERT_NE(a, b); | |
968 #endif | |
969 } | |
970 | |
971 | |
972 | |
973 TEST(Toolbox, EndiannessConversions16) | |
974 { | |
975 Endianness e = Toolbox::DetectEndianness(); | |
976 | |
977 for (unsigned int i = 0; i < 65536; i += 17) | |
978 { | |
979 uint16_t v = static_cast<uint16_t>(i); | |
980 ASSERT_EQ16(v, be16toh(htobe16(v))); | |
981 ASSERT_EQ16(v, le16toh(htole16(v))); | |
982 | |
983 const uint8_t* bytes = reinterpret_cast<const uint8_t*>(&v); | |
984 if (bytes[0] != bytes[1]) | |
985 { | |
986 ASSERT_NE16(v, le16toh(htobe16(v))); | |
987 ASSERT_NE16(v, be16toh(htole16(v))); | |
988 } | |
989 else | |
990 { | |
991 ASSERT_EQ16(v, le16toh(htobe16(v))); | |
992 ASSERT_EQ16(v, be16toh(htole16(v))); | |
993 } | |
994 | |
995 switch (e) | |
996 { | |
997 case Endianness_Little: | |
998 ASSERT_EQ16(v, htole16(v)); | |
999 if (bytes[0] != bytes[1]) | |
1000 { | |
1001 ASSERT_NE16(v, htobe16(v)); | |
1002 } | |
1003 else | |
1004 { | |
1005 ASSERT_EQ16(v, htobe16(v)); | |
1006 } | |
1007 break; | |
1008 | |
1009 case Endianness_Big: | |
1010 ASSERT_EQ16(v, htobe16(v)); | |
1011 if (bytes[0] != bytes[1]) | |
1012 { | |
1013 ASSERT_NE16(v, htole16(v)); | |
1014 } | |
1015 else | |
1016 { | |
1017 ASSERT_EQ16(v, htole16(v)); | |
1018 } | |
1019 break; | |
1020 | |
1021 default: | |
1022 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
1023 } | |
1024 } | |
1025 } | |
1026 | |
1027 | |
1028 TEST(Toolbox, EndiannessConversions32) | |
1029 { | |
1030 const uint32_t v = 0xff010203u; | |
1031 const uint32_t r = 0x030201ffu; | |
1032 ASSERT_EQ32(v, be32toh(htobe32(v))); | |
1033 ASSERT_EQ32(v, le32toh(htole32(v))); | |
1034 ASSERT_NE32(v, be32toh(htole32(v))); | |
1035 ASSERT_NE32(v, le32toh(htobe32(v))); | |
1036 | |
1037 switch (Toolbox::DetectEndianness()) | |
1038 { | |
1039 case Endianness_Little: | |
1040 ASSERT_EQ32(r, htobe32(v)); | |
1041 ASSERT_EQ32(v, htole32(v)); | |
1042 ASSERT_EQ32(r, be32toh(v)); | |
1043 ASSERT_EQ32(v, le32toh(v)); | |
1044 break; | |
1045 | |
1046 case Endianness_Big: | |
1047 ASSERT_EQ32(v, htobe32(v)); | |
1048 ASSERT_EQ32(r, htole32(v)); | |
1049 ASSERT_EQ32(v, be32toh(v)); | |
1050 ASSERT_EQ32(r, le32toh(v)); | |
1051 break; | |
1052 | |
1053 default: | |
1054 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
1055 } | |
1056 } | |
1057 | |
1058 | |
1059 TEST(Toolbox, EndiannessConversions64) | |
1060 { | |
1061 const uint64_t v = 0xff01020304050607LL; | |
1062 const uint64_t r = 0x07060504030201ffLL; | |
1063 ASSERT_EQ64(v, be64toh(htobe64(v))); | |
1064 ASSERT_EQ64(v, le64toh(htole64(v))); | |
1065 ASSERT_NE64(v, be64toh(htole64(v))); | |
1066 ASSERT_NE64(v, le64toh(htobe64(v))); | |
1067 | |
1068 switch (Toolbox::DetectEndianness()) | |
1069 { | |
1070 case Endianness_Little: | |
1071 ASSERT_EQ64(r, htobe64(v)); | |
1072 ASSERT_EQ64(v, htole64(v)); | |
1073 ASSERT_EQ64(r, be64toh(v)); | |
1074 ASSERT_EQ64(v, le64toh(v)); | |
1075 break; | |
1076 | |
1077 case Endianness_Big: | |
1078 ASSERT_EQ64(v, htobe64(v)); | |
1079 ASSERT_EQ64(r, htole64(v)); | |
1080 ASSERT_EQ64(v, be64toh(v)); | |
1081 ASSERT_EQ64(r, le64toh(v)); | |
1082 break; | |
1083 | |
1084 default: | |
1085 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
1086 } | |
1087 } | |
1088 | |
1089 | |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4234
diff
changeset
|
1090 #if ORTHANC_SANDBOXED != 1 |
3987 | 1091 TEST(Toolbox, Now) |
1092 { | |
1093 LOG(WARNING) << "Local time: " << SystemToolbox::GetNowIsoString(false); | |
1094 LOG(WARNING) << "Universal time: " << SystemToolbox::GetNowIsoString(true); | |
1095 | |
1096 std::string date, time; | |
1097 SystemToolbox::GetNowDicom(date, time, false); | |
1098 LOG(WARNING) << "Local DICOM time: [" << date << "] [" << time << "]"; | |
1099 | |
1100 SystemToolbox::GetNowDicom(date, time, true); | |
1101 LOG(WARNING) << "Universal DICOM time: [" << date << "] [" << time << "]"; | |
1102 } | |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4234
diff
changeset
|
1103 #endif |
3987 | 1104 |
1105 | |
1106 #if ORTHANC_ENABLE_PUGIXML == 1 | |
1107 TEST(Toolbox, Xml) | |
1108 { | |
1109 Json::Value a; | |
1110 a["hello"] = "world"; | |
1111 a["42"] = 43; | |
1112 a["b"] = Json::arrayValue; | |
1113 a["b"].append("test"); | |
1114 a["b"].append("test2"); | |
1115 | |
1116 std::string s; | |
1117 Toolbox::JsonToXml(s, a); | |
1118 | |
1119 std::cout << s; | |
1120 } | |
1121 #endif | |
1122 | |
1123 | |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4234
diff
changeset
|
1124 #if !defined(_WIN32) && (ORTHANC_SANDBOXED != 1) |
3987 | 1125 TEST(Toolbox, ExecuteSystemCommand) |
1126 { | |
1127 std::vector<std::string> args(2); | |
1128 args[0] = "Hello"; | |
1129 args[1] = "World"; | |
1130 | |
1131 SystemToolbox::ExecuteSystemCommand("echo", args); | |
1132 } | |
1133 #endif | |
1134 | |
1135 | |
1136 TEST(Toolbox, IsInteger) | |
1137 { | |
1138 ASSERT_TRUE(Toolbox::IsInteger("00236")); | |
1139 ASSERT_TRUE(Toolbox::IsInteger("-0042")); | |
1140 ASSERT_TRUE(Toolbox::IsInteger("0")); | |
1141 ASSERT_TRUE(Toolbox::IsInteger("-0")); | |
1142 | |
1143 ASSERT_FALSE(Toolbox::IsInteger("")); | |
1144 ASSERT_FALSE(Toolbox::IsInteger("42a")); | |
1145 ASSERT_FALSE(Toolbox::IsInteger("42-")); | |
1146 } | |
1147 | |
1148 | |
1149 TEST(Toolbox, StartsWith) | |
1150 { | |
1151 ASSERT_TRUE(Toolbox::StartsWith("hello world", "")); | |
1152 ASSERT_TRUE(Toolbox::StartsWith("hello world", "hello")); | |
1153 ASSERT_TRUE(Toolbox::StartsWith("hello world", "h")); | |
1154 ASSERT_FALSE(Toolbox::StartsWith("hello world", "H")); | |
1155 ASSERT_FALSE(Toolbox::StartsWith("h", "hello")); | |
1156 ASSERT_TRUE(Toolbox::StartsWith("h", "h")); | |
1157 ASSERT_FALSE(Toolbox::StartsWith("", "h")); | |
1158 } | |
1159 | |
1160 | |
1161 TEST(Toolbox, UriEncode) | |
1162 { | |
1163 std::string s; | |
1164 | |
1165 // Unreserved characters must not be modified | |
1166 std::string t = "aAzZ09.-~_"; | |
1167 Toolbox::UriEncode(s, t); | |
1168 ASSERT_EQ(t, s); | |
1169 | |
4234
a38376b80cd1
WebDAV: by-studies and by-patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4186
diff
changeset
|
1170 Toolbox::UriEncode(s, "!#$&'()*+,/:;=?@[]"); ASSERT_EQ("%21%23%24%26%27%28%29%2A%2B%2C/%3A%3B%3D%3F%40%5B%5D", s); |
3987 | 1171 Toolbox::UriEncode(s, "%"); ASSERT_EQ("%25", s); |
1172 | |
1173 // Encode characters from UTF-8. This is the test string from the | |
1174 // file "../Resources/EncodingTests.py" | |
1175 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"); | |
1176 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); | |
1177 } | |
1178 | |
1179 | |
1180 TEST(Toolbox, AccessJson) | |
1181 { | |
1182 Json::Value v = Json::arrayValue; | |
1183 ASSERT_EQ("nope", Toolbox::GetJsonStringField(v, "hello", "nope")); | |
1184 | |
1185 v = Json::objectValue; | |
1186 ASSERT_EQ("nope", Toolbox::GetJsonStringField(v, "hello", "nope")); | |
1187 ASSERT_EQ(-10, Toolbox::GetJsonIntegerField(v, "hello", -10)); | |
1188 ASSERT_EQ(10u, Toolbox::GetJsonUnsignedIntegerField(v, "hello", 10)); | |
1189 ASSERT_TRUE(Toolbox::GetJsonBooleanField(v, "hello", true)); | |
1190 | |
1191 v["hello"] = "world"; | |
1192 ASSERT_EQ("world", Toolbox::GetJsonStringField(v, "hello", "nope")); | |
1193 ASSERT_THROW(Toolbox::GetJsonIntegerField(v, "hello", -10), OrthancException); | |
1194 ASSERT_THROW(Toolbox::GetJsonUnsignedIntegerField(v, "hello", 10), OrthancException); | |
1195 ASSERT_THROW(Toolbox::GetJsonBooleanField(v, "hello", true), OrthancException); | |
1196 | |
1197 v["hello"] = -42; | |
1198 ASSERT_THROW(Toolbox::GetJsonStringField(v, "hello", "nope"), OrthancException); | |
1199 ASSERT_EQ(-42, Toolbox::GetJsonIntegerField(v, "hello", -10)); | |
1200 ASSERT_THROW(Toolbox::GetJsonUnsignedIntegerField(v, "hello", 10), OrthancException); | |
1201 ASSERT_THROW(Toolbox::GetJsonBooleanField(v, "hello", true), OrthancException); | |
1202 | |
1203 v["hello"] = 42; | |
1204 ASSERT_THROW(Toolbox::GetJsonStringField(v, "hello", "nope"), OrthancException); | |
1205 ASSERT_EQ(42, Toolbox::GetJsonIntegerField(v, "hello", -10)); | |
1206 ASSERT_EQ(42u, Toolbox::GetJsonUnsignedIntegerField(v, "hello", 10)); | |
1207 ASSERT_THROW(Toolbox::GetJsonBooleanField(v, "hello", true), OrthancException); | |
1208 | |
1209 v["hello"] = false; | |
1210 ASSERT_THROW(Toolbox::GetJsonStringField(v, "hello", "nope"), OrthancException); | |
1211 ASSERT_THROW(Toolbox::GetJsonIntegerField(v, "hello", -10), OrthancException); | |
1212 ASSERT_THROW(Toolbox::GetJsonUnsignedIntegerField(v, "hello", 10), OrthancException); | |
1213 ASSERT_FALSE(Toolbox::GetJsonBooleanField(v, "hello", true)); | |
1214 } | |
1215 | |
1216 | |
1217 TEST(Toolbox, LinesIterator) | |
1218 { | |
1219 std::string s; | |
1220 | |
1221 { | |
1222 std::string content; | |
1223 Toolbox::LinesIterator it(content); | |
1224 ASSERT_FALSE(it.GetLine(s)); | |
1225 } | |
1226 | |
1227 { | |
1228 std::string content = "\n\r"; | |
1229 Toolbox::LinesIterator it(content); | |
1230 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s); | |
1231 ASSERT_FALSE(it.GetLine(s)); | |
1232 } | |
1233 | |
1234 { | |
1235 std::string content = "\n Hello \n\nWorld\n\n"; | |
1236 Toolbox::LinesIterator it(content); | |
1237 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s); | |
1238 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ(" Hello ", s); | |
1239 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s); | |
1240 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("World", s); | |
1241 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s); | |
1242 ASSERT_FALSE(it.GetLine(s)); it.Next(); | |
1243 ASSERT_FALSE(it.GetLine(s)); | |
1244 } | |
1245 | |
1246 { | |
1247 std::string content = "\r Hello \r\rWorld\r\r"; | |
1248 Toolbox::LinesIterator it(content); | |
1249 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s); | |
1250 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ(" Hello ", s); | |
1251 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s); | |
1252 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("World", s); | |
1253 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s); | |
1254 ASSERT_FALSE(it.GetLine(s)); it.Next(); | |
1255 ASSERT_FALSE(it.GetLine(s)); | |
1256 } | |
1257 | |
1258 { | |
1259 std::string content = "\n\r Hello \n\r\n\rWorld\n\r\n\r"; | |
1260 Toolbox::LinesIterator it(content); | |
1261 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s); | |
1262 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ(" Hello ", s); | |
1263 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s); | |
1264 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("World", s); | |
1265 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s); | |
1266 ASSERT_FALSE(it.GetLine(s)); it.Next(); | |
1267 ASSERT_FALSE(it.GetLine(s)); | |
1268 } | |
1269 | |
1270 { | |
1271 std::string content = "\r\n Hello \r\n\r\nWorld\r\n\r\n"; | |
1272 Toolbox::LinesIterator it(content); | |
1273 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s); | |
1274 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ(" Hello ", s); | |
1275 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s); | |
1276 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("World", s); | |
1277 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s); | |
1278 ASSERT_FALSE(it.GetLine(s)); it.Next(); | |
1279 ASSERT_FALSE(it.GetLine(s)); | |
1280 } | |
1281 } | |
1282 | |
1283 | |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4234
diff
changeset
|
1284 #if ORTHANC_SANDBOXED != 1 |
3987 | 1285 TEST(Toolbox, SubstituteVariables) |
1286 { | |
1287 std::map<std::string, std::string> env; | |
1288 env["NOPE"] = "nope"; | |
1289 env["WORLD"] = "world"; | |
1290 | |
1291 ASSERT_EQ("Hello world\r\nWorld \r\nDone world\r\n", | |
1292 Toolbox::SubstituteVariables( | |
1293 "Hello ${WORLD}\r\nWorld ${HELLO}\r\nDone ${WORLD}\r\n", | |
1294 env)); | |
1295 | |
1296 ASSERT_EQ("world A a B world C 'c' D {\"a\":\"b\"} E ", | |
1297 Toolbox::SubstituteVariables( | |
1298 "${WORLD} A ${WORLD2:-a} B ${WORLD:-b} C ${WORLD2:-\"'c'\"} D ${WORLD2:-'{\"a\":\"b\"}'} E ${WORLD2:-}", | |
1299 env)); | |
1300 | |
1301 SystemToolbox::GetEnvironmentVariables(env); | |
1302 ASSERT_TRUE(env.find("NOPE") == env.end()); | |
1303 | |
1304 // The "PATH" environment variable should always be available on | |
1305 // machines running the unit tests | |
1306 ASSERT_TRUE(env.find("PATH") != env.end() /* Case used by UNIX */ || | |
1307 env.find("Path") != env.end() /* Case used by Windows */); | |
1308 | |
1309 env["PATH"] = "hello"; | |
1310 ASSERT_EQ("AhelloB", | |
1311 Toolbox::SubstituteVariables("A${PATH}B", env)); | |
1312 } | |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4234
diff
changeset
|
1313 #endif |
3987 | 1314 |
1315 | |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4234
diff
changeset
|
1316 #if ORTHANC_SANDBOXED != 1 |
3987 | 1317 TEST(MetricsRegistry, Basic) |
1318 { | |
1319 { | |
1320 MetricsRegistry m; | |
1321 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
|
1322 m.SetIntegerValue("hello.world", 42); |
3987 | 1323 |
1324 std::string s; | |
1325 m.ExportPrometheusText(s); | |
1326 ASSERT_TRUE(s.empty()); | |
1327 } | |
1328 | |
1329 { | |
1330 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
|
1331 m.Register("hello.world", MetricsUpdatePolicy_Directly, MetricsDataType_Integer); |
3987 | 1332 |
1333 std::string s; | |
1334 m.ExportPrometheusText(s); | |
1335 ASSERT_TRUE(s.empty()); | |
1336 } | |
1337 | |
1338 { | |
1339 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
|
1340 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
|
1341 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
|
1342 ASSERT_THROW(m.GetUpdatePolicy("nope"), OrthancException); |
3987 | 1343 |
1344 std::string s; | |
1345 m.ExportPrometheusText(s); | |
1346 | |
1347 std::vector<std::string> t; | |
1348 Toolbox::TokenizeString(t, s, '\n'); | |
1349 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
|
1350 ASSERT_EQ("hello.world -42 ", t[0].substr(0, 16)); |
3987 | 1351 ASSERT_TRUE(t[1].empty()); |
1352 } | |
1353 | |
1354 { | |
1355 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
|
1356 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
|
1357 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
|
1358 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
|
1359 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
|
1360 m.SetIntegerValue("hello.max", 5); |
3987 | 1361 |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1362 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
|
1363 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
|
1364 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
|
1365 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
|
1366 m.SetIntegerValue("hello.min", 5); |
3987 | 1367 |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1368 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
|
1369 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
|
1370 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
|
1371 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
|
1372 m.SetIntegerValue("hello.directly", 5); |
3987 | 1373 |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1374 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
|
1375 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
|
1376 ASSERT_EQ(MetricsUpdatePolicy_Directly, m.GetUpdatePolicy("hello.directly")); |
3987 | 1377 |
1378 std::string s; | |
1379 m.ExportPrometheusText(s); | |
1380 | |
1381 std::vector<std::string> t; | |
1382 Toolbox::TokenizeString(t, s, '\n'); | |
1383 ASSERT_EQ(4u, t.size()); | |
1384 ASSERT_TRUE(t[3].empty()); | |
1385 | |
1386 std::map<std::string, std::string> u; | |
1387 for (size_t i = 0; i < t.size() - 1; i++) | |
1388 { | |
1389 std::vector<std::string> v; | |
1390 Toolbox::TokenizeString(v, t[i], ' '); | |
1391 u[v[0]] = v[1]; | |
1392 } | |
1393 | |
1394 ASSERT_EQ("20", u["hello.max"]); | |
1395 ASSERT_EQ("-10", u["hello.min"]); | |
5336
dd9795dc380d
renamed MetricsType as MetricsUpdate to clarify
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5334
diff
changeset
|
1396 ASSERT_EQ("5", u["hello.directly"]); |
3987 | 1397 } |
1398 | |
1399 { | |
1400 MetricsRegistry m; | |
1401 | |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1402 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
|
1403 m.SetIntegerValue("b", 10, MetricsUpdatePolicy_MinOver10Seconds); |
3987 | 1404 |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1405 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
|
1406 m.SetIntegerValue("c", 10, MetricsUpdatePolicy_MinOver10Seconds); |
3987 | 1407 |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1408 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
|
1409 ASSERT_THROW(m.Register("d", MetricsUpdatePolicy_Directly, MetricsDataType_Integer), OrthancException); |
3987 | 1410 |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1411 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
|
1412 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
|
1413 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
|
1414 ASSERT_EQ(MetricsUpdatePolicy_MaxOver10Seconds, m.GetUpdatePolicy("d")); |
3987 | 1415 } |
1416 | |
1417 { | |
1418 MetricsRegistry m; | |
1419 | |
1420 { | |
1421 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
|
1422 MetricsRegistry::Timer t2(m, "b", MetricsUpdatePolicy_MinOver10Seconds); |
3987 | 1423 } |
1424 | |
5337
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1425 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
|
1426 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
|
1427 } |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1428 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1429 { |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1430 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
|
1431 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
|
1432 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
|
1433 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1434 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
|
1435 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
|
1436 } |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1437 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1438 { |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1439 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
|
1440 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
|
1441 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
|
1442 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1443 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
|
1444 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
|
1445 } |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1446 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1447 { |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1448 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
|
1449 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
|
1450 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
|
1451 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1452 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
|
1453 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
|
1454 } |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1455 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1456 { |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1457 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
|
1458 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
|
1459 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
|
1460 |
b376abae664a
Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5336
diff
changeset
|
1461 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
|
1462 ASSERT_EQ(MetricsDataType_Integer, m.GetDataType("c")); |
3987 | 1463 } |
1464 } | |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4234
diff
changeset
|
1465 #endif |
4342
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1466 |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1467 |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1468 #if ORTHANC_SANDBOXED != 1 |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1469 TEST(Toolbox, ReadFileRange) |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1470 { |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1471 TemporaryFile tmp; |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1472 std::string s; |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1473 |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1474 tmp.Write(""); |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1475 tmp.Read(s); ASSERT_TRUE(s.empty()); |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1476 tmp.ReadRange(s, 0, 0, true); ASSERT_TRUE(s.empty()); |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1477 tmp.ReadRange(s, 0, 10, false); ASSERT_TRUE(s.empty()); |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1478 |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1479 ASSERT_THROW(tmp.ReadRange(s, 0, 1, true), OrthancException); |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1480 |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1481 tmp.Write("Hello"); |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1482 tmp.Read(s); ASSERT_EQ("Hello", s); |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1483 tmp.ReadRange(s, 0, 5, true); ASSERT_EQ("Hello", s); |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1484 tmp.ReadRange(s, 0, 1, true); ASSERT_EQ("H", s); |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1485 tmp.ReadRange(s, 1, 2, true); ASSERT_EQ("e", s); |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1486 tmp.ReadRange(s, 2, 3, true); ASSERT_EQ("l", s); |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1487 tmp.ReadRange(s, 3, 4, true); ASSERT_EQ("l", s); |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1488 tmp.ReadRange(s, 4, 5, true); ASSERT_EQ("o", s); |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1489 tmp.ReadRange(s, 2, 5, true); ASSERT_EQ("llo", s); |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1490 tmp.ReadRange(s, 2, 50, false); ASSERT_EQ("llo", s); |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1491 tmp.ReadRange(s, 2, 2, false); ASSERT_TRUE(s.empty()); |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1492 tmp.ReadRange(s, 10, 50, false); ASSERT_TRUE(s.empty()); |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1493 |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1494 ASSERT_THROW(tmp.ReadRange(s, 5, 10, true), OrthancException); |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1495 ASSERT_THROW(tmp.ReadRange(s, 10, 50, true), OrthancException); |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1496 ASSERT_THROW(tmp.ReadRange(s, 50, 10, true), OrthancException); |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1497 ASSERT_THROW(tmp.ReadRange(s, 2, 1, true), OrthancException); |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1498 } |
52166629239f
SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4330
diff
changeset
|
1499 #endif |
4538
8a7523da6a9b
added SystemToolbox::GetMacAddresses()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1500 |
8a7523da6a9b
added SystemToolbox::GetMacAddresses()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1501 |
8a7523da6a9b
added SystemToolbox::GetMacAddresses()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1502 #if ORTHANC_SANDBOXED != 1 |
8a7523da6a9b
added SystemToolbox::GetMacAddresses()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1503 TEST(Toolbox, GetMacAddressess) |
8a7523da6a9b
added SystemToolbox::GetMacAddresses()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1504 { |
8a7523da6a9b
added SystemToolbox::GetMacAddresses()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1505 std::set<std::string> mac; |
8a7523da6a9b
added SystemToolbox::GetMacAddresses()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1506 SystemToolbox::GetMacAddresses(mac); |
8a7523da6a9b
added SystemToolbox::GetMacAddresses()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1507 |
8a7523da6a9b
added SystemToolbox::GetMacAddresses()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1508 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
|
1509 { |
8a7523da6a9b
added SystemToolbox::GetMacAddresses()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1510 printf("MAC address: [%s]\n", it->c_str()); |
8a7523da6a9b
added SystemToolbox::GetMacAddresses()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1511 } |
8a7523da6a9b
added SystemToolbox::GetMacAddresses()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1512 } |
8a7523da6a9b
added SystemToolbox::GetMacAddresses()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1513 #endif |