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