Mercurial > hg > orthanc
annotate UnitTestsSources/UnitTestsMain.cpp @ 1516:f09f5d3225a7
fix
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 11 Aug 2015 08:53:47 +0200 |
parents | fe07f82d83d3 |
children | f9b0169eb6bb |
rev | line source |
---|---|
827
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
1 /** |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
2 * Orthanc - A Lightweight, RESTful DICOM Store |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1102
diff
changeset
|
3 * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics |
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1102
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
827
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
5 * |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
6 * This program is free software: you can redistribute it and/or |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
7 * modify it under the terms of the GNU General Public License as |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
8 * published by the Free Software Foundation, either version 3 of the |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
9 * License, or (at your option) any later version. |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
10 * |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
11 * In addition, as a special exception, the copyright holders of this |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
12 * program give permission to link the code of its release with the |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
14 * that use the same license as the "OpenSSL" library), and distribute |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
15 * the linked executables. You must obey the GNU General Public License |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
16 * in all respects for all of the code used other than "OpenSSL". If you |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
17 * modify file(s) with this exception, you may extend this exception to |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
18 * your version of the file(s), but you are not obligated to do so. If |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
19 * you do not wish to do so, delete this exception statement from your |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
20 * version. If you delete this exception statement from all source files |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
21 * in the program, then also delete it here. |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
22 * |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
23 * This program is distributed in the hope that it will be useful, but |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
24 * WITHOUT ANY WARRANTY; without even the implied warranty of |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
26 * General Public License for more details. |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
27 * |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
28 * You should have received a copy of the GNU General Public License |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
29 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
30 **/ |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
31 |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
32 |
831
84513f2ee1f3
pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
827
diff
changeset
|
33 #include "PrecompiledHeadersUnitTests.h" |
434
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
34 #include "../Core/EnumerationDictionary.h" |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
35 |
0 | 36 #include "gtest/gtest.h" |
37 | |
38 #include <ctype.h> | |
39 | |
40 #include "../Core/Compression/ZlibCompressor.h" | |
1513 | 41 #include "../Core/Compression/GzipCompressor.h" |
0 | 42 #include "../Core/DicomFormat/DicomTag.h" |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
43 #include "../Core/HttpServer/HttpToolbox.h" |
1485
27661b33f624
Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
44 #include "../Core/Logging.h" |
63 | 45 #include "../Core/OrthancException.h" |
0 | 46 #include "../Core/Toolbox.h" |
47 #include "../Core/Uuid.h" | |
63 | 48 #include "../OrthancServer/OrthancInitialization.h" |
0 | 49 |
1337 | 50 |
63 | 51 using namespace Orthanc; |
0 | 52 |
53 | |
54 TEST(Uuid, Generation) | |
55 { | |
56 for (int i = 0; i < 10; i++) | |
57 { | |
58 std::string s = Toolbox::GenerateUuid(); | |
59 ASSERT_TRUE(Toolbox::IsUuid(s)); | |
60 } | |
61 } | |
62 | |
63 TEST(Uuid, Test) | |
64 { | |
65 ASSERT_FALSE(Toolbox::IsUuid("")); | |
66 ASSERT_FALSE(Toolbox::IsUuid("012345678901234567890123456789012345")); | |
67 ASSERT_TRUE(Toolbox::IsUuid("550e8400-e29b-41d4-a716-446655440000")); | |
708 | 68 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
|
69 ASSERT_FALSE(Toolbox::IsUuid("01234567890123456789012345678901234_")); |
402 | 70 ASSERT_FALSE(Toolbox::StartsWithUuid("550e8400-e29b-41d4-a716-44665544000")); |
71 ASSERT_TRUE(Toolbox::StartsWithUuid("550e8400-e29b-41d4-a716-446655440000")); | |
72 ASSERT_TRUE(Toolbox::StartsWithUuid("550e8400-e29b-41d4-a716-446655440000 ok")); | |
73 ASSERT_FALSE(Toolbox::StartsWithUuid("550e8400-e29b-41d4-a716-446655440000ok")); | |
74 } | |
75 | |
76 TEST(Toolbox, IsSHA1) | |
77 { | |
78 ASSERT_FALSE(Toolbox::IsSHA1("")); | |
79 ASSERT_FALSE(Toolbox::IsSHA1("01234567890123456789012345678901234567890123")); | |
80 ASSERT_FALSE(Toolbox::IsSHA1("012345678901234567890123456789012345678901234")); | |
81 ASSERT_TRUE(Toolbox::IsSHA1("b5ed549f-956400ce-69a8c063-bf5b78be-2732a4b9")); | |
82 | |
1428 | 83 std::string sha = " b5ed549f-956400ce-69a8c063-bf5b78be-2732a4b9 "; |
84 ASSERT_TRUE(Toolbox::IsSHA1(sha)); | |
85 sha[3] = '\0'; | |
86 sha[53] = '\0'; | |
87 ASSERT_TRUE(Toolbox::IsSHA1(sha)); | |
88 sha[40] = '\0'; | |
89 ASSERT_FALSE(Toolbox::IsSHA1(sha)); | |
90 ASSERT_FALSE(Toolbox::IsSHA1(" ")); | |
91 | |
92 ASSERT_TRUE(Toolbox::IsSHA1("16738bc3-e47ed42a-43ce044c-a3414a45-cb069bd0")); | |
93 | |
402 | 94 std::string s; |
95 Toolbox::ComputeSHA1(s, "The quick brown fox jumps over the lazy dog"); | |
96 ASSERT_TRUE(Toolbox::IsSHA1(s)); | |
97 ASSERT_EQ("2fd4e1c6-7a2d28fc-ed849ee1-bb76e739-1b93eb12", s); | |
707
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
98 |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
99 ASSERT_FALSE(Toolbox::IsSHA1("b5ed549f-956400ce-69a8c063-bf5b78be-2732a4b_")); |
0 | 100 } |
101 | |
708 | 102 |
1513 | 103 TEST(Gzip, Basic) |
104 { | |
105 std::string s = "Hello world"; | |
106 | |
107 std::string compressed; | |
108 GzipCompressor c; | |
109 ASSERT_FALSE(c.HasPrefixWithUncompressedSize()); | |
110 IBufferCompressor::Compress(compressed, c, s); | |
111 | |
112 std::string uncompressed; | |
113 IBufferCompressor::Uncompress(uncompressed, c, compressed); | |
114 ASSERT_EQ(s.size(), uncompressed.size()); | |
115 ASSERT_EQ(0, memcmp(&s[0], &uncompressed[0], s.size())); | |
116 } | |
117 | |
118 | |
119 TEST(Gzip, Empty) | |
120 { | |
121 std::string s; | |
122 | |
123 std::string compressed; | |
124 GzipCompressor c; | |
125 ASSERT_FALSE(c.HasPrefixWithUncompressedSize()); | |
126 c.SetPrefixWithUncompressedSize(false); | |
127 IBufferCompressor::Compress(compressed, c, s); | |
128 | |
129 std::string uncompressed; | |
130 IBufferCompressor::Uncompress(uncompressed, c, compressed); | |
131 ASSERT_EQ(0, uncompressed.size()); | |
132 } | |
133 | |
134 | |
135 TEST(Gzip, BasicWithPrefix) | |
136 { | |
137 std::string s = "Hello world"; | |
138 | |
139 std::string compressed; | |
140 GzipCompressor c; | |
141 c.SetPrefixWithUncompressedSize(true); | |
142 ASSERT_TRUE(c.HasPrefixWithUncompressedSize()); | |
143 IBufferCompressor::Compress(compressed, c, s); | |
144 | |
145 std::string uncompressed; | |
146 IBufferCompressor::Uncompress(uncompressed, c, compressed); | |
147 ASSERT_EQ(s.size(), uncompressed.size()); | |
148 ASSERT_EQ(0, memcmp(&s[0], &uncompressed[0], s.size())); | |
149 } | |
150 | |
151 | |
152 TEST(Gzip, EmptyWithPrefix) | |
153 { | |
154 std::string s; | |
155 | |
156 std::string compressed; | |
157 GzipCompressor c; | |
158 c.SetPrefixWithUncompressedSize(true); | |
159 ASSERT_TRUE(c.HasPrefixWithUncompressedSize()); | |
160 IBufferCompressor::Compress(compressed, c, s); | |
161 | |
162 std::string uncompressed; | |
163 IBufferCompressor::Uncompress(uncompressed, c, compressed); | |
164 ASSERT_EQ(0, uncompressed.size()); | |
165 } | |
166 | |
167 | |
0 | 168 TEST(Zlib, Basic) |
169 { | |
170 std::string s = Toolbox::GenerateUuid(); | |
171 s = s + s + s + s; | |
172 | |
708 | 173 std::string compressed, compressed2; |
174 ZlibCompressor c; | |
1513 | 175 ASSERT_TRUE(c.HasPrefixWithUncompressedSize()); |
1512 | 176 IBufferCompressor::Compress(compressed, c, s); |
708 | 177 |
178 std::string uncompressed; | |
1512 | 179 IBufferCompressor::Uncompress(uncompressed, c, compressed); |
708 | 180 ASSERT_EQ(s.size(), uncompressed.size()); |
181 ASSERT_EQ(0, memcmp(&s[0], &uncompressed[0], s.size())); | |
182 } | |
183 | |
184 | |
185 TEST(Zlib, Level) | |
186 { | |
187 std::string s = Toolbox::GenerateUuid(); | |
188 s = s + s + s + s; | |
189 | |
190 std::string compressed, compressed2; | |
191 ZlibCompressor c; | |
192 c.SetCompressionLevel(9); | |
1512 | 193 IBufferCompressor::Compress(compressed, c, s); |
708 | 194 |
195 c.SetCompressionLevel(0); | |
1512 | 196 IBufferCompressor::Compress(compressed2, c, s); |
708 | 197 |
198 ASSERT_TRUE(compressed.size() < compressed2.size()); | |
199 } | |
200 | |
201 | |
727 | 202 TEST(Zlib, DISABLED_Corrupted) // Disabled because it may result in a crash |
708 | 203 { |
204 std::string s = Toolbox::GenerateUuid(); | |
205 s = s + s + s + s; | |
206 | |
0 | 207 std::string compressed; |
208 ZlibCompressor c; | |
1512 | 209 IBufferCompressor::Compress(compressed, c, s); |
0 | 210 |
708 | 211 compressed[compressed.size() - 1] = 'a'; |
212 std::string u; | |
0 | 213 |
1512 | 214 ASSERT_THROW(IBufferCompressor::Uncompress(u, c, compressed), OrthancException); |
0 | 215 } |
216 | |
708 | 217 |
0 | 218 TEST(Zlib, Empty) |
219 { | |
220 std::string s = ""; | |
221 | |
708 | 222 std::string compressed, compressed2; |
0 | 223 ZlibCompressor c; |
1512 | 224 IBufferCompressor::Compress(compressed, c, s); |
708 | 225 ASSERT_EQ(compressed, compressed2); |
0 | 226 |
227 std::string uncompressed; | |
1512 | 228 IBufferCompressor::Uncompress(uncompressed, c, compressed); |
0 | 229 ASSERT_EQ(0u, uncompressed.size()); |
230 } | |
231 | |
708 | 232 |
912
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
233 TEST(ParseGetArguments, Basic) |
0 | 234 { |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
235 IHttpHandler::GetArguments b; |
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
236 HttpToolbox::ParseGetArguments(b, "aaa=baaa&bb=a&aa=c"); |
1363
feaf2840917c
Plugins now receive duplicated GET arguments in their REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1337
diff
changeset
|
237 |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
238 IHttpHandler::Arguments a; |
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
239 HttpToolbox::CompileGetArguments(a, b); |
1363
feaf2840917c
Plugins now receive duplicated GET arguments in their REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1337
diff
changeset
|
240 |
0 | 241 ASSERT_EQ(3u, a.size()); |
242 ASSERT_EQ(a["aaa"], "baaa"); | |
243 ASSERT_EQ(a["bb"], "a"); | |
244 ASSERT_EQ(a["aa"], "c"); | |
245 } | |
246 | |
912
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
247 TEST(ParseGetArguments, BasicEmpty) |
0 | 248 { |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
249 IHttpHandler::GetArguments b; |
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
250 HttpToolbox::ParseGetArguments(b, "aaa&bb=aa&aa"); |
1363
feaf2840917c
Plugins now receive duplicated GET arguments in their REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1337
diff
changeset
|
251 |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
252 IHttpHandler::Arguments a; |
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
253 HttpToolbox::CompileGetArguments(a, b); |
1363
feaf2840917c
Plugins now receive duplicated GET arguments in their REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1337
diff
changeset
|
254 |
0 | 255 ASSERT_EQ(3u, a.size()); |
256 ASSERT_EQ(a["aaa"], ""); | |
257 ASSERT_EQ(a["bb"], "aa"); | |
258 ASSERT_EQ(a["aa"], ""); | |
259 } | |
260 | |
912
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
261 TEST(ParseGetArguments, Single) |
0 | 262 { |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
263 IHttpHandler::GetArguments b; |
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
264 HttpToolbox::ParseGetArguments(b, "aaa=baaa"); |
1363
feaf2840917c
Plugins now receive duplicated GET arguments in their REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1337
diff
changeset
|
265 |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
266 IHttpHandler::Arguments a; |
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
267 HttpToolbox::CompileGetArguments(a, b); |
1363
feaf2840917c
Plugins now receive duplicated GET arguments in their REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1337
diff
changeset
|
268 |
0 | 269 ASSERT_EQ(1u, a.size()); |
270 ASSERT_EQ(a["aaa"], "baaa"); | |
271 } | |
272 | |
912
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
273 TEST(ParseGetArguments, SingleEmpty) |
0 | 274 { |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
275 IHttpHandler::GetArguments b; |
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
276 HttpToolbox::ParseGetArguments(b, "aaa"); |
1363
feaf2840917c
Plugins now receive duplicated GET arguments in their REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1337
diff
changeset
|
277 |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
278 IHttpHandler::Arguments a; |
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
279 HttpToolbox::CompileGetArguments(a, b); |
1363
feaf2840917c
Plugins now receive duplicated GET arguments in their REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1337
diff
changeset
|
280 |
0 | 281 ASSERT_EQ(1u, a.size()); |
282 ASSERT_EQ(a["aaa"], ""); | |
283 } | |
284 | |
912
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
285 TEST(ParseGetQuery, Test1) |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
286 { |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
287 UriComponents uri; |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
288 IHttpHandler::GetArguments b; |
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
289 HttpToolbox::ParseGetQuery(uri, b, "/instances/test/world?aaa=baaa&bb=a&aa=c"); |
1363
feaf2840917c
Plugins now receive duplicated GET arguments in their REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1337
diff
changeset
|
290 |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
291 IHttpHandler::Arguments a; |
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
292 HttpToolbox::CompileGetArguments(a, b); |
1363
feaf2840917c
Plugins now receive duplicated GET arguments in their REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1337
diff
changeset
|
293 |
912
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
294 ASSERT_EQ(3u, uri.size()); |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
295 ASSERT_EQ("instances", uri[0]); |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
296 ASSERT_EQ("test", uri[1]); |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
297 ASSERT_EQ("world", uri[2]); |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
298 ASSERT_EQ(3u, a.size()); |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
299 ASSERT_EQ(a["aaa"], "baaa"); |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
300 ASSERT_EQ(a["bb"], "a"); |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
301 ASSERT_EQ(a["aa"], "c"); |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
302 } |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
303 |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
304 TEST(ParseGetQuery, Test2) |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
305 { |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
306 UriComponents uri; |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
307 IHttpHandler::GetArguments b; |
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
308 HttpToolbox::ParseGetQuery(uri, b, "/instances/test/world"); |
1363
feaf2840917c
Plugins now receive duplicated GET arguments in their REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1337
diff
changeset
|
309 |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
310 IHttpHandler::Arguments a; |
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
311 HttpToolbox::CompileGetArguments(a, b); |
1363
feaf2840917c
Plugins now receive duplicated GET arguments in their REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1337
diff
changeset
|
312 |
912
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
313 ASSERT_EQ(3u, uri.size()); |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
314 ASSERT_EQ("instances", uri[0]); |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
315 ASSERT_EQ("test", uri[1]); |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
316 ASSERT_EQ("world", uri[2]); |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
317 ASSERT_EQ(0u, a.size()); |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
318 } |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
319 |
0 | 320 TEST(Uri, SplitUriComponents) |
321 { | |
966
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
322 UriComponents c, d; |
0 | 323 Toolbox::SplitUriComponents(c, "/cou/hello/world"); |
324 ASSERT_EQ(3u, c.size()); | |
325 ASSERT_EQ("cou", c[0]); | |
326 ASSERT_EQ("hello", c[1]); | |
327 ASSERT_EQ("world", c[2]); | |
328 | |
329 Toolbox::SplitUriComponents(c, "/cou/hello/world/"); | |
330 ASSERT_EQ(3u, c.size()); | |
331 ASSERT_EQ("cou", c[0]); | |
332 ASSERT_EQ("hello", c[1]); | |
333 ASSERT_EQ("world", c[2]); | |
334 | |
335 Toolbox::SplitUriComponents(c, "/cou/hello/world/a"); | |
336 ASSERT_EQ(4u, c.size()); | |
337 ASSERT_EQ("cou", c[0]); | |
338 ASSERT_EQ("hello", c[1]); | |
339 ASSERT_EQ("world", c[2]); | |
340 ASSERT_EQ("a", c[3]); | |
341 | |
342 Toolbox::SplitUriComponents(c, "/"); | |
343 ASSERT_EQ(0u, c.size()); | |
344 | |
345 Toolbox::SplitUriComponents(c, "/hello"); | |
346 ASSERT_EQ(1u, c.size()); | |
347 ASSERT_EQ("hello", c[0]); | |
348 | |
349 Toolbox::SplitUriComponents(c, "/hello/"); | |
350 ASSERT_EQ(1u, c.size()); | |
351 ASSERT_EQ("hello", c[0]); | |
352 | |
63 | 353 ASSERT_THROW(Toolbox::SplitUriComponents(c, ""), OrthancException); |
354 ASSERT_THROW(Toolbox::SplitUriComponents(c, "a"), OrthancException); | |
207 | 355 ASSERT_THROW(Toolbox::SplitUriComponents(c, "/coucou//coucou"), OrthancException); |
707
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
356 |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
357 c.clear(); |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
358 c.push_back("test"); |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
359 ASSERT_EQ("/", Toolbox::FlattenUri(c, 10)); |
0 | 360 } |
361 | |
362 | |
966
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
363 TEST(Uri, Truncate) |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
364 { |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
365 UriComponents c, d; |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
366 Toolbox::SplitUriComponents(c, "/cou/hello/world"); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
367 |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
368 Toolbox::TruncateUri(d, c, 0); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
369 ASSERT_EQ(3u, d.size()); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
370 ASSERT_EQ("cou", d[0]); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
371 ASSERT_EQ("hello", d[1]); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
372 ASSERT_EQ("world", d[2]); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
373 |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
374 Toolbox::TruncateUri(d, c, 1); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
375 ASSERT_EQ(2u, d.size()); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
376 ASSERT_EQ("hello", d[0]); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
377 ASSERT_EQ("world", d[1]); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
378 |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
379 Toolbox::TruncateUri(d, c, 2); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
380 ASSERT_EQ(1u, d.size()); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
381 ASSERT_EQ("world", d[0]); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
382 |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
383 Toolbox::TruncateUri(d, c, 3); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
384 ASSERT_EQ(0u, d.size()); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
385 |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
386 Toolbox::TruncateUri(d, c, 4); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
387 ASSERT_EQ(0u, d.size()); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
388 |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
389 Toolbox::TruncateUri(d, c, 5); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
390 ASSERT_EQ(0u, d.size()); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
391 } |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
392 |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
393 |
0 | 394 TEST(Uri, Child) |
395 { | |
396 UriComponents c1; Toolbox::SplitUriComponents(c1, "/hello/world"); | |
397 UriComponents c2; Toolbox::SplitUriComponents(c2, "/hello/hello"); | |
398 UriComponents c3; Toolbox::SplitUriComponents(c3, "/hello"); | |
399 UriComponents c4; Toolbox::SplitUriComponents(c4, "/world"); | |
400 UriComponents c5; Toolbox::SplitUriComponents(c5, "/"); | |
401 | |
402 ASSERT_TRUE(Toolbox::IsChildUri(c1, c1)); | |
403 ASSERT_FALSE(Toolbox::IsChildUri(c1, c2)); | |
404 ASSERT_FALSE(Toolbox::IsChildUri(c1, c3)); | |
405 ASSERT_FALSE(Toolbox::IsChildUri(c1, c4)); | |
406 ASSERT_FALSE(Toolbox::IsChildUri(c1, c5)); | |
407 | |
408 ASSERT_FALSE(Toolbox::IsChildUri(c2, c1)); | |
409 ASSERT_TRUE(Toolbox::IsChildUri(c2, c2)); | |
410 ASSERT_FALSE(Toolbox::IsChildUri(c2, c3)); | |
411 ASSERT_FALSE(Toolbox::IsChildUri(c2, c4)); | |
412 ASSERT_FALSE(Toolbox::IsChildUri(c2, c5)); | |
413 | |
414 ASSERT_TRUE(Toolbox::IsChildUri(c3, c1)); | |
415 ASSERT_TRUE(Toolbox::IsChildUri(c3, c2)); | |
416 ASSERT_TRUE(Toolbox::IsChildUri(c3, c3)); | |
417 ASSERT_FALSE(Toolbox::IsChildUri(c3, c4)); | |
418 ASSERT_FALSE(Toolbox::IsChildUri(c3, c5)); | |
419 | |
420 ASSERT_FALSE(Toolbox::IsChildUri(c4, c1)); | |
421 ASSERT_FALSE(Toolbox::IsChildUri(c4, c2)); | |
422 ASSERT_FALSE(Toolbox::IsChildUri(c4, c3)); | |
423 ASSERT_TRUE(Toolbox::IsChildUri(c4, c4)); | |
424 ASSERT_FALSE(Toolbox::IsChildUri(c4, c5)); | |
425 | |
426 ASSERT_TRUE(Toolbox::IsChildUri(c5, c1)); | |
427 ASSERT_TRUE(Toolbox::IsChildUri(c5, c2)); | |
428 ASSERT_TRUE(Toolbox::IsChildUri(c5, c3)); | |
429 ASSERT_TRUE(Toolbox::IsChildUri(c5, c4)); | |
430 ASSERT_TRUE(Toolbox::IsChildUri(c5, c5)); | |
431 } | |
432 | |
433 TEST(Uri, AutodetectMimeType) | |
434 { | |
435 ASSERT_EQ("", Toolbox::AutodetectMimeType("../NOTES")); | |
436 ASSERT_EQ("", Toolbox::AutodetectMimeType("")); | |
437 ASSERT_EQ("", Toolbox::AutodetectMimeType("/")); | |
438 ASSERT_EQ("", Toolbox::AutodetectMimeType("a/a")); | |
439 | |
440 ASSERT_EQ("text/plain", Toolbox::AutodetectMimeType("../NOTES.txt")); | |
441 ASSERT_EQ("text/plain", Toolbox::AutodetectMimeType("../coucou.xml/NOTES.txt")); | |
442 ASSERT_EQ("text/xml", Toolbox::AutodetectMimeType("../.xml")); | |
443 | |
444 ASSERT_EQ("application/javascript", Toolbox::AutodetectMimeType("NOTES.js")); | |
445 ASSERT_EQ("application/json", Toolbox::AutodetectMimeType("NOTES.json")); | |
446 ASSERT_EQ("application/pdf", Toolbox::AutodetectMimeType("NOTES.pdf")); | |
447 ASSERT_EQ("text/css", Toolbox::AutodetectMimeType("NOTES.css")); | |
448 ASSERT_EQ("text/html", Toolbox::AutodetectMimeType("NOTES.html")); | |
449 ASSERT_EQ("text/plain", Toolbox::AutodetectMimeType("NOTES.txt")); | |
450 ASSERT_EQ("text/xml", Toolbox::AutodetectMimeType("NOTES.xml")); | |
451 ASSERT_EQ("image/gif", Toolbox::AutodetectMimeType("NOTES.gif")); | |
452 ASSERT_EQ("image/jpeg", Toolbox::AutodetectMimeType("NOTES.jpg")); | |
453 ASSERT_EQ("image/jpeg", Toolbox::AutodetectMimeType("NOTES.jpeg")); | |
454 ASSERT_EQ("image/png", Toolbox::AutodetectMimeType("NOTES.png")); | |
455 } | |
456 | |
22 | 457 TEST(Toolbox, ComputeMD5) |
458 { | |
459 std::string s; | |
460 | |
461 // # echo -n "Hello" | md5sum | |
462 | |
463 Toolbox::ComputeMD5(s, "Hello"); | |
464 ASSERT_EQ("8b1a9953c4611296a827abf8c47804d7", s); | |
465 Toolbox::ComputeMD5(s, ""); | |
466 ASSERT_EQ("d41d8cd98f00b204e9800998ecf8427e", s); | |
467 } | |
468 | |
177 | 469 TEST(Toolbox, ComputeSHA1) |
470 { | |
471 std::string s; | |
472 | |
473 Toolbox::ComputeSHA1(s, "The quick brown fox jumps over the lazy dog"); | |
474 ASSERT_EQ("2fd4e1c6-7a2d28fc-ed849ee1-bb76e739-1b93eb12", s); | |
475 Toolbox::ComputeSHA1(s, ""); | |
476 ASSERT_EQ("da39a3ee-5e6b4b0d-3255bfef-95601890-afd80709", s); | |
477 } | |
478 | |
479 | |
809
8ce2f69436ca
do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
480 static std::string EncodeBase64Bis(const std::string& s) |
8ce2f69436ca
do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
481 { |
8ce2f69436ca
do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
482 std::string result; |
8ce2f69436ca
do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
483 Toolbox::EncodeBase64(result, s); |
8ce2f69436ca
do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
484 return result; |
8ce2f69436ca
do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
485 } |
8ce2f69436ca
do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
486 |
8ce2f69436ca
do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
487 |
24 | 488 TEST(Toolbox, Base64) |
489 { | |
809
8ce2f69436ca
do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
490 ASSERT_EQ("", EncodeBase64Bis("")); |
8ce2f69436ca
do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
491 ASSERT_EQ("YQ==", EncodeBase64Bis("a")); |
707
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
492 |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
493 const std::string hello = "SGVsbG8gd29ybGQ="; |
809
8ce2f69436ca
do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
494 ASSERT_EQ(hello, EncodeBase64Bis("Hello world")); |
8ce2f69436ca
do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
495 |
8ce2f69436ca
do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
496 std::string decoded; |
8ce2f69436ca
do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
497 Toolbox::DecodeBase64(decoded, hello); |
8ce2f69436ca
do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
498 ASSERT_EQ("Hello world", decoded); |
24 | 499 } |
500 | |
87
8517e2c44283
path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
501 TEST(Toolbox, PathToExecutable) |
8517e2c44283
path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
502 { |
8517e2c44283
path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
503 printf("[%s]\n", Toolbox::GetPathToExecutable().c_str()); |
8517e2c44283
path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
504 printf("[%s]\n", Toolbox::GetDirectoryOfExecutable().c_str()); |
8517e2c44283
path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
505 } |
8517e2c44283
path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
506 |
247
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
235
diff
changeset
|
507 TEST(Toolbox, StripSpaces) |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
235
diff
changeset
|
508 { |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
235
diff
changeset
|
509 ASSERT_EQ("", Toolbox::StripSpaces(" \t \r \n ")); |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
235
diff
changeset
|
510 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
|
511 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
|
512 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
|
513 } |
100
27dc762e3dc8
getting rid of static dcmtk for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
514 |
707
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
515 TEST(Toolbox, Case) |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
516 { |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
517 std::string s = "CoU"; |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
518 std::string ss; |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
519 |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
520 Toolbox::ToUpperCase(ss, s); |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
521 ASSERT_EQ("COU", ss); |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
522 Toolbox::ToLowerCase(ss, s); |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
523 ASSERT_EQ("cou", ss); |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
524 |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
525 s = "CoU"; |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
526 Toolbox::ToUpperCase(s); |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
527 ASSERT_EQ("COU", s); |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
528 |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
529 s = "CoU"; |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
530 Toolbox::ToLowerCase(s); |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
531 ASSERT_EQ("cou", s); |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
532 } |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
533 |
100
27dc762e3dc8
getting rid of static dcmtk for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
534 |
27dc762e3dc8
getting rid of static dcmtk for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
535 TEST(Logger, Basic) |
27dc762e3dc8
getting rid of static dcmtk for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
536 { |
102
7593b57dc1bf
switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
537 LOG(INFO) << "I say hello"; |
100
27dc762e3dc8
getting rid of static dcmtk for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
538 } |
27dc762e3dc8
getting rid of static dcmtk for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
539 |
107
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
540 TEST(Toolbox, ConvertFromLatin1) |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
541 { |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
542 // 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
|
543 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
|
544 |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
545 /*FILE* f = fopen("/tmp/tutu", "w"); |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
546 fwrite(&data[0], 9, 1, f); |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
547 fclose(f);*/ |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
548 |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
549 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
|
550 ASSERT_EQ("&abc", Toolbox::ConvertToAscii(s)); |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
551 |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
552 // Open in Emacs, then save with UTF-8 encoding, then "hexdump -C" |
949
766a57997121
enumeration for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
930
diff
changeset
|
553 std::string utf8 = Toolbox::ConvertToUtf8(s, Encoding_Latin1); |
235 | 554 ASSERT_EQ(15u, utf8.size()); |
107
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
555 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
|
556 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
|
557 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
|
558 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
|
559 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
|
560 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
|
561 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
|
562 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
|
563 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
|
564 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
|
565 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
|
566 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
|
567 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
|
568 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
|
569 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
|
570 } |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
571 |
336 | 572 TEST(Toolbox, UrlDecode) |
573 { | |
574 std::string s; | |
575 | |
576 s = "Hello%20World"; | |
577 Toolbox::UrlDecode(s); | |
578 ASSERT_EQ("Hello World", s); | |
579 | |
337 | 580 s = "%21%23%24%26%27%28%29%2A%2B%2c%2f%3A%3b%3d%3f%40%5B%5D%90%ff"; |
336 | 581 Toolbox::UrlDecode(s); |
337 | 582 std::string ss = "!#$&'()*+,/:;=?@[]"; |
583 ss.push_back((char) 144); | |
584 ss.push_back((char) 255); | |
585 ASSERT_EQ(ss, s); | |
336 | 586 |
587 s = "(2000%2C00A4)+Other"; | |
588 Toolbox::UrlDecode(s); | |
589 ASSERT_EQ("(2000,00A4) Other", s); | |
590 } | |
591 | |
100
27dc762e3dc8
getting rid of static dcmtk for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
592 |
429
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
593 #if defined(__linux) |
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
594 TEST(OrthancInitialization, AbsoluteDirectory) |
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
595 { |
810
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
809
diff
changeset
|
596 ASSERT_EQ("/tmp/hello", Configuration::InterpretRelativePath("/tmp", "hello")); |
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
809
diff
changeset
|
597 ASSERT_EQ("/tmp", Configuration::InterpretRelativePath("/tmp", "/tmp")); |
429
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
598 } |
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
599 #endif |
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
600 |
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
601 |
434
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
602 |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
603 #include "../OrthancServer/ServerEnumerations.h" |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
604 |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
605 TEST(EnumerationDictionary, Simple) |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
606 { |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
607 Toolbox::EnumerationDictionary<MetadataType> d; |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
608 |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
609 ASSERT_THROW(d.Translate("ReceptionDate"), OrthancException); |
435
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
610 ASSERT_EQ(MetadataType_ModifiedFrom, d.Translate("5")); |
436
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
435
diff
changeset
|
611 ASSERT_EQ(256, d.Translate("256")); |
434
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
612 |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
613 d.Add(MetadataType_Instance_ReceptionDate, "ReceptionDate"); |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
614 |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
615 ASSERT_EQ(MetadataType_Instance_ReceptionDate, d.Translate("ReceptionDate")); |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
616 ASSERT_EQ(MetadataType_Instance_ReceptionDate, d.Translate("2")); |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
617 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
|
618 |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
619 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
|
620 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
|
621 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
|
622 d.Add(MetadataType_ModifiedFrom, "ModifiedFrom"); // ok |
434
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
623 } |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
624 |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
625 |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
626 TEST(EnumerationDictionary, ServerEnumerations) |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
627 { |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
628 ASSERT_STREQ("Patient", EnumerationToString(ResourceType_Patient)); |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
629 ASSERT_STREQ("Study", EnumerationToString(ResourceType_Study)); |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
630 ASSERT_STREQ("Series", EnumerationToString(ResourceType_Series)); |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
631 ASSERT_STREQ("Instance", EnumerationToString(ResourceType_Instance)); |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
632 |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
633 ASSERT_STREQ("ModifiedSeries", EnumerationToString(ChangeType_ModifiedSeries)); |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
634 |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
635 ASSERT_STREQ("Failure", EnumerationToString(StoreStatus_Failure)); |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
636 ASSERT_STREQ("Success", EnumerationToString(StoreStatus_Success)); |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
637 |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
638 ASSERT_STREQ("CompletedSeries", EnumerationToString(ChangeType_CompletedSeries)); |
435
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
639 |
437 | 640 ASSERT_EQ("IndexInSeries", EnumerationToString(MetadataType_Instance_IndexInSeries)); |
641 ASSERT_EQ("LastUpdate", EnumerationToString(MetadataType_LastUpdate)); | |
435
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
642 |
559 | 643 ASSERT_EQ(ResourceType_Patient, StringToResourceType("PATienT")); |
644 ASSERT_EQ(ResourceType_Study, StringToResourceType("STudy")); | |
645 ASSERT_EQ(ResourceType_Series, StringToResourceType("SeRiEs")); | |
646 ASSERT_EQ(ResourceType_Instance, StringToResourceType("INStance")); | |
647 ASSERT_EQ(ResourceType_Instance, StringToResourceType("IMagE")); | |
648 ASSERT_THROW(StringToResourceType("heLLo"), OrthancException); | |
649 | |
435
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
650 ASSERT_EQ(2047, StringToMetadata("2047")); |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
651 ASSERT_THROW(StringToMetadata("Ceci est un test"), OrthancException); |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
652 ASSERT_THROW(RegisterUserMetadata(128, ""), OrthancException); // too low (< 1024) |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
653 ASSERT_THROW(RegisterUserMetadata(128000, ""), OrthancException); // too high (> 65535) |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
654 RegisterUserMetadata(2047, "Ceci est un test"); |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
655 ASSERT_EQ(2047, StringToMetadata("2047")); |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
656 ASSERT_EQ(2047, StringToMetadata("Ceci est un test")); |
1429
7366a0bdda6a
attempt of fix for Syngo.Via
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1428
diff
changeset
|
657 |
7366a0bdda6a
attempt of fix for Syngo.Via
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1428
diff
changeset
|
658 ASSERT_STREQ("Generic", EnumerationToString(StringToModalityManufacturer("Generic"))); |
7366a0bdda6a
attempt of fix for Syngo.Via
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1428
diff
changeset
|
659 ASSERT_STREQ("StoreScp", EnumerationToString(StringToModalityManufacturer("StoreScp"))); |
7366a0bdda6a
attempt of fix for Syngo.Via
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1428
diff
changeset
|
660 ASSERT_STREQ("ClearCanvas", EnumerationToString(StringToModalityManufacturer("ClearCanvas"))); |
7366a0bdda6a
attempt of fix for Syngo.Via
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1428
diff
changeset
|
661 ASSERT_STREQ("MedInria", EnumerationToString(StringToModalityManufacturer("MedInria"))); |
7366a0bdda6a
attempt of fix for Syngo.Via
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1428
diff
changeset
|
662 ASSERT_STREQ("Dcm4Chee", EnumerationToString(StringToModalityManufacturer("Dcm4Chee"))); |
7366a0bdda6a
attempt of fix for Syngo.Via
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1428
diff
changeset
|
663 ASSERT_STREQ("SyngoVia", EnumerationToString(StringToModalityManufacturer("SyngoVia"))); |
434
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
664 } |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
665 |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
666 |
450 | 667 |
483
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
668 TEST(Toolbox, WriteFile) |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
669 { |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
670 std::string path; |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
671 |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
672 { |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
673 Toolbox::TemporaryFile tmp; |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
674 path = tmp.GetPath(); |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
675 |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
676 std::string s; |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
677 s.append("Hello"); |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
678 s.push_back('\0'); |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
679 s.append("World"); |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
680 ASSERT_EQ(11u, s.size()); |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
681 |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
682 Toolbox::WriteFile(s, path.c_str()); |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
683 |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
684 std::string t; |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
685 Toolbox::ReadFile(t, path.c_str()); |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
686 |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
687 ASSERT_EQ(11u, t.size()); |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
688 ASSERT_EQ(0, t[5]); |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
689 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
|
690 } |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
691 |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
692 std::string u; |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
693 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
|
694 } |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
695 |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
696 |
608 | 697 TEST(Toolbox, Wildcard) |
698 { | |
699 ASSERT_EQ("abcd", Toolbox::WildcardToRegularExpression("abcd")); | |
700 ASSERT_EQ("ab.*cd", Toolbox::WildcardToRegularExpression("ab*cd")); | |
701 ASSERT_EQ("ab..cd", Toolbox::WildcardToRegularExpression("ab??cd")); | |
702 ASSERT_EQ("a.*b.c.*d", Toolbox::WildcardToRegularExpression("a*b?c*d")); | |
703 ASSERT_EQ("a\\{b\\]", Toolbox::WildcardToRegularExpression("a{b]")); | |
704 } | |
705 | |
706 | |
707 TEST(Toolbox, Tokenize) | |
708 { | |
709 std::vector<std::string> t; | |
710 | |
711 Toolbox::TokenizeString(t, "", ','); | |
1492 | 712 ASSERT_EQ(1u, t.size()); |
608 | 713 ASSERT_EQ("", t[0]); |
714 | |
715 Toolbox::TokenizeString(t, "abc", ','); | |
1492 | 716 ASSERT_EQ(1u, t.size()); |
608 | 717 ASSERT_EQ("abc", t[0]); |
718 | |
719 Toolbox::TokenizeString(t, "ab,cd,ef,", ','); | |
1492 | 720 ASSERT_EQ(4u, t.size()); |
608 | 721 ASSERT_EQ("ab", t[0]); |
722 ASSERT_EQ("cd", t[1]); | |
723 ASSERT_EQ("ef", t[2]); | |
724 ASSERT_EQ("", t[3]); | |
725 } | |
726 | |
1086
e56c3ed8d738
Parameter to set the default encoding for DICOM files without SpecificCharacterSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
727 TEST(Toolbox, Enumerations) |
e56c3ed8d738
Parameter to set the default encoding for DICOM files without SpecificCharacterSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
728 { |
e56c3ed8d738
Parameter to set the default encoding for DICOM files without SpecificCharacterSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
729 ASSERT_EQ(Encoding_Utf8, StringToEncoding(EnumerationToString(Encoding_Utf8))); |
e56c3ed8d738
Parameter to set the default encoding for DICOM files without SpecificCharacterSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
730 ASSERT_EQ(Encoding_Ascii, StringToEncoding(EnumerationToString(Encoding_Ascii))); |
e56c3ed8d738
Parameter to set the default encoding for DICOM files without SpecificCharacterSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
731 ASSERT_EQ(Encoding_Latin1, StringToEncoding(EnumerationToString(Encoding_Latin1))); |
1087 | 732 ASSERT_EQ(Encoding_Latin2, StringToEncoding(EnumerationToString(Encoding_Latin2))); |
733 ASSERT_EQ(Encoding_Latin3, StringToEncoding(EnumerationToString(Encoding_Latin3))); | |
734 ASSERT_EQ(Encoding_Latin4, StringToEncoding(EnumerationToString(Encoding_Latin4))); | |
735 ASSERT_EQ(Encoding_Latin5, StringToEncoding(EnumerationToString(Encoding_Latin5))); | |
736 ASSERT_EQ(Encoding_Cyrillic, StringToEncoding(EnumerationToString(Encoding_Cyrillic))); | |
737 ASSERT_EQ(Encoding_Arabic, StringToEncoding(EnumerationToString(Encoding_Arabic))); | |
738 ASSERT_EQ(Encoding_Greek, StringToEncoding(EnumerationToString(Encoding_Greek))); | |
739 ASSERT_EQ(Encoding_Hebrew, StringToEncoding(EnumerationToString(Encoding_Hebrew))); | |
1090
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1087
diff
changeset
|
740 ASSERT_EQ(Encoding_Japanese, StringToEncoding(EnumerationToString(Encoding_Japanese))); |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1087
diff
changeset
|
741 ASSERT_EQ(Encoding_Chinese, StringToEncoding(EnumerationToString(Encoding_Chinese))); |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1087
diff
changeset
|
742 ASSERT_EQ(Encoding_Thai, StringToEncoding(EnumerationToString(Encoding_Thai))); |
1086
e56c3ed8d738
Parameter to set the default encoding for DICOM files without SpecificCharacterSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
743 |
e56c3ed8d738
Parameter to set the default encoding for DICOM files without SpecificCharacterSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
744 ASSERT_EQ(ResourceType_Patient, StringToResourceType(EnumerationToString(ResourceType_Patient))); |
e56c3ed8d738
Parameter to set the default encoding for DICOM files without SpecificCharacterSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
745 ASSERT_EQ(ResourceType_Study, StringToResourceType(EnumerationToString(ResourceType_Study))); |
e56c3ed8d738
Parameter to set the default encoding for DICOM files without SpecificCharacterSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
746 ASSERT_EQ(ResourceType_Series, StringToResourceType(EnumerationToString(ResourceType_Series))); |
e56c3ed8d738
Parameter to set the default encoding for DICOM files without SpecificCharacterSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
747 ASSERT_EQ(ResourceType_Instance, StringToResourceType(EnumerationToString(ResourceType_Instance))); |
e56c3ed8d738
Parameter to set the default encoding for DICOM files without SpecificCharacterSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
748 |
e56c3ed8d738
Parameter to set the default encoding for DICOM files without SpecificCharacterSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
749 ASSERT_EQ(ImageFormat_Png, StringToImageFormat(EnumerationToString(ImageFormat_Png))); |
e56c3ed8d738
Parameter to set the default encoding for DICOM files without SpecificCharacterSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
750 } |
e56c3ed8d738
Parameter to set the default encoding for DICOM files without SpecificCharacterSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
751 |
608 | 752 |
674
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
753 |
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
754 #if defined(__linux) |
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
755 #include <endian.h> |
1337 | 756 #elif defined(__FreeBSD__) |
757 #include <machine/endian.h> | |
674
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
758 #endif |
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
759 |
1337 | 760 |
637 | 761 TEST(Toolbox, Endianness) |
762 { | |
674
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
763 // Parts of this test come from Adam Conrad |
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
764 // http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=728822#5 |
637 | 765 |
1337 | 766 |
767 /** | |
768 * Windows and OS X are assumed to always little-endian. | |
769 **/ | |
770 | |
771 #if defined(_WIN32) || defined(__APPLE__) | |
637 | 772 ASSERT_EQ(Endianness_Little, Toolbox::DetectEndianness()); |
674
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
773 |
918 | 774 |
1337 | 775 /** |
776 * Linux. | |
777 **/ | |
778 | |
890 | 779 #elif defined(__linux) || defined(__FreeBSD_kernel__) |
674
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
780 |
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
781 #if !defined(__BYTE_ORDER) |
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
782 # error Support your platform here |
637 | 783 #endif |
784 | |
674
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
785 # if __BYTE_ORDER == __BIG_ENDIAN |
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
786 ASSERT_EQ(Endianness_Big, Toolbox::DetectEndianness()); |
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
787 # else // __LITTLE_ENDIAN |
637 | 788 ASSERT_EQ(Endianness_Little, Toolbox::DetectEndianness()); |
674
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
789 # endif |
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
790 |
1337 | 791 |
792 /** | |
793 * FreeBSD. | |
794 **/ | |
795 | |
796 #elif defined(__FreeBSD__) | |
797 # if _BYTE_ORDER == _BIG_ENDIAN | |
798 ASSERT_EQ(Endianness_Big, Toolbox::DetectEndianness()); | |
799 # else // _LITTLE_ENDIAN | |
800 ASSERT_EQ(Endianness_Little, Toolbox::DetectEndianness()); | |
801 # endif | |
802 | |
674
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
803 #else |
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
804 #error Support your platform here |
637 | 805 #endif |
806 } | |
807 | |
808 | |
1045
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
809 #if ORTHANC_PUGIXML_ENABLED == 1 |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
810 TEST(Toolbox, Xml) |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
811 { |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
812 Json::Value a; |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
813 a["hello"] = "world"; |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
814 a["42"] = 43; |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
815 a["b"] = Json::arrayValue; |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
816 a["b"].append("test"); |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
817 a["b"].append("test2"); |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
818 |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
819 std::string s; |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
820 Toolbox::JsonToXml(s, a); |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
821 |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
822 std::cout << s; |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
823 } |
1050
64f1842aae2e
Toolbox::ExecuteSystemCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1045
diff
changeset
|
824 #endif |
1045
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
825 |
1050
64f1842aae2e
Toolbox::ExecuteSystemCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1045
diff
changeset
|
826 |
64f1842aae2e
Toolbox::ExecuteSystemCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1045
diff
changeset
|
827 #if !defined(_WIN32) |
64f1842aae2e
Toolbox::ExecuteSystemCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1045
diff
changeset
|
828 TEST(Toolbox, ExecuteSystemCommand) |
64f1842aae2e
Toolbox::ExecuteSystemCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1045
diff
changeset
|
829 { |
64f1842aae2e
Toolbox::ExecuteSystemCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1045
diff
changeset
|
830 std::vector<std::string> args(2); |
64f1842aae2e
Toolbox::ExecuteSystemCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1045
diff
changeset
|
831 args[0] = "Hello"; |
64f1842aae2e
Toolbox::ExecuteSystemCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1045
diff
changeset
|
832 args[1] = "World"; |
64f1842aae2e
Toolbox::ExecuteSystemCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1045
diff
changeset
|
833 |
64f1842aae2e
Toolbox::ExecuteSystemCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1045
diff
changeset
|
834 Toolbox::ExecuteSystemCommand("echo", args); |
64f1842aae2e
Toolbox::ExecuteSystemCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1045
diff
changeset
|
835 } |
1045
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
836 #endif |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
837 |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
838 |
1102
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1090
diff
changeset
|
839 TEST(Toolbox, IsInteger) |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1090
diff
changeset
|
840 { |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1090
diff
changeset
|
841 ASSERT_TRUE(Toolbox::IsInteger("00236")); |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1090
diff
changeset
|
842 ASSERT_TRUE(Toolbox::IsInteger("-0042")); |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1090
diff
changeset
|
843 ASSERT_TRUE(Toolbox::IsInteger("0")); |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1090
diff
changeset
|
844 ASSERT_TRUE(Toolbox::IsInteger("-0")); |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1090
diff
changeset
|
845 |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1090
diff
changeset
|
846 ASSERT_FALSE(Toolbox::IsInteger("")); |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1090
diff
changeset
|
847 ASSERT_FALSE(Toolbox::IsInteger("42a")); |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1090
diff
changeset
|
848 ASSERT_FALSE(Toolbox::IsInteger("42-")); |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1090
diff
changeset
|
849 } |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1090
diff
changeset
|
850 |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1090
diff
changeset
|
851 |
1430
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1429
diff
changeset
|
852 TEST(Toolbox, StartsWith) |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1429
diff
changeset
|
853 { |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1429
diff
changeset
|
854 ASSERT_TRUE(Toolbox::StartsWith("hello world", "")); |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1429
diff
changeset
|
855 ASSERT_TRUE(Toolbox::StartsWith("hello world", "hello")); |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1429
diff
changeset
|
856 ASSERT_TRUE(Toolbox::StartsWith("hello world", "h")); |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1429
diff
changeset
|
857 ASSERT_FALSE(Toolbox::StartsWith("hello world", "H")); |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1429
diff
changeset
|
858 ASSERT_FALSE(Toolbox::StartsWith("h", "hello")); |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1429
diff
changeset
|
859 ASSERT_TRUE(Toolbox::StartsWith("h", "h")); |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1429
diff
changeset
|
860 ASSERT_FALSE(Toolbox::StartsWith("", "h")); |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1429
diff
changeset
|
861 } |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1429
diff
changeset
|
862 |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1429
diff
changeset
|
863 |
0 | 864 int main(int argc, char **argv) |
865 { | |
1485
27661b33f624
Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
866 Logging::Initialize(); |
27661b33f624
Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
867 Logging::EnableInfoLevel(true); |
27661b33f624
Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
868 Toolbox::DetectEndianness(); |
27661b33f624
Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
869 Toolbox::MakeDirectory("UnitTestsResults"); |
27661b33f624
Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
870 OrthancInitialize(); |
159
c08fbad40ddd
less verbosity in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
871 |
0 | 872 ::testing::InitGoogleTest(&argc, argv); |
873 int result = RUN_ALL_TESTS(); | |
1485
27661b33f624
Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
874 |
63 | 875 OrthancFinalize(); |
1485
27661b33f624
Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
876 Logging::Finalize(); |
27661b33f624
Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
877 |
0 | 878 return result; |
879 } |