comparison UnitTestsSources/UnitTestsMain.cpp @ 1023:226cfef3822e templating

integration mainline->templating
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 10 Jul 2014 11:42:32 +0200
parents 509e146c3cb3
children 0bfeeb6d340f
comparison
equal deleted inserted replaced
945:427a1f996b7b 1023:226cfef3822e
172 c.Uncompress(uncompressed, vv); 172 c.Uncompress(uncompressed, vv);
173 ASSERT_EQ(0u, uncompressed.size()); 173 ASSERT_EQ(0u, uncompressed.size());
174 } 174 }
175 175
176 176
177 TEST(ParseGetQuery, Basic) 177 TEST(ParseGetArguments, Basic)
178 { 178 {
179 HttpHandler::Arguments a; 179 HttpHandler::Arguments a;
180 HttpHandler::ParseGetQuery(a, "aaa=baaa&bb=a&aa=c"); 180 HttpHandler::ParseGetArguments(a, "aaa=baaa&bb=a&aa=c");
181 ASSERT_EQ(3u, a.size()); 181 ASSERT_EQ(3u, a.size());
182 ASSERT_EQ(a["aaa"], "baaa"); 182 ASSERT_EQ(a["aaa"], "baaa");
183 ASSERT_EQ(a["bb"], "a"); 183 ASSERT_EQ(a["bb"], "a");
184 ASSERT_EQ(a["aa"], "c"); 184 ASSERT_EQ(a["aa"], "c");
185 } 185 }
186 186
187 TEST(ParseGetQuery, BasicEmpty) 187 TEST(ParseGetArguments, BasicEmpty)
188 { 188 {
189 HttpHandler::Arguments a; 189 HttpHandler::Arguments a;
190 HttpHandler::ParseGetQuery(a, "aaa&bb=aa&aa"); 190 HttpHandler::ParseGetArguments(a, "aaa&bb=aa&aa");
191 ASSERT_EQ(3u, a.size()); 191 ASSERT_EQ(3u, a.size());
192 ASSERT_EQ(a["aaa"], ""); 192 ASSERT_EQ(a["aaa"], "");
193 ASSERT_EQ(a["bb"], "aa"); 193 ASSERT_EQ(a["bb"], "aa");
194 ASSERT_EQ(a["aa"], ""); 194 ASSERT_EQ(a["aa"], "");
195 } 195 }
196 196
197 TEST(ParseGetQuery, Single) 197 TEST(ParseGetArguments, Single)
198 { 198 {
199 HttpHandler::Arguments a; 199 HttpHandler::Arguments a;
200 HttpHandler::ParseGetQuery(a, "aaa=baaa"); 200 HttpHandler::ParseGetArguments(a, "aaa=baaa");
201 ASSERT_EQ(1u, a.size()); 201 ASSERT_EQ(1u, a.size());
202 ASSERT_EQ(a["aaa"], "baaa"); 202 ASSERT_EQ(a["aaa"], "baaa");
203 } 203 }
204 204
205 TEST(ParseGetQuery, SingleEmpty) 205 TEST(ParseGetArguments, SingleEmpty)
206 { 206 {
207 HttpHandler::Arguments a; 207 HttpHandler::Arguments a;
208 HttpHandler::ParseGetQuery(a, "aaa"); 208 HttpHandler::ParseGetArguments(a, "aaa");
209 ASSERT_EQ(1u, a.size()); 209 ASSERT_EQ(1u, a.size());
210 ASSERT_EQ(a["aaa"], ""); 210 ASSERT_EQ(a["aaa"], "");
211 } 211 }
212 212
213 TEST(ParseGetQuery, Test1)
214 {
215 UriComponents uri;
216 HttpHandler::Arguments a;
217 HttpHandler::ParseGetQuery(uri, a, "/instances/test/world?aaa=baaa&bb=a&aa=c");
218 ASSERT_EQ(3u, uri.size());
219 ASSERT_EQ("instances", uri[0]);
220 ASSERT_EQ("test", uri[1]);
221 ASSERT_EQ("world", uri[2]);
222 ASSERT_EQ(3u, a.size());
223 ASSERT_EQ(a["aaa"], "baaa");
224 ASSERT_EQ(a["bb"], "a");
225 ASSERT_EQ(a["aa"], "c");
226 }
227
228 TEST(ParseGetQuery, Test2)
229 {
230 UriComponents uri;
231 HttpHandler::Arguments a;
232 HttpHandler::ParseGetQuery(uri, a, "/instances/test/world");
233 ASSERT_EQ(3u, uri.size());
234 ASSERT_EQ("instances", uri[0]);
235 ASSERT_EQ("test", uri[1]);
236 ASSERT_EQ("world", uri[2]);
237 ASSERT_EQ(0u, a.size());
238 }
239
213 TEST(Uri, SplitUriComponents) 240 TEST(Uri, SplitUriComponents)
214 { 241 {
215 UriComponents c; 242 UriComponents c, d;
216 Toolbox::SplitUriComponents(c, "/cou/hello/world"); 243 Toolbox::SplitUriComponents(c, "/cou/hello/world");
217 ASSERT_EQ(3u, c.size()); 244 ASSERT_EQ(3u, c.size());
218 ASSERT_EQ("cou", c[0]); 245 ASSERT_EQ("cou", c[0]);
219 ASSERT_EQ("hello", c[1]); 246 ASSERT_EQ("hello", c[1]);
220 ASSERT_EQ("world", c[2]); 247 ASSERT_EQ("world", c[2]);
248 ASSERT_THROW(Toolbox::SplitUriComponents(c, "/coucou//coucou"), OrthancException); 275 ASSERT_THROW(Toolbox::SplitUriComponents(c, "/coucou//coucou"), OrthancException);
249 276
250 c.clear(); 277 c.clear();
251 c.push_back("test"); 278 c.push_back("test");
252 ASSERT_EQ("/", Toolbox::FlattenUri(c, 10)); 279 ASSERT_EQ("/", Toolbox::FlattenUri(c, 10));
280 }
281
282
283 TEST(Uri, Truncate)
284 {
285 UriComponents c, d;
286 Toolbox::SplitUriComponents(c, "/cou/hello/world");
287
288 Toolbox::TruncateUri(d, c, 0);
289 ASSERT_EQ(3u, d.size());
290 ASSERT_EQ("cou", d[0]);
291 ASSERT_EQ("hello", d[1]);
292 ASSERT_EQ("world", d[2]);
293
294 Toolbox::TruncateUri(d, c, 1);
295 ASSERT_EQ(2u, d.size());
296 ASSERT_EQ("hello", d[0]);
297 ASSERT_EQ("world", d[1]);
298
299 Toolbox::TruncateUri(d, c, 2);
300 ASSERT_EQ(1u, d.size());
301 ASSERT_EQ("world", d[0]);
302
303 Toolbox::TruncateUri(d, c, 3);
304 ASSERT_EQ(0u, d.size());
305
306 Toolbox::TruncateUri(d, c, 4);
307 ASSERT_EQ(0u, d.size());
308
309 Toolbox::TruncateUri(d, c, 5);
310 ASSERT_EQ(0u, d.size());
253 } 311 }
254 312
255 313
256 TEST(Uri, Child) 314 TEST(Uri, Child)
257 { 315 {
412 470
413 std::string s((char*) &data[0], 10); 471 std::string s((char*) &data[0], 10);
414 ASSERT_EQ("&abc", Toolbox::ConvertToAscii(s)); 472 ASSERT_EQ("&abc", Toolbox::ConvertToAscii(s));
415 473
416 // Open in Emacs, then save with UTF-8 encoding, then "hexdump -C" 474 // Open in Emacs, then save with UTF-8 encoding, then "hexdump -C"
417 std::string utf8 = Toolbox::ConvertToUtf8(s, "ISO-8859-1"); 475 std::string utf8 = Toolbox::ConvertToUtf8(s, Encoding_Latin1);
418 ASSERT_EQ(15u, utf8.size()); 476 ASSERT_EQ(15u, utf8.size());
419 ASSERT_EQ(0xc3, static_cast<unsigned char>(utf8[0])); 477 ASSERT_EQ(0xc3, static_cast<unsigned char>(utf8[0]));
420 ASSERT_EQ(0xa0, static_cast<unsigned char>(utf8[1])); 478 ASSERT_EQ(0xa0, static_cast<unsigned char>(utf8[1]));
421 ASSERT_EQ(0xc3, static_cast<unsigned char>(utf8[2])); 479 ASSERT_EQ(0xc3, static_cast<unsigned char>(utf8[2]));
422 ASSERT_EQ(0xa9, static_cast<unsigned char>(utf8[3])); 480 ASSERT_EQ(0xa9, static_cast<unsigned char>(utf8[3]));