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