comparison UnitTestsSources/UnitTestsMain.cpp @ 1441:f3672356c121

refactoring: IHttpHandler and HttpToolbox
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 01 Jul 2015 10:38:39 +0200
parents ad94a3583b07
children 27661b33f624
comparison
equal deleted inserted replaced
1440:3567503c00a7 1441:f3672356c121
37 37
38 #include <ctype.h> 38 #include <ctype.h>
39 39
40 #include "../Core/Compression/ZlibCompressor.h" 40 #include "../Core/Compression/ZlibCompressor.h"
41 #include "../Core/DicomFormat/DicomTag.h" 41 #include "../Core/DicomFormat/DicomTag.h"
42 #include "../Core/HttpServer/HttpHandler.h" 42 #include "../Core/HttpServer/HttpToolbox.h"
43 #include "../Core/OrthancException.h" 43 #include "../Core/OrthancException.h"
44 #include "../Core/Toolbox.h" 44 #include "../Core/Toolbox.h"
45 #include "../Core/Uuid.h" 45 #include "../Core/Uuid.h"
46 #include "../OrthancServer/OrthancInitialization.h" 46 #include "../OrthancServer/OrthancInitialization.h"
47 47
186 } 186 }
187 187
188 188
189 TEST(ParseGetArguments, Basic) 189 TEST(ParseGetArguments, Basic)
190 { 190 {
191 HttpHandler::GetArguments b; 191 IHttpHandler::GetArguments b;
192 HttpHandler::ParseGetArguments(b, "aaa=baaa&bb=a&aa=c"); 192 HttpToolbox::ParseGetArguments(b, "aaa=baaa&bb=a&aa=c");
193 193
194 HttpHandler::Arguments a; 194 IHttpHandler::Arguments a;
195 HttpHandler::CompileGetArguments(a, b); 195 HttpToolbox::CompileGetArguments(a, b);
196 196
197 ASSERT_EQ(3u, a.size()); 197 ASSERT_EQ(3u, a.size());
198 ASSERT_EQ(a["aaa"], "baaa"); 198 ASSERT_EQ(a["aaa"], "baaa");
199 ASSERT_EQ(a["bb"], "a"); 199 ASSERT_EQ(a["bb"], "a");
200 ASSERT_EQ(a["aa"], "c"); 200 ASSERT_EQ(a["aa"], "c");
201 } 201 }
202 202
203 TEST(ParseGetArguments, BasicEmpty) 203 TEST(ParseGetArguments, BasicEmpty)
204 { 204 {
205 HttpHandler::GetArguments b; 205 IHttpHandler::GetArguments b;
206 HttpHandler::ParseGetArguments(b, "aaa&bb=aa&aa"); 206 HttpToolbox::ParseGetArguments(b, "aaa&bb=aa&aa");
207 207
208 HttpHandler::Arguments a; 208 IHttpHandler::Arguments a;
209 HttpHandler::CompileGetArguments(a, b); 209 HttpToolbox::CompileGetArguments(a, b);
210 210
211 ASSERT_EQ(3u, a.size()); 211 ASSERT_EQ(3u, a.size());
212 ASSERT_EQ(a["aaa"], ""); 212 ASSERT_EQ(a["aaa"], "");
213 ASSERT_EQ(a["bb"], "aa"); 213 ASSERT_EQ(a["bb"], "aa");
214 ASSERT_EQ(a["aa"], ""); 214 ASSERT_EQ(a["aa"], "");
215 } 215 }
216 216
217 TEST(ParseGetArguments, Single) 217 TEST(ParseGetArguments, Single)
218 { 218 {
219 HttpHandler::GetArguments b; 219 IHttpHandler::GetArguments b;
220 HttpHandler::ParseGetArguments(b, "aaa=baaa"); 220 HttpToolbox::ParseGetArguments(b, "aaa=baaa");
221 221
222 HttpHandler::Arguments a; 222 IHttpHandler::Arguments a;
223 HttpHandler::CompileGetArguments(a, b); 223 HttpToolbox::CompileGetArguments(a, b);
224 224
225 ASSERT_EQ(1u, a.size()); 225 ASSERT_EQ(1u, a.size());
226 ASSERT_EQ(a["aaa"], "baaa"); 226 ASSERT_EQ(a["aaa"], "baaa");
227 } 227 }
228 228
229 TEST(ParseGetArguments, SingleEmpty) 229 TEST(ParseGetArguments, SingleEmpty)
230 { 230 {
231 HttpHandler::GetArguments b; 231 IHttpHandler::GetArguments b;
232 HttpHandler::ParseGetArguments(b, "aaa"); 232 HttpToolbox::ParseGetArguments(b, "aaa");
233 233
234 HttpHandler::Arguments a; 234 IHttpHandler::Arguments a;
235 HttpHandler::CompileGetArguments(a, b); 235 HttpToolbox::CompileGetArguments(a, b);
236 236
237 ASSERT_EQ(1u, a.size()); 237 ASSERT_EQ(1u, a.size());
238 ASSERT_EQ(a["aaa"], ""); 238 ASSERT_EQ(a["aaa"], "");
239 } 239 }
240 240
241 TEST(ParseGetQuery, Test1) 241 TEST(ParseGetQuery, Test1)
242 { 242 {
243 UriComponents uri; 243 UriComponents uri;
244 HttpHandler::GetArguments b; 244 IHttpHandler::GetArguments b;
245 HttpHandler::ParseGetQuery(uri, b, "/instances/test/world?aaa=baaa&bb=a&aa=c"); 245 HttpToolbox::ParseGetQuery(uri, b, "/instances/test/world?aaa=baaa&bb=a&aa=c");
246 246
247 HttpHandler::Arguments a; 247 IHttpHandler::Arguments a;
248 HttpHandler::CompileGetArguments(a, b); 248 HttpToolbox::CompileGetArguments(a, b);
249 249
250 ASSERT_EQ(3u, uri.size()); 250 ASSERT_EQ(3u, uri.size());
251 ASSERT_EQ("instances", uri[0]); 251 ASSERT_EQ("instances", uri[0]);
252 ASSERT_EQ("test", uri[1]); 252 ASSERT_EQ("test", uri[1]);
253 ASSERT_EQ("world", uri[2]); 253 ASSERT_EQ("world", uri[2]);
258 } 258 }
259 259
260 TEST(ParseGetQuery, Test2) 260 TEST(ParseGetQuery, Test2)
261 { 261 {
262 UriComponents uri; 262 UriComponents uri;
263 HttpHandler::GetArguments b; 263 IHttpHandler::GetArguments b;
264 HttpHandler::ParseGetQuery(uri, b, "/instances/test/world"); 264 HttpToolbox::ParseGetQuery(uri, b, "/instances/test/world");
265 265
266 HttpHandler::Arguments a; 266 IHttpHandler::Arguments a;
267 HttpHandler::CompileGetArguments(a, b); 267 HttpToolbox::CompileGetArguments(a, b);
268 268
269 ASSERT_EQ(3u, uri.size()); 269 ASSERT_EQ(3u, uri.size());
270 ASSERT_EQ("instances", uri[0]); 270 ASSERT_EQ("instances", uri[0]);
271 ASSERT_EQ("test", uri[1]); 271 ASSERT_EQ("test", uri[1]);
272 ASSERT_EQ("world", uri[2]); 272 ASSERT_EQ("world", uri[2]);