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