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