Mercurial > hg > orthanc
annotate UnitTestsSources/main.cpp @ 2750:4c271054e044 Orthanc-0.7.3
close old branch
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 17 Jul 2018 09:39:43 +0200 |
parents | 38e2883e096f |
children | 0da078f3affc |
rev | line source |
---|---|
434
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
1 #include "../Core/EnumerationDictionary.h" |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
2 |
0 | 3 #include "gtest/gtest.h" |
4 | |
5 #include <ctype.h> | |
6 | |
7 #include "../Core/Compression/ZlibCompressor.h" | |
8 #include "../Core/DicomFormat/DicomTag.h" | |
9 #include "../Core/HttpServer/HttpHandler.h" | |
63 | 10 #include "../Core/OrthancException.h" |
0 | 11 #include "../Core/Toolbox.h" |
12 #include "../Core/Uuid.h" | |
63 | 13 #include "../OrthancServer/FromDcmtkBridge.h" |
14 #include "../OrthancServer/OrthancInitialization.h" | |
450 | 15 #include "../Core/MultiThreading/SharedMessageQueue.h" |
0 | 16 |
63 | 17 using namespace Orthanc; |
0 | 18 |
19 | |
20 TEST(Uuid, Generation) | |
21 { | |
22 for (int i = 0; i < 10; i++) | |
23 { | |
24 std::string s = Toolbox::GenerateUuid(); | |
25 ASSERT_TRUE(Toolbox::IsUuid(s)); | |
26 } | |
27 } | |
28 | |
29 TEST(Uuid, Test) | |
30 { | |
31 ASSERT_FALSE(Toolbox::IsUuid("")); | |
32 ASSERT_FALSE(Toolbox::IsUuid("012345678901234567890123456789012345")); | |
33 ASSERT_TRUE(Toolbox::IsUuid("550e8400-e29b-41d4-a716-446655440000")); | |
708 | 34 ASSERT_FALSE(Toolbox::IsUuid("550e8400-e29b-41d4-a716-44665544000_")); |
707
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
35 ASSERT_FALSE(Toolbox::IsUuid("01234567890123456789012345678901234_")); |
402 | 36 ASSERT_FALSE(Toolbox::StartsWithUuid("550e8400-e29b-41d4-a716-44665544000")); |
37 ASSERT_TRUE(Toolbox::StartsWithUuid("550e8400-e29b-41d4-a716-446655440000")); | |
38 ASSERT_TRUE(Toolbox::StartsWithUuid("550e8400-e29b-41d4-a716-446655440000 ok")); | |
39 ASSERT_FALSE(Toolbox::StartsWithUuid("550e8400-e29b-41d4-a716-446655440000ok")); | |
40 } | |
41 | |
42 TEST(Toolbox, IsSHA1) | |
43 { | |
44 ASSERT_FALSE(Toolbox::IsSHA1("")); | |
45 ASSERT_FALSE(Toolbox::IsSHA1("01234567890123456789012345678901234567890123")); | |
46 ASSERT_FALSE(Toolbox::IsSHA1("012345678901234567890123456789012345678901234")); | |
47 ASSERT_TRUE(Toolbox::IsSHA1("b5ed549f-956400ce-69a8c063-bf5b78be-2732a4b9")); | |
48 | |
49 std::string s; | |
50 Toolbox::ComputeSHA1(s, "The quick brown fox jumps over the lazy dog"); | |
51 ASSERT_TRUE(Toolbox::IsSHA1(s)); | |
52 ASSERT_EQ("2fd4e1c6-7a2d28fc-ed849ee1-bb76e739-1b93eb12", s); | |
707
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
53 |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
54 ASSERT_FALSE(Toolbox::IsSHA1("b5ed549f-956400ce-69a8c063-bf5b78be-2732a4b_")); |
0 | 55 } |
56 | |
708 | 57 static void StringToVector(std::vector<uint8_t>& v, |
58 const std::string& s) | |
59 { | |
60 v.resize(s.size()); | |
61 for (size_t i = 0; i < s.size(); i++) | |
62 v[i] = s[i]; | |
63 } | |
64 | |
65 | |
0 | 66 TEST(Zlib, Basic) |
67 { | |
68 std::string s = Toolbox::GenerateUuid(); | |
69 s = s + s + s + s; | |
70 | |
708 | 71 std::string compressed, compressed2; |
72 ZlibCompressor c; | |
73 c.Compress(compressed, s); | |
74 | |
75 std::vector<uint8_t> v, vv; | |
76 StringToVector(v, s); | |
77 c.Compress(compressed2, v); | |
78 ASSERT_EQ(compressed, compressed2); | |
79 | |
80 std::string uncompressed; | |
81 c.Uncompress(uncompressed, compressed); | |
82 ASSERT_EQ(s.size(), uncompressed.size()); | |
83 ASSERT_EQ(0, memcmp(&s[0], &uncompressed[0], s.size())); | |
84 | |
85 StringToVector(vv, compressed); | |
86 c.Uncompress(uncompressed, vv); | |
87 ASSERT_EQ(s.size(), uncompressed.size()); | |
88 ASSERT_EQ(0, memcmp(&s[0], &uncompressed[0], s.size())); | |
89 } | |
90 | |
91 | |
92 TEST(Zlib, Level) | |
93 { | |
94 std::string s = Toolbox::GenerateUuid(); | |
95 s = s + s + s + s; | |
96 | |
97 std::string compressed, compressed2; | |
98 ZlibCompressor c; | |
99 c.SetCompressionLevel(9); | |
100 c.Compress(compressed, s); | |
101 | |
102 c.SetCompressionLevel(0); | |
103 c.Compress(compressed2, s); | |
104 | |
105 ASSERT_TRUE(compressed.size() < compressed2.size()); | |
106 } | |
107 | |
108 | |
109 TEST(Zlib, Corrupted) | |
110 { | |
111 std::string s = Toolbox::GenerateUuid(); | |
112 s = s + s + s + s; | |
113 | |
0 | 114 std::string compressed; |
115 ZlibCompressor c; | |
116 c.Compress(compressed, s); | |
117 | |
708 | 118 compressed[compressed.size() - 1] = 'a'; |
119 std::string u; | |
0 | 120 |
708 | 121 ASSERT_THROW(c.Uncompress(u, compressed), OrthancException); |
0 | 122 } |
123 | |
708 | 124 |
0 | 125 TEST(Zlib, Empty) |
126 { | |
127 std::string s = ""; | |
708 | 128 std::vector<uint8_t> v, vv; |
0 | 129 |
708 | 130 std::string compressed, compressed2; |
0 | 131 ZlibCompressor c; |
132 c.Compress(compressed, s); | |
708 | 133 c.Compress(compressed2, v); |
134 ASSERT_EQ(compressed, compressed2); | |
0 | 135 |
136 std::string uncompressed; | |
137 c.Uncompress(uncompressed, compressed); | |
708 | 138 ASSERT_EQ(0u, uncompressed.size()); |
0 | 139 |
708 | 140 StringToVector(vv, compressed); |
141 c.Uncompress(uncompressed, vv); | |
0 | 142 ASSERT_EQ(0u, uncompressed.size()); |
143 } | |
144 | |
708 | 145 |
0 | 146 TEST(ParseGetQuery, Basic) |
147 { | |
148 HttpHandler::Arguments a; | |
149 HttpHandler::ParseGetQuery(a, "aaa=baaa&bb=a&aa=c"); | |
150 ASSERT_EQ(3u, a.size()); | |
151 ASSERT_EQ(a["aaa"], "baaa"); | |
152 ASSERT_EQ(a["bb"], "a"); | |
153 ASSERT_EQ(a["aa"], "c"); | |
154 } | |
155 | |
156 TEST(ParseGetQuery, BasicEmpty) | |
157 { | |
158 HttpHandler::Arguments a; | |
159 HttpHandler::ParseGetQuery(a, "aaa&bb=aa&aa"); | |
160 ASSERT_EQ(3u, a.size()); | |
161 ASSERT_EQ(a["aaa"], ""); | |
162 ASSERT_EQ(a["bb"], "aa"); | |
163 ASSERT_EQ(a["aa"], ""); | |
164 } | |
165 | |
166 TEST(ParseGetQuery, Single) | |
167 { | |
168 HttpHandler::Arguments a; | |
169 HttpHandler::ParseGetQuery(a, "aaa=baaa"); | |
170 ASSERT_EQ(1u, a.size()); | |
171 ASSERT_EQ(a["aaa"], "baaa"); | |
172 } | |
173 | |
174 TEST(ParseGetQuery, SingleEmpty) | |
175 { | |
176 HttpHandler::Arguments a; | |
177 HttpHandler::ParseGetQuery(a, "aaa"); | |
178 ASSERT_EQ(1u, a.size()); | |
179 ASSERT_EQ(a["aaa"], ""); | |
180 } | |
181 | |
182 TEST(DicomFormat, Tag) | |
183 { | |
184 ASSERT_EQ("PatientName", FromDcmtkBridge::GetName(DicomTag(0x0010, 0x0010))); | |
185 | |
304 | 186 DicomTag t = FromDcmtkBridge::ParseTag("SeriesDescription"); |
0 | 187 ASSERT_EQ(0x0008, t.GetGroup()); |
188 ASSERT_EQ(0x103E, t.GetElement()); | |
304 | 189 |
190 t = FromDcmtkBridge::ParseTag("0020-e040"); | |
191 ASSERT_EQ(0x0020, t.GetGroup()); | |
192 ASSERT_EQ(0xe040, t.GetElement()); | |
567 | 193 |
194 // Test ==() and !=() operators | |
195 ASSERT_TRUE(DICOM_TAG_PATIENT_ID == DicomTag(0x0010, 0x0020)); | |
196 ASSERT_FALSE(DICOM_TAG_PATIENT_ID != DicomTag(0x0010, 0x0020)); | |
0 | 197 } |
198 | |
199 | |
200 TEST(Uri, SplitUriComponents) | |
201 { | |
202 UriComponents c; | |
203 Toolbox::SplitUriComponents(c, "/cou/hello/world"); | |
204 ASSERT_EQ(3u, c.size()); | |
205 ASSERT_EQ("cou", c[0]); | |
206 ASSERT_EQ("hello", c[1]); | |
207 ASSERT_EQ("world", c[2]); | |
208 | |
209 Toolbox::SplitUriComponents(c, "/cou/hello/world/"); | |
210 ASSERT_EQ(3u, c.size()); | |
211 ASSERT_EQ("cou", c[0]); | |
212 ASSERT_EQ("hello", c[1]); | |
213 ASSERT_EQ("world", c[2]); | |
214 | |
215 Toolbox::SplitUriComponents(c, "/cou/hello/world/a"); | |
216 ASSERT_EQ(4u, c.size()); | |
217 ASSERT_EQ("cou", c[0]); | |
218 ASSERT_EQ("hello", c[1]); | |
219 ASSERT_EQ("world", c[2]); | |
220 ASSERT_EQ("a", c[3]); | |
221 | |
222 Toolbox::SplitUriComponents(c, "/"); | |
223 ASSERT_EQ(0u, c.size()); | |
224 | |
225 Toolbox::SplitUriComponents(c, "/hello"); | |
226 ASSERT_EQ(1u, c.size()); | |
227 ASSERT_EQ("hello", c[0]); | |
228 | |
229 Toolbox::SplitUriComponents(c, "/hello/"); | |
230 ASSERT_EQ(1u, c.size()); | |
231 ASSERT_EQ("hello", c[0]); | |
232 | |
63 | 233 ASSERT_THROW(Toolbox::SplitUriComponents(c, ""), OrthancException); |
234 ASSERT_THROW(Toolbox::SplitUriComponents(c, "a"), OrthancException); | |
207 | 235 ASSERT_THROW(Toolbox::SplitUriComponents(c, "/coucou//coucou"), OrthancException); |
707
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
236 |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
237 c.clear(); |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
238 c.push_back("test"); |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
239 ASSERT_EQ("/", Toolbox::FlattenUri(c, 10)); |
0 | 240 } |
241 | |
242 | |
243 TEST(Uri, Child) | |
244 { | |
245 UriComponents c1; Toolbox::SplitUriComponents(c1, "/hello/world"); | |
246 UriComponents c2; Toolbox::SplitUriComponents(c2, "/hello/hello"); | |
247 UriComponents c3; Toolbox::SplitUriComponents(c3, "/hello"); | |
248 UriComponents c4; Toolbox::SplitUriComponents(c4, "/world"); | |
249 UriComponents c5; Toolbox::SplitUriComponents(c5, "/"); | |
250 | |
251 ASSERT_TRUE(Toolbox::IsChildUri(c1, c1)); | |
252 ASSERT_FALSE(Toolbox::IsChildUri(c1, c2)); | |
253 ASSERT_FALSE(Toolbox::IsChildUri(c1, c3)); | |
254 ASSERT_FALSE(Toolbox::IsChildUri(c1, c4)); | |
255 ASSERT_FALSE(Toolbox::IsChildUri(c1, c5)); | |
256 | |
257 ASSERT_FALSE(Toolbox::IsChildUri(c2, c1)); | |
258 ASSERT_TRUE(Toolbox::IsChildUri(c2, c2)); | |
259 ASSERT_FALSE(Toolbox::IsChildUri(c2, c3)); | |
260 ASSERT_FALSE(Toolbox::IsChildUri(c2, c4)); | |
261 ASSERT_FALSE(Toolbox::IsChildUri(c2, c5)); | |
262 | |
263 ASSERT_TRUE(Toolbox::IsChildUri(c3, c1)); | |
264 ASSERT_TRUE(Toolbox::IsChildUri(c3, c2)); | |
265 ASSERT_TRUE(Toolbox::IsChildUri(c3, c3)); | |
266 ASSERT_FALSE(Toolbox::IsChildUri(c3, c4)); | |
267 ASSERT_FALSE(Toolbox::IsChildUri(c3, c5)); | |
268 | |
269 ASSERT_FALSE(Toolbox::IsChildUri(c4, c1)); | |
270 ASSERT_FALSE(Toolbox::IsChildUri(c4, c2)); | |
271 ASSERT_FALSE(Toolbox::IsChildUri(c4, c3)); | |
272 ASSERT_TRUE(Toolbox::IsChildUri(c4, c4)); | |
273 ASSERT_FALSE(Toolbox::IsChildUri(c4, c5)); | |
274 | |
275 ASSERT_TRUE(Toolbox::IsChildUri(c5, c1)); | |
276 ASSERT_TRUE(Toolbox::IsChildUri(c5, c2)); | |
277 ASSERT_TRUE(Toolbox::IsChildUri(c5, c3)); | |
278 ASSERT_TRUE(Toolbox::IsChildUri(c5, c4)); | |
279 ASSERT_TRUE(Toolbox::IsChildUri(c5, c5)); | |
280 } | |
281 | |
282 TEST(Uri, AutodetectMimeType) | |
283 { | |
284 ASSERT_EQ("", Toolbox::AutodetectMimeType("../NOTES")); | |
285 ASSERT_EQ("", Toolbox::AutodetectMimeType("")); | |
286 ASSERT_EQ("", Toolbox::AutodetectMimeType("/")); | |
287 ASSERT_EQ("", Toolbox::AutodetectMimeType("a/a")); | |
288 | |
289 ASSERT_EQ("text/plain", Toolbox::AutodetectMimeType("../NOTES.txt")); | |
290 ASSERT_EQ("text/plain", Toolbox::AutodetectMimeType("../coucou.xml/NOTES.txt")); | |
291 ASSERT_EQ("text/xml", Toolbox::AutodetectMimeType("../.xml")); | |
292 | |
293 ASSERT_EQ("application/javascript", Toolbox::AutodetectMimeType("NOTES.js")); | |
294 ASSERT_EQ("application/json", Toolbox::AutodetectMimeType("NOTES.json")); | |
295 ASSERT_EQ("application/pdf", Toolbox::AutodetectMimeType("NOTES.pdf")); | |
296 ASSERT_EQ("text/css", Toolbox::AutodetectMimeType("NOTES.css")); | |
297 ASSERT_EQ("text/html", Toolbox::AutodetectMimeType("NOTES.html")); | |
298 ASSERT_EQ("text/plain", Toolbox::AutodetectMimeType("NOTES.txt")); | |
299 ASSERT_EQ("text/xml", Toolbox::AutodetectMimeType("NOTES.xml")); | |
300 ASSERT_EQ("image/gif", Toolbox::AutodetectMimeType("NOTES.gif")); | |
301 ASSERT_EQ("image/jpeg", Toolbox::AutodetectMimeType("NOTES.jpg")); | |
302 ASSERT_EQ("image/jpeg", Toolbox::AutodetectMimeType("NOTES.jpeg")); | |
303 ASSERT_EQ("image/png", Toolbox::AutodetectMimeType("NOTES.png")); | |
304 } | |
305 | |
22 | 306 TEST(Toolbox, ComputeMD5) |
307 { | |
308 std::string s; | |
309 | |
310 // # echo -n "Hello" | md5sum | |
311 | |
312 Toolbox::ComputeMD5(s, "Hello"); | |
313 ASSERT_EQ("8b1a9953c4611296a827abf8c47804d7", s); | |
314 Toolbox::ComputeMD5(s, ""); | |
315 ASSERT_EQ("d41d8cd98f00b204e9800998ecf8427e", s); | |
316 } | |
317 | |
177 | 318 TEST(Toolbox, ComputeSHA1) |
319 { | |
320 std::string s; | |
321 | |
322 Toolbox::ComputeSHA1(s, "The quick brown fox jumps over the lazy dog"); | |
323 ASSERT_EQ("2fd4e1c6-7a2d28fc-ed849ee1-bb76e739-1b93eb12", s); | |
324 Toolbox::ComputeSHA1(s, ""); | |
325 ASSERT_EQ("da39a3ee-5e6b4b0d-3255bfef-95601890-afd80709", s); | |
326 } | |
327 | |
328 | |
24 | 329 TEST(Toolbox, Base64) |
330 { | |
331 ASSERT_EQ("", Toolbox::EncodeBase64("")); | |
332 ASSERT_EQ("YQ==", Toolbox::EncodeBase64("a")); | |
707
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
333 |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
334 const std::string hello = "SGVsbG8gd29ybGQ="; |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
335 ASSERT_EQ(hello, Toolbox::EncodeBase64("Hello world")); |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
336 ASSERT_EQ("Hello world", Toolbox::DecodeBase64(hello)); |
24 | 337 } |
338 | |
87
8517e2c44283
path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
339 TEST(Toolbox, PathToExecutable) |
8517e2c44283
path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
340 { |
8517e2c44283
path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
341 printf("[%s]\n", Toolbox::GetPathToExecutable().c_str()); |
8517e2c44283
path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
342 printf("[%s]\n", Toolbox::GetDirectoryOfExecutable().c_str()); |
8517e2c44283
path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
343 } |
8517e2c44283
path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
344 |
247
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
235
diff
changeset
|
345 TEST(Toolbox, StripSpaces) |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
235
diff
changeset
|
346 { |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
235
diff
changeset
|
347 ASSERT_EQ("", Toolbox::StripSpaces(" \t \r \n ")); |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
235
diff
changeset
|
348 ASSERT_EQ("coucou", Toolbox::StripSpaces(" coucou \t \r \n ")); |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
235
diff
changeset
|
349 ASSERT_EQ("cou cou", Toolbox::StripSpaces(" cou cou \n ")); |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
235
diff
changeset
|
350 ASSERT_EQ("c", Toolbox::StripSpaces(" \n\t c\r \n ")); |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
235
diff
changeset
|
351 } |
100
27dc762e3dc8
getting rid of static dcmtk for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
352 |
707
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
353 TEST(Toolbox, Case) |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
354 { |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
355 std::string s = "CoU"; |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
356 std::string ss; |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
357 |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
358 Toolbox::ToUpperCase(ss, s); |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
359 ASSERT_EQ("COU", ss); |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
360 Toolbox::ToLowerCase(ss, s); |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
361 ASSERT_EQ("cou", ss); |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
362 |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
363 s = "CoU"; |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
364 Toolbox::ToUpperCase(s); |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
365 ASSERT_EQ("COU", s); |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
366 |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
367 s = "CoU"; |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
368 Toolbox::ToLowerCase(s); |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
369 ASSERT_EQ("cou", s); |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
370 } |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
371 |
100
27dc762e3dc8
getting rid of static dcmtk for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
372 |
102
7593b57dc1bf
switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
373 #include <glog/logging.h> |
100
27dc762e3dc8
getting rid of static dcmtk for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
374 |
27dc762e3dc8
getting rid of static dcmtk for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
375 TEST(Logger, Basic) |
27dc762e3dc8
getting rid of static dcmtk for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
376 { |
102
7593b57dc1bf
switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
377 LOG(INFO) << "I say hello"; |
100
27dc762e3dc8
getting rid of static dcmtk for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
378 } |
27dc762e3dc8
getting rid of static dcmtk for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
379 |
107
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
380 TEST(Toolbox, ConvertFromLatin1) |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
381 { |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
382 // This is a Latin-1 test string |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
383 const unsigned char data[10] = { 0xe0, 0xe9, 0xea, 0xe7, 0x26, 0xc6, 0x61, 0x62, 0x63, 0x00 }; |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
384 |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
385 /*FILE* f = fopen("/tmp/tutu", "w"); |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
386 fwrite(&data[0], 9, 1, f); |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
387 fclose(f);*/ |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
388 |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
389 std::string s((char*) &data[0], 10); |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
390 ASSERT_EQ("&abc", Toolbox::ConvertToAscii(s)); |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
391 |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
392 // Open in Emacs, then save with UTF-8 encoding, then "hexdump -C" |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
393 std::string utf8 = Toolbox::ConvertToUtf8(s, "ISO-8859-1"); |
235 | 394 ASSERT_EQ(15u, utf8.size()); |
107
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
395 ASSERT_EQ(0xc3, static_cast<unsigned char>(utf8[0])); |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
396 ASSERT_EQ(0xa0, static_cast<unsigned char>(utf8[1])); |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
397 ASSERT_EQ(0xc3, static_cast<unsigned char>(utf8[2])); |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
398 ASSERT_EQ(0xa9, static_cast<unsigned char>(utf8[3])); |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
399 ASSERT_EQ(0xc3, static_cast<unsigned char>(utf8[4])); |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
400 ASSERT_EQ(0xaa, static_cast<unsigned char>(utf8[5])); |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
401 ASSERT_EQ(0xc3, static_cast<unsigned char>(utf8[6])); |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
402 ASSERT_EQ(0xa7, static_cast<unsigned char>(utf8[7])); |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
403 ASSERT_EQ(0x26, static_cast<unsigned char>(utf8[8])); |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
404 ASSERT_EQ(0xc3, static_cast<unsigned char>(utf8[9])); |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
405 ASSERT_EQ(0x86, static_cast<unsigned char>(utf8[10])); |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
406 ASSERT_EQ(0x61, static_cast<unsigned char>(utf8[11])); |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
407 ASSERT_EQ(0x62, static_cast<unsigned char>(utf8[12])); |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
408 ASSERT_EQ(0x63, static_cast<unsigned char>(utf8[13])); |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
409 ASSERT_EQ(0x00, static_cast<unsigned char>(utf8[14])); // Null-terminated string |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
410 } |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
411 |
336 | 412 TEST(Toolbox, UrlDecode) |
413 { | |
414 std::string s; | |
415 | |
416 s = "Hello%20World"; | |
417 Toolbox::UrlDecode(s); | |
418 ASSERT_EQ("Hello World", s); | |
419 | |
337 | 420 s = "%21%23%24%26%27%28%29%2A%2B%2c%2f%3A%3b%3d%3f%40%5B%5D%90%ff"; |
336 | 421 Toolbox::UrlDecode(s); |
337 | 422 std::string ss = "!#$&'()*+,/:;=?@[]"; |
423 ss.push_back((char) 144); | |
424 ss.push_back((char) 255); | |
425 ASSERT_EQ(ss, s); | |
336 | 426 |
427 s = "(2000%2C00A4)+Other"; | |
428 Toolbox::UrlDecode(s); | |
429 ASSERT_EQ("(2000,00A4) Other", s); | |
430 } | |
431 | |
100
27dc762e3dc8
getting rid of static dcmtk for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
432 |
429
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
433 #if defined(__linux) |
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
434 TEST(OrthancInitialization, AbsoluteDirectory) |
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
435 { |
430 | 436 ASSERT_EQ("/tmp/hello", InterpretRelativePath("/tmp", "hello")); |
437 ASSERT_EQ("/tmp", InterpretRelativePath("/tmp", "/tmp")); | |
429
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
438 } |
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
439 #endif |
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
440 |
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
441 |
434
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
442 |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
443 #include "../OrthancServer/ServerEnumerations.h" |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
444 |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
445 TEST(EnumerationDictionary, Simple) |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
446 { |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
447 Toolbox::EnumerationDictionary<MetadataType> d; |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
448 |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
449 ASSERT_THROW(d.Translate("ReceptionDate"), OrthancException); |
435
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
450 ASSERT_EQ(MetadataType_ModifiedFrom, d.Translate("5")); |
436
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
435
diff
changeset
|
451 ASSERT_EQ(256, d.Translate("256")); |
434
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
452 |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
453 d.Add(MetadataType_Instance_ReceptionDate, "ReceptionDate"); |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
454 |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
455 ASSERT_EQ(MetadataType_Instance_ReceptionDate, d.Translate("ReceptionDate")); |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
456 ASSERT_EQ(MetadataType_Instance_ReceptionDate, d.Translate("2")); |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
457 ASSERT_EQ("ReceptionDate", d.Translate(MetadataType_Instance_ReceptionDate)); |
435
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
458 |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
459 ASSERT_THROW(d.Add(MetadataType_Instance_ReceptionDate, "Hello"), OrthancException); |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
460 ASSERT_THROW(d.Add(MetadataType_ModifiedFrom, "ReceptionDate"), OrthancException); // already used |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
461 ASSERT_THROW(d.Add(MetadataType_ModifiedFrom, "1024"), OrthancException); // cannot register numbers |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
462 d.Add(MetadataType_ModifiedFrom, "ModifiedFrom"); // ok |
434
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
463 } |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
464 |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
465 |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
466 TEST(EnumerationDictionary, ServerEnumerations) |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
467 { |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
468 ASSERT_STREQ("Patient", EnumerationToString(ResourceType_Patient)); |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
469 ASSERT_STREQ("Study", EnumerationToString(ResourceType_Study)); |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
470 ASSERT_STREQ("Series", EnumerationToString(ResourceType_Series)); |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
471 ASSERT_STREQ("Instance", EnumerationToString(ResourceType_Instance)); |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
472 |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
473 ASSERT_STREQ("ModifiedSeries", EnumerationToString(ChangeType_ModifiedSeries)); |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
474 |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
475 ASSERT_STREQ("Failure", EnumerationToString(StoreStatus_Failure)); |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
476 ASSERT_STREQ("Success", EnumerationToString(StoreStatus_Success)); |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
477 |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
478 ASSERT_STREQ("CompletedSeries", EnumerationToString(ChangeType_CompletedSeries)); |
435
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
479 |
437 | 480 ASSERT_EQ("IndexInSeries", EnumerationToString(MetadataType_Instance_IndexInSeries)); |
481 ASSERT_EQ("LastUpdate", EnumerationToString(MetadataType_LastUpdate)); | |
435
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
482 |
559 | 483 ASSERT_EQ(ResourceType_Patient, StringToResourceType("PATienT")); |
484 ASSERT_EQ(ResourceType_Study, StringToResourceType("STudy")); | |
485 ASSERT_EQ(ResourceType_Series, StringToResourceType("SeRiEs")); | |
486 ASSERT_EQ(ResourceType_Instance, StringToResourceType("INStance")); | |
487 ASSERT_EQ(ResourceType_Instance, StringToResourceType("IMagE")); | |
488 ASSERT_THROW(StringToResourceType("heLLo"), OrthancException); | |
489 | |
435
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
490 ASSERT_EQ(2047, StringToMetadata("2047")); |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
491 ASSERT_THROW(StringToMetadata("Ceci est un test"), OrthancException); |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
492 ASSERT_THROW(RegisterUserMetadata(128, ""), OrthancException); // too low (< 1024) |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
493 ASSERT_THROW(RegisterUserMetadata(128000, ""), OrthancException); // too high (> 65535) |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
494 RegisterUserMetadata(2047, "Ceci est un test"); |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
495 ASSERT_EQ(2047, StringToMetadata("2047")); |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
496 ASSERT_EQ(2047, StringToMetadata("Ceci est un test")); |
434
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
497 } |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
498 |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
499 |
450 | 500 |
501 class DynamicInteger : public IDynamicObject | |
502 { | |
503 private: | |
504 int value_; | |
505 | |
506 public: | |
507 DynamicInteger(int value) : value_(value) | |
508 { | |
509 } | |
510 | |
511 int GetValue() const | |
512 { | |
513 return value_; | |
514 } | |
515 }; | |
516 | |
517 | |
518 TEST(SharedMessageQueue, Basic) | |
519 { | |
520 SharedMessageQueue q; | |
452 | 521 ASSERT_TRUE(q.WaitEmpty(0)); |
450 | 522 q.Enqueue(new DynamicInteger(10)); |
452 | 523 ASSERT_FALSE(q.WaitEmpty(1)); |
450 | 524 q.Enqueue(new DynamicInteger(20)); |
525 q.Enqueue(new DynamicInteger(30)); | |
526 q.Enqueue(new DynamicInteger(40)); | |
527 | |
528 std::auto_ptr<DynamicInteger> i; | |
452 | 529 i.reset(dynamic_cast<DynamicInteger*>(q.Dequeue(1))); ASSERT_EQ(10, i->GetValue()); |
530 i.reset(dynamic_cast<DynamicInteger*>(q.Dequeue(1))); ASSERT_EQ(20, i->GetValue()); | |
531 i.reset(dynamic_cast<DynamicInteger*>(q.Dequeue(1))); ASSERT_EQ(30, i->GetValue()); | |
532 ASSERT_FALSE(q.WaitEmpty(1)); | |
533 i.reset(dynamic_cast<DynamicInteger*>(q.Dequeue(1))); ASSERT_EQ(40, i->GetValue()); | |
534 ASSERT_TRUE(q.WaitEmpty(0)); | |
535 ASSERT_EQ(NULL, q.Dequeue(1)); | |
450 | 536 } |
537 | |
538 | |
539 TEST(SharedMessageQueue, Clean) | |
540 { | |
541 try | |
542 { | |
543 SharedMessageQueue q; | |
544 q.Enqueue(new DynamicInteger(10)); | |
545 q.Enqueue(new DynamicInteger(20)); | |
546 throw OrthancException("Nope"); | |
547 } | |
533 | 548 catch (OrthancException&) |
450 | 549 { |
550 } | |
551 } | |
552 | |
553 | |
483
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
554 TEST(Toolbox, WriteFile) |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
555 { |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
556 std::string path; |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
557 |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
558 { |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
559 Toolbox::TemporaryFile tmp; |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
560 path = tmp.GetPath(); |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
561 |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
562 std::string s; |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
563 s.append("Hello"); |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
564 s.push_back('\0'); |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
565 s.append("World"); |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
566 ASSERT_EQ(11u, s.size()); |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
567 |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
568 Toolbox::WriteFile(s, path.c_str()); |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
569 |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
570 std::string t; |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
571 Toolbox::ReadFile(t, path.c_str()); |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
572 |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
573 ASSERT_EQ(11u, t.size()); |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
574 ASSERT_EQ(0, t[5]); |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
575 ASSERT_EQ(0, memcmp(s.c_str(), t.c_str(), s.size())); |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
576 } |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
577 |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
578 std::string u; |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
579 ASSERT_THROW(Toolbox::ReadFile(u, path.c_str()), OrthancException); |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
580 } |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
581 |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
582 |
608 | 583 TEST(Toolbox, Wildcard) |
584 { | |
585 ASSERT_EQ("abcd", Toolbox::WildcardToRegularExpression("abcd")); | |
586 ASSERT_EQ("ab.*cd", Toolbox::WildcardToRegularExpression("ab*cd")); | |
587 ASSERT_EQ("ab..cd", Toolbox::WildcardToRegularExpression("ab??cd")); | |
588 ASSERT_EQ("a.*b.c.*d", Toolbox::WildcardToRegularExpression("a*b?c*d")); | |
589 ASSERT_EQ("a\\{b\\]", Toolbox::WildcardToRegularExpression("a{b]")); | |
590 } | |
591 | |
592 | |
593 TEST(Toolbox, Tokenize) | |
594 { | |
595 std::vector<std::string> t; | |
596 | |
597 Toolbox::TokenizeString(t, "", ','); | |
598 ASSERT_EQ(1, t.size()); | |
599 ASSERT_EQ("", t[0]); | |
600 | |
601 Toolbox::TokenizeString(t, "abc", ','); | |
602 ASSERT_EQ(1, t.size()); | |
603 ASSERT_EQ("abc", t[0]); | |
604 | |
605 Toolbox::TokenizeString(t, "ab,cd,ef,", ','); | |
606 ASSERT_EQ(4, t.size()); | |
607 ASSERT_EQ("ab", t[0]); | |
608 ASSERT_EQ("cd", t[1]); | |
609 ASSERT_EQ("ef", t[2]); | |
610 ASSERT_EQ("", t[3]); | |
611 } | |
612 | |
613 | |
674
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
614 |
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
615 #if defined(__linux) |
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
616 #include <endian.h> |
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
617 #endif |
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
618 |
637 | 619 TEST(Toolbox, Endianness) |
620 { | |
674
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
621 // Parts of this test come from Adam Conrad |
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
622 // http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=728822#5 |
637 | 623 |
624 #if defined(_WIN32) | |
625 ASSERT_EQ(Endianness_Little, Toolbox::DetectEndianness()); | |
674
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
626 |
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
627 #elif defined(__linux) |
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
628 |
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
629 #if !defined(__BYTE_ORDER) |
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
630 # error Support your platform here |
637 | 631 #endif |
632 | |
674
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
633 # if __BYTE_ORDER == __BIG_ENDIAN |
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
634 ASSERT_EQ(Endianness_Big, Toolbox::DetectEndianness()); |
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
635 # else // __LITTLE_ENDIAN |
637 | 636 ASSERT_EQ(Endianness_Little, Toolbox::DetectEndianness()); |
674
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
637 # endif |
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
638 |
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
639 #else |
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
640 #error Support your platform here |
637 | 641 #endif |
642 } | |
643 | |
644 | |
645 | |
0 | 646 int main(int argc, char **argv) |
647 { | |
102
7593b57dc1bf
switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
648 // Initialize Google's logging library. |
7593b57dc1bf
switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
649 FLAGS_logtostderr = true; |
137
0e97abc7b950
fix of a bug in older versions of sqlite
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
107
diff
changeset
|
650 FLAGS_minloglevel = 0; |
159
c08fbad40ddd
less verbosity in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
651 |
c08fbad40ddd
less verbosity in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
652 // Go to trace-level verbosity |
c08fbad40ddd
less verbosity in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
653 //FLAGS_v = 1; |
c08fbad40ddd
less verbosity in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
654 |
453 | 655 Toolbox::DetectEndianness(); |
656 | |
102
7593b57dc1bf
switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
657 google::InitGoogleLogging("Orthanc"); |
100
27dc762e3dc8
getting rid of static dcmtk for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
658 |
63 | 659 OrthancInitialize(); |
0 | 660 ::testing::InitGoogleTest(&argc, argv); |
661 int result = RUN_ALL_TESTS(); | |
63 | 662 OrthancFinalize(); |
0 | 663 return result; |
664 } |