2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * @file TestSuite05.cpp
20 * @brief Test cases for Attribute class.
28 #include <dpl/test/test_runner.h>
30 #include <dpl/ace/Attribute.h>
31 #include <dpl/ace-dao-ro/BaseAttribute.h>
33 #define TESTSUITE05(n) \
34 RUNNER_TEST(ts05_attr_tests_ ## n)
36 class AT : public Attribute {
42 static std::string* uriAuthorityStatic(const std::string *input) {
44 return at.uriAuthority(input);
47 static std::string* uriHostStatic(const std::string *input) {
49 return at.uriHost(input);
52 static std::string* uriSchemeStatic(const std::string *input) {
54 return at.uriScheme(input);
57 static std::string* uriSchemeAuthorityStatic(const std::string *input) {
58 AT at("Winnie the Pooh");
59 return at.uriSchemeAuthority(input);
62 static std::string* uriPathStatic(const std::string *input) {
64 return at.uriPath(input);
67 static bool markTest(){
69 for(int i =0; i<128; ++i){
70 if( i == '-' || i == '_' || i == '.'|| i == '!'|| i == '~' || i == '*' || i == '\'' || i == ')' || i == '(' ){
86 static bool digitTest(){
88 for(int i =0; i<128; ++i){
89 if( i > 47 && i < 58 ){
105 static bool alphaTest(){
107 for(int i =0; i<128; ++i){
108 if( ( i>64 && i<91 ) || ( i>96 && i<123 ) ) {
124 static bool isEscapedStatic(const char esc[3]) {
126 return at.isEscaped(esc);
130 bool assertEqual(const std::string * actual, const char * intended) {
131 if (actual == NULL || intended == NULL) {
132 if (intended == NULL && actual == NULL) {
140 std::string temp(intended);
142 if (temp == *actual) {
150 bool assertTrue(bool condition){
154 bool assertFalse(bool condition){
158 TESTSUITE05(01_uriAuthority){
159 std::string * outcome = NULL;
160 std::string query("http://www.wp.pl");
161 outcome = AT::uriAuthorityStatic(&query);
162 RUNNER_ASSERT(assertEqual(outcome, "www.wp.pl"));
166 TESTSUITE05(02_uriAuthority){
167 std::string * outcome = NULL;
168 std::string query("http://authority?path/asdf");
169 outcome = AT::uriAuthorityStatic(&query);
170 RUNNER_ASSERT(assertEqual(outcome, "authority"));
174 TESTSUITE05(03_uriAuthority){
175 std::string * outcome = NULL;
176 std::string query("abcd"); //This should be interpreted as schema
177 outcome = AT::uriAuthorityStatic(&query);
178 RUNNER_ASSERT(assertEqual(outcome, ""));
182 TESTSUITE05(04_uriAuthority){
183 std::string * outcome = NULL;
184 std::string query("http://authority/asdf");
185 outcome = AT::uriAuthorityStatic(&query);
186 RUNNER_ASSERT(assertEqual(outcome, "authority"));
190 TESTSUITE05(05_uriAuthority){
191 std::string * outcome = NULL;
192 std::string query("http://user@host:20?ds");
193 outcome = AT::uriAuthorityStatic(&query);
194 RUNNER_ASSERT(assertEqual(outcome, "user@host:20"));
198 TESTSUITE05(06_uriAuthority){
199 std::string * outcome = NULL;
200 std::string query("http://hostname:23");
201 outcome = AT::uriAuthorityStatic(&query);
202 RUNNER_ASSERT(assertEqual(outcome, "hostname:23"));
206 TESTSUITE05(07_uriAuthority){
207 std::string * outcome = NULL;
208 std::string query("http://user@host:port");
209 outcome = AT::uriAuthorityStatic(&query);
210 RUNNER_ASSERT(assertEqual(outcome, "user@host:port"));
214 TESTSUITE05(08_uriAuthority){
215 std::string * outcome = NULL;
216 std::string query("http://1user@host:port"); //This is a VALID URI
217 outcome = AT::uriAuthorityStatic(&query);
218 RUNNER_ASSERT(assertEqual(outcome, "1user@host:port"));
222 TESTSUITE05(09_uriAuthority){
223 std::string * outcome = NULL;
224 std::string query("http://abc%30"); //This is not a valid uri
225 outcome = AT::uriAuthorityStatic(&query);
226 RUNNER_ASSERT(assertEqual(outcome, "abc%30"));
230 TESTSUITE05(10_uriAuthority){
231 std::string * outcome = NULL;
232 std::string query("http:///asd"); //This is not a valid uri
233 outcome = AT::uriAuthorityStatic(&query);
234 RUNNER_ASSERT(assertEqual(outcome, ""));
238 TESTSUITE05(11_uriAuthority){
239 std::string * outcome = NULL;
240 std::string query("http://?asd"); //This is not a valid uri
241 outcome = AT::uriAuthorityStatic(&query);
242 RUNNER_ASSERT(assertEqual(outcome, ""));
246 TESTSUITE05(12_uriAuthority){
247 std::string * outcome = NULL;
248 std::string query("http://%34%56%67%ab");
249 outcome = AT::uriAuthorityStatic(&query);
250 RUNNER_ASSERT(assertEqual(outcome, "%34%56%67%ab"));
254 TESTSUITE05(13_uriAuthority){
255 std::string * outcome = NULL;
256 std::string query("http://<>"); //This is not a valid uri
257 outcome = AT::uriAuthorityStatic(&query);
258 RUNNER_ASSERT(assertEqual(outcome, NULL));
262 TESTSUITE05(14_uriAuthority){
263 std::string * outcome = NULL;
264 std::string query("http://\\/"); //This is not a valid uri
265 outcome = AT::uriAuthorityStatic(&query);
266 RUNNER_ASSERT(assertEqual(outcome, NULL));
270 TESTSUITE05(15_uriHost){
271 std::string * outcome = NULL;
272 std::string query("http://user@host:23");
273 outcome = AT::uriHostStatic(&query);
274 RUNNER_ASSERT(assertEqual(outcome, "host"));
278 TESTSUITE05(16_uriHost){
279 std::string * outcome = NULL;
280 std::string query("http://user@host:name"); //This is not a valid uri
281 outcome = AT::uriHostStatic(&query);
282 RUNNER_ASSERT(assertEqual(outcome, ""));
286 TESTSUITE05(17_uriHost){
287 std::string * outcome = NULL;
288 std::string query("http::::"); //This is a valid uri
289 outcome = AT::uriHostStatic(&query);
290 RUNNER_ASSERT(assertEqual(outcome, ""));
294 TESTSUITE05(18_uriHost){
295 std::string * outcome = NULL;
296 std::string query("..%%%."); //This is not a valid uri
297 outcome = AT::uriHostStatic(&query);
298 RUNNER_ASSERT(assertEqual(outcome, NULL));
302 TESTSUITE05(19_uriHost){
303 std::string * outcome = NULL;
304 std::string query("ftp://abds.eu/fda");
305 outcome = AT::uriHostStatic(&query);
306 RUNNER_ASSERT(assertEqual(outcome, "abds.eu"));
310 TESTSUITE05(20_uriHost){
311 std::string * outcome = NULL;
312 std::string query("abs%14ccc");
313 //This is a valid uri because it's interpreted as a path not a host
314 outcome = AT::uriHostStatic(&query);
315 RUNNER_ASSERT(assertEqual(outcome, ""));
319 TESTSUITE05(21_uriHost){
320 std::string * outcome = NULL;
321 std::string query("http://abc@123.2.23.213:982");
322 outcome = AT::uriHostStatic(&query);
323 RUNNER_ASSERT(assertEqual(outcome, "123.2.23.213"));
327 TESTSUITE05(22_uriHost){
328 std::string * outcome = NULL;
329 std::string query("http://abc@1233.2.23.213:982");
330 //Hostname is invalid, but uri is valid
331 outcome = AT::uriHostStatic(&query);
332 RUNNER_ASSERT(assertEqual(outcome, ""));
336 TESTSUITE05(23_uriHost){
337 std::string * outcome = NULL;
338 std::string query("http://ab%23c@host"); //Valid escaped characters
339 outcome = AT::uriHostStatic(&query);
340 RUNNER_ASSERT(assertEqual(outcome, "host"));
344 TESTSUITE05(24_uriHost){
345 std::string * outcome = NULL;
346 std::string query("http://ab%23c@host%34"); //Invalid escaped characters in hostname
347 outcome = AT::uriHostStatic(&query);
348 RUNNER_ASSERT(assertEqual(outcome, ""));
352 TESTSUITE05(25_uriHost){
353 std::string * outcome = NULL;
354 std::string query("http://ab%GGc@host"); //Wrong character %
355 outcome = AT::uriHostStatic(&query);
356 RUNNER_ASSERT(assertEqual(outcome, NULL));
360 TESTSUITE05(26_uriHost){
361 std::string * outcome = NULL;
362 std::string query("http://www.example.pl");
363 outcome = AT::uriHostStatic(&query);
364 RUNNER_ASSERT(assertEqual(outcome, "www.example.pl"));
368 TESTSUITE05(27_uriScheme){
369 std::string * outcome = NULL;
370 std::string query("http://host");
371 outcome = AT::uriSchemeStatic(&query);
372 RUNNER_ASSERT(assertEqual(outcome, "http"));
376 TESTSUITE05(28_uriScheme){
377 std::string * outcome = NULL;
378 //Wrong character '1' in scheme , it's not an URI because two slashes are not acceptable
379 //in any other place than in separation between scheme and pat
380 std::string query("1http://host");
381 outcome = AT::uriSchemeStatic(&query);
382 RUNNER_ASSERT(assertEqual(outcome, NULL));
386 TESTSUITE05(29_uriScheme){
387 std::string * outcome = NULL;
388 std::string query("ftp+a-fdf.ads://host");
389 outcome = AT::uriSchemeStatic(&query);
390 RUNNER_ASSERT(assertEqual(outcome, "ftp+a-fdf.ads"));
394 TESTSUITE05(30_uriScheme){
395 std::string * outcome = NULL;
396 //Scheme cannot start with plus, it's not an URI because two slashes are not acceptable
397 //in any other place than in separation between scheme and path
398 std::string query("+++://host");
399 outcome = AT::uriSchemeStatic(&query);
400 RUNNER_ASSERT(assertEqual(outcome, NULL));
404 TESTSUITE05(31_uriScheme){
405 std::string * outcome = NULL;
406 std::string query("aaaac"); //It's a path not a scheme'a
407 outcome = AT::uriSchemeStatic(&query);
408 RUNNER_ASSERT(assertEqual(outcome, ""));
412 TESTSUITE05(32_uriScheme){
413 std::string * outcome = NULL;
414 //no escaped characters in schema, it's not an URI because two slashes are not acceptable
415 //in any other place than in separation between scheme and path
416 std::string query("ftpa%34fdfads://host");
417 outcome = AT::uriSchemeStatic(&query);
418 RUNNER_ASSERT(assertEqual(outcome, NULL));
422 TESTSUITE05(33_uriScheme){
423 std::string * outcome = NULL;
424 //no escaped characters in schema, it's not an URI because two slashes are not acceptable
425 //in any other place than in separation between scheme and path
426 std::string query("meaninglessstring://host%34");
427 outcome = AT::uriSchemeStatic(&query);
428 RUNNER_ASSERT(assertEqual(outcome, "meaninglessstring"));
432 TESTSUITE05(34_uriScheme){
433 std::string * outcome = NULL;
434 std::string query("meaninglessstring2://");
435 outcome = AT::uriSchemeStatic(&query);
436 RUNNER_ASSERT(assertEqual(outcome, "meaninglessstring2"));
440 TESTSUITE05(35_uriScheme){
441 std::string * outcome = NULL;
442 std::string query("http://www.samsung.com/ace/bondi#5");
443 outcome = AT::uriSchemeStatic(&query);
444 RUNNER_ASSERT(assertEqual(outcome, "http"));
448 TESTSUITE05(36_uriScheme){
449 std::string * outcome = NULL;
450 std::string query("www.samsung.com");
451 outcome = AT::uriSchemeStatic(&query);
452 RUNNER_ASSERT(assertEqual(outcome, ""));
456 TESTSUITE05(37_uriSchemeAuthority){
457 std::string * outcome = NULL;
458 std::string query("http://www.samsung.com");
459 outcome = AT::uriSchemeAuthorityStatic(&query);
460 RUNNER_ASSERT(assertEqual(outcome, "http://www.samsung.com"));
464 TESTSUITE05(38_uriSchemeAuthority){
465 std::string * outcome = NULL;
466 std::string query("ftp23://www.samsung.com/avc%23");
467 outcome = AT::uriSchemeAuthorityStatic(&query);
468 RUNNER_ASSERT(assertEqual(outcome, "ftp23://www.samsung.com"));
472 TESTSUITE05(39_uriSchemeAuthority){
473 std::string * outcome = NULL;
474 std::string query("ftp++://anonymous@hostname:12/avc%23");
475 outcome = AT::uriSchemeAuthorityStatic(&query);
476 RUNNER_ASSERT(assertEqual(outcome, "ftp++://anonymous@hostname:12"));
480 TESTSUITE05(40_uriSchemeAuthority){
481 std::string * outcome = NULL;
482 std::string query("32ftp://anonymous@hostname:12/avc%23");
483 outcome = AT::uriSchemeAuthorityStatic(&query);
484 RUNNER_ASSERT(assertEqual(outcome, NULL));
488 TESTSUITE05(41_uriSchemeAuthority){
489 std::string * outcome = NULL;
490 std::string query("http://aaabbb?acd");
491 outcome = AT::uriSchemeAuthorityStatic(&query);
492 RUNNER_ASSERT(assertEqual(outcome, "http://aaabbb"));
496 TESTSUITE05(42_uriSchemeAuthority){
497 std::string * outcome = NULL;
498 std::string query("http://aaabbb/acd;sdf;sdf");
499 outcome = AT::uriSchemeAuthorityStatic(&query);
500 RUNNER_ASSERT(assertEqual(outcome, "http://aaabbb"));
504 TESTSUITE05(43_uriPath){
505 std::string * outcome = NULL;
506 std::string query("ftp://authority//invalidpath");
507 outcome = AT::uriPathStatic(&query);
508 RUNNER_ASSERT(assertEqual(outcome, NULL));
512 TESTSUITE05(44_uriPath){
513 std::string * outcome = NULL;
514 std::string query("ftp://authority/validpath");
515 outcome = AT::uriPathStatic(&query);
516 RUNNER_ASSERT(assertEqual(outcome, "validpath"));
520 TESTSUITE05(45_uriPath){
521 std::string * outcome = NULL;
522 std::string query("ftp://authority/validpath;param;param");
523 outcome = AT::uriPathStatic(&query);
524 RUNNER_ASSERT(assertEqual(outcome, "validpath;param;param"));
528 TESTSUITE05(46_uriPath){
529 std::string * outcome = NULL;
530 std::string query("ftp://authority/validpath;param;param?query");
531 outcome = AT::uriPathStatic(&query);
532 RUNNER_ASSERT(assertEqual(outcome, "validpath;param;param"));
536 TESTSUITE05(47_uriPath){
537 std::string * outcome = NULL;
538 std::string query("ftp://authority/validpath;?param;param?query");
539 outcome = AT::uriPathStatic(&query);
540 RUNNER_ASSERT(assertEqual(outcome, "validpath;"));
544 TESTSUITE05(48_uriPath){
545 std::string * outcome = NULL;
546 std::string query("ftp://authority/validpath;param?;param?query");
547 outcome = AT::uriPathStatic(&query);
548 RUNNER_ASSERT(assertEqual(outcome, "validpath;param"));
552 TESTSUITE05(49_uriPath){
553 std::string * outcome = NULL;
554 std::string query("ftp://authority/valid:path?query");
555 outcome = AT::uriPathStatic(&query);
556 RUNNER_ASSERT(assertEqual(outcome, "valid:path"));
560 TESTSUITE05(50_uriPath){
561 std::string * outcome = NULL;
562 std::string query("ftp://authority/:::");
563 outcome = AT::uriPathStatic(&query);
564 RUNNER_ASSERT(assertEqual(outcome, ":::"));
568 TESTSUITE05(51_uriPath){
569 std::string * outcome = NULL;
570 std::string query("/path1/path2?abc#fragment");
571 outcome = AT::uriPathStatic(&query);
572 RUNNER_ASSERT(assertEqual(outcome, "path1/path2"));
576 TESTSUITE05(52_uriPath){
577 std::string * outcome = NULL;
578 std::string query("http://www.samsung.com/normalpath/path2?query");
579 outcome = AT::uriPathStatic(&query);
580 RUNNER_ASSERT(assertEqual(outcome, "normalpath/path2"));
584 TESTSUITE05(53_markTest){
585 RUNNER_ASSERT(AT::markTest());
588 TESTSUITE05(54_digitTest){
589 RUNNER_ASSERT(AT::digitTest());
592 TESTSUITE05(55_alphaTest){
593 RUNNER_ASSERT(AT::alphaTest());
596 TESTSUITE05(56_escapedTest){
597 const char * query = "%23";
598 RUNNER_ASSERT(assertTrue(AT::isEscapedStatic(query)));
600 RUNNER_ASSERT(assertTrue(AT::isEscapedStatic(query)));
603 RUNNER_ASSERT(assertFalse(AT::isEscapedStatic(query)));
606 RUNNER_ASSERT(assertFalse(AT::isEscapedStatic(query)));
609 RUNNER_ASSERT(assertFalse(AT::isEscapedStatic(query)));
612 RUNNER_ASSERT(assertFalse(AT::isEscapedStatic(query)));
615 RUNNER_ASSERT(assertTrue(AT::isEscapedStatic(query)));
618 RUNNER_ASSERT(assertTrue(AT::isEscapedStatic(query)));