[Release] wrt-commons_0.2.108
[framework/web/wrt-commons.git] / tests / utils / path_tests.cpp
1 /*
2  * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 /**
17  * @file    path.h
18  * @author  Tomasz Iwanek (t.iwanek@samsung.com)
19  * @version 1.0
20  */
21
22 #include <set>
23 #include <memory>
24
25 #include <dpl/test/test_runner.h>
26 #include <dpl/scoped_dir.h>
27 #include <dpl/scoped_free.h>
28 #include <dpl/utils/path.h>
29 #include <dpl/foreach.h>
30 #include <dpl/log/log.h>
31 #include <dpl/binary_queue.h>
32 #include <dpl/file_input.h>
33 #include <dpl/file_output.h>
34
35 #include <sys/stat.h>
36 #include <unistd.h>
37
38 using namespace DPL::Utils;
39
40 namespace {
41 //do not used path here we test it
42 std::string rootTest = "/tmp/wrttest/";
43 }
44
45 #define ROOTGUARD_TESTMETHOD(FUNC)                                                         \
46 {                                                                                          \
47     bool catched = false;                                                                  \
48     Try {                                                                                  \
49         FUNC;                                                                              \
50     } Catch(Path::RootDirectoryError) {                                                    \
51         catched = true;                                                                    \
52     }                                                                                      \
53     RUNNER_ASSERT_MSG(catched, "Use of method should be protected against root diretory"); \
54 }                                                                                          \
55
56 RUNNER_TEST_GROUP_INIT(DPL_Path)
57
58 /*
59 Name: path_touch
60 Description: constructs paths in many ways
61 Expected: success full constrution
62 */
63 RUNNER_TEST(path_mkfile)
64 {
65     DPL::ScopedDir sd(rootTest);
66
67     struct stat st;
68     memset(&st, 0, sizeof(struct stat));
69     Path path = Path(rootTest) / "touch.txt";
70     RUNNER_ASSERT_MSG(lstat(path.Fullpath().c_str(), &st) != 0, "File should not be created");
71     RUNNER_ASSERT(!path.Exists());
72     MakeEmptyFile(path);
73     RUNNER_ASSERT_MSG(lstat(path.Fullpath().c_str(), &st) == 0, "File should be created");
74     RUNNER_ASSERT(path.Exists());
75     RUNNER_ASSERT(path.IsFile());
76     RUNNER_ASSERT(!path.IsDir());
77     RUNNER_ASSERT(!path.IsSymlink());
78 }
79
80 /*
81 Name: path_touch
82 Description: tries to craete file when it exists
83 Expected: failure
84 */
85 RUNNER_TEST(path_mkfile_exists)
86 {
87     DPL::ScopedDir sd(rootTest);
88
89     Path path = Path(rootTest) / "touch.txt";
90     MakeEmptyFile(path);
91     RUNNER_ASSERT(path.Exists());
92     bool cannotCreate2ndTime = false;
93     Try
94     {
95         MakeEmptyFile(path);
96     }
97     Catch(Path::AlreadyExists)
98     {
99         cannotCreate2ndTime = true;
100     }
101     RUNNER_ASSERT_MSG(cannotCreate2ndTime, "File created should not be able to be created second time");
102 }
103
104 /*
105 Name: path_mkfile_invalid_path
106 Description: tries to create file in not exisitng directory
107 Expected: failure at creation
108 */
109 RUNNER_TEST(path_mkfile_invalid_path)
110 {
111     DPL::ScopedDir sd(rootTest);
112
113     Path path = Path(rootTest) / "not_existing" / "touch.txt";
114     bool cannotCreate = false;
115     Try
116     {
117         MakeEmptyFile(path);
118     }
119     Catch(Path::OperationFailed)
120     {
121         cannotCreate = true;
122     }
123     RUNNER_ASSERT_MSG(cannotCreate, "File created should not be able to be created");
124 }
125
126 /*
127 Name: path_mkdir
128 Description: creates valid directory
129 Expected: success direcotry creation
130 */
131 RUNNER_TEST(path_mkdir)
132 {
133     DPL::ScopedDir sd(rootTest);
134
135     struct stat st;
136     memset(&st, 0, sizeof(struct stat));
137     Path path = Path(rootTest) / "touchDir";
138     RUNNER_ASSERT_MSG(lstat(path.Fullpath().c_str(), &st) != 0, "Directory should not be created");
139     RUNNER_ASSERT(!path.Exists());
140     MakeDir(path);
141     RUNNER_ASSERT_MSG(lstat(path.Fullpath().c_str(), &st) == 0, "Directory should be created");
142     RUNNER_ASSERT(path.Exists());
143     RUNNER_ASSERT(!path.IsFile());
144     RUNNER_ASSERT(path.IsDir());
145     RUNNER_ASSERT(!path.IsSymlink());
146 }
147
148 /*
149 Name: path_symlink
150 Description: chekc if symlink is correctly recognized
151 Expected: method isSymlink returns true
152 */
153 RUNNER_TEST(path_symlink)
154 {
155     DPL::ScopedDir sd(rootTest);
156
157     struct stat st;
158     memset(&st, 0, sizeof(struct stat));
159     Path path = Path(rootTest) / "symlink";
160     RUNNER_ASSERT_MSG(lstat(path.Fullpath().c_str(), &st) != 0, "Symlink should not be created");
161     RUNNER_ASSERT(!path.Exists());
162     (void)symlink("/nonexistisfile/file/file/file ", path.Fullpath().c_str());
163     RUNNER_ASSERT_MSG(lstat(path.Fullpath().c_str(), &st) == 0, "Symlink should be created");
164     RUNNER_ASSERT(path.Exists());
165     RUNNER_ASSERT(!path.IsFile());
166     RUNNER_ASSERT(!path.IsDir());
167     RUNNER_ASSERT(path.IsSymlink());
168 }
169
170 /*
171 Name: path_construction_empty
172 Description: tries to construct empty path
173 Expected: failure
174 */
175 RUNNER_TEST(path_construction_empty)
176 {
177     bool passed = false;
178     Try
179     {
180         Path path1(std::string(""));
181     }
182     Catch(Path::EmptyPath)
183     {
184         passed = true;
185     }
186     RUNNER_ASSERT_MSG(passed, "Construction with empty path do not fails");
187 }
188
189 /*
190 Name: path_construction_root
191 Description: tries to construct root path
192 Expected: success
193 */
194 RUNNER_TEST(path_construction_root)
195 {
196     Path path1(std::string("/"));
197     RUNNER_ASSERT(path1.Fullpath() == "/");
198     RUNNER_ASSERT(path1.Filename() == "");
199     bool passed = false;
200     Try
201     {
202         RUNNER_ASSERT(path1.DirectoryName() == "/");
203     }
204     Catch(Path::InternalError)
205     {
206         passed = true;
207     }
208     RUNNER_ASSERT_MSG(passed, "Directory name for root should be an error");
209 }
210
211 /*
212 Name: path_construction_1
213 Description: constructs paths in many ways
214 Expected: success full constrution
215 */
216 RUNNER_TEST(path_construction_1)
217 {
218     DPL::ScopedFree<char> sf(getcwd(NULL, 0));
219
220     Path path1(std::string("/test/bin/file"));
221     RUNNER_ASSERT(path1.Fullpath() == "/test/bin/file");
222     RUNNER_ASSERT(path1.Filename() == "file");
223     RUNNER_ASSERT(path1.DirectoryName() == "/test/bin");
224 }
225
226 /*
227 Name: path_construction_2
228 Description: constructs paths in many ways
229 Expected: success full constrution
230 */
231 RUNNER_TEST(path_construction_2)
232 {
233     DPL::ScopedFree<char> sf(getcwd(NULL, 0));
234     std::string cwd(sf.Get());
235
236     Path path2(std::string("test/bin/file.eas"));
237     RUNNER_ASSERT(path2.Fullpath() == cwd + "/test/bin/file.eas");
238     RUNNER_ASSERT(path2.Filename() == "file.eas");
239     RUNNER_ASSERT(path2.DirectoryName() == cwd + "/test/bin");
240 }
241
242 /*
243 Name: path_construction_3
244 Description: constructs paths in many ways
245 Expected: success full constrution
246 */
247 RUNNER_TEST(path_construction_3)
248 {
249     DPL::ScopedFree<char> sf(getcwd(NULL, 0));
250     std::string cwd(sf.Get());
251
252     Path path3("test/23/abc");
253     RUNNER_ASSERT(path3.Fullpath() == cwd + "/test/23/abc");
254     RUNNER_ASSERT(path3.Filename() == "abc");
255     RUNNER_ASSERT(path3.DirectoryName() == cwd + "/test/23");
256 }
257
258 /*
259 Name: path_construction_4
260 Description: constructs paths in many ways
261 Expected: success full constrution
262 */
263 RUNNER_TEST(path_construction_4)
264 {
265     DPL::ScopedFree<char> sf(getcwd(NULL, 0));
266
267     Path path4("/test/bin/abc");
268     RUNNER_ASSERT(path4.Fullpath() == "/test/bin/abc");
269     RUNNER_ASSERT(path4.Filename() == "abc");
270     RUNNER_ASSERT(path4.DirectoryName() == "/test/bin");
271 }
272
273 /*
274 Name: path_construction_5
275 Description: constructs paths in many ways
276 Expected: success full constrution
277 */
278 RUNNER_TEST(path_construction_5)
279 {
280     DPL::ScopedFree<char> sf(getcwd(NULL, 0));
281     std::string cwd(sf.Get());
282
283     Path path5(DPL::String(L"test/bin/file.st.exe"));
284     RUNNER_ASSERT(path5.Fullpath() == cwd + "/test/bin/file.st.exe");
285     RUNNER_ASSERT(path5.Filename() == "file.st.exe");
286     RUNNER_ASSERT(path5.DirectoryName() == cwd + "/test/bin");
287 }
288
289 /*
290 Name: path_construction_6
291 Description: constructs paths in many ways
292 Expected: success full constrution
293 */
294 RUNNER_TEST(path_construction_6)
295 {
296     DPL::ScopedFree<char> sf(getcwd(NULL, 0));
297
298     Path path6(DPL::String(L"/test/bin/file"));
299     RUNNER_ASSERT(path6.Fullpath() == "/test/bin/file");
300     RUNNER_ASSERT(path6.Filename() == "file");
301     RUNNER_ASSERT(path6.DirectoryName() == "/test/bin");
302 }
303
304 /*
305 Name: path_construction_7
306 Description: constructs paths in many ways
307 Expected: success full constrution
308 */
309 RUNNER_TEST(path_construction_7)
310 {
311     DPL::ScopedFree<char> sf(getcwd(NULL, 0));
312     std::string cwd(sf.Get());
313
314     Path path7 = Path("test") / "a///23/lol";
315     RUNNER_ASSERT(path7.Fullpath() == cwd + "/test/a/23/lol");
316     RUNNER_ASSERT(path7.Filename() == "lol");
317     RUNNER_ASSERT(path7.DirectoryName() == cwd + "/test/a/23");
318 }
319
320 /*
321 Name: path_construction_8
322 Description: constructs paths in many ways
323 Expected: success full constrution
324 */
325 RUNNER_TEST(path_construction_8)
326 {
327     DPL::ScopedFree<char> sf(getcwd(NULL, 0));
328
329     Path path8 = Path("/test/bin/") / "123" / "dir1.dll";
330     RUNNER_ASSERT(path8.Fullpath() == "/test/bin/123/dir1.dll");
331     RUNNER_ASSERT(path8.Filename() == "dir1.dll");
332     RUNNER_ASSERT(path8.DirectoryName() ==  "/test/bin/123");
333 }
334
335 /*
336 Name: path_construction_9
337 Description: constructs paths in many ways
338 Expected: success full constrution
339 */
340 RUNNER_TEST(path_construction_9)
341 {
342     DPL::ScopedFree<char> sf(getcwd(NULL, 0));
343
344     Path path9 = Path("/test/bin/file.txt//");
345     RUNNER_ASSERT(path9.Fullpath() == "/test/bin/file.txt");
346     RUNNER_ASSERT(path9.Filename() == "file.txt");
347     RUNNER_ASSERT(path9.DirectoryName() ==  "/test/bin");
348 }
349
350 /*
351 Name: path_construction_10
352 Description: constructs paths by appending
353 Expected: success full constrution
354 */
355 RUNNER_TEST(path_construction_10)
356 {
357     Path path10 = Path("/test/");
358     path10 /= "one";
359     path10 /= std::string("two");
360     path10 /= DPL::String(L"three");
361     RUNNER_ASSERT(path10.Fullpath() == "/test/one/two/three");
362     RUNNER_ASSERT(path10.Filename() == "three");
363     RUNNER_ASSERT(path10.DirectoryName() ==  "/test/one/two");
364 }
365
366 /*
367 Name: path_remove
368 Description: tests removing paths
369 Expected: successfull path remove
370 */
371 RUNNER_TEST(path_remove_valid)
372 {
373     DPL::ScopedDir sd(rootTest);
374
375     struct stat st;
376     memset(&st, 0, sizeof(struct stat));
377     Path path = Path(rootTest) / "touchDir";
378     RUNNER_ASSERT(!path.Exists());
379
380     MakeDir(path);
381     RUNNER_ASSERT_MSG(lstat(path.Fullpath().c_str(), &st) == 0, "Directory should be created");
382     RUNNER_ASSERT(path.Exists());
383
384     Remove(path);
385     RUNNER_ASSERT_MSG(lstat(path.Fullpath().c_str(), &st) != 0, "Directory should not be created");
386     RUNNER_ASSERT(!path.Exists());
387
388     MakeEmptyFile(path);
389     RUNNER_ASSERT_MSG(lstat(path.Fullpath().c_str(), &st) == 0, "File should be created");
390     RUNNER_ASSERT(path.Exists());
391
392     Remove(path);
393     RUNNER_ASSERT_MSG(lstat(path.Fullpath().c_str(), &st) != 0, "File should not be created");
394     RUNNER_ASSERT(!path.Exists());
395 }
396
397 /*
398 Name: path_try_remove
399 Description: tests removing paths
400 Expected: successfull path remove once
401 */
402 RUNNER_TEST(path_try_remove_valid)
403 {
404     DPL::ScopedDir sd(rootTest);
405
406     struct stat st;
407     memset(&st, 0, sizeof(struct stat));
408     Path path = Path(rootTest) / "touchDir";
409     RUNNER_ASSERT(!path.Exists());
410
411     MakeDir(path);
412     RUNNER_ASSERT_MSG(lstat(path.Fullpath().c_str(), &st) == 0, "Directory should be created");
413     RUNNER_ASSERT(path.Exists());
414
415     RUNNER_ASSERT(TryRemove(path));
416     RUNNER_ASSERT(!TryRemove(path));
417     RUNNER_ASSERT_MSG(lstat(path.Fullpath().c_str(), &st) != 0, "Directory should not be created");
418     RUNNER_ASSERT(!path.Exists());
419
420     MakeEmptyFile(path);
421     RUNNER_ASSERT_MSG(lstat(path.Fullpath().c_str(), &st) == 0, "File should be created");
422     RUNNER_ASSERT(path.Exists());
423
424     RUNNER_ASSERT(TryRemove(path));
425     RUNNER_ASSERT(!TryRemove(path));
426     RUNNER_ASSERT_MSG(lstat(path.Fullpath().c_str(), &st) != 0, "File should not be created");
427     RUNNER_ASSERT(!path.Exists());
428 }
429
430 /*
431 Name: path_remove_invalid
432 Description: tests removing invalid paths
433 Expected: failure at path remove
434 */
435 RUNNER_TEST(path_remove_invalid)
436 {
437     DPL::ScopedDir sd(rootTest);
438
439     Path path = Path(rootTest) / "touchDir";
440
441     bool removedNotExisting = true;
442     Try
443     {
444         Remove(path);
445     }
446     Catch(Path::OperationFailed)
447     {
448         removedNotExisting = false;
449     }
450     RUNNER_ASSERT_MSG(!removedNotExisting, "Removing not existing file");
451 }
452
453 /*
454 Name: path_rename
455 Description: tests path renaming
456 Expected: path is successfully renamed
457 */
458 RUNNER_TEST(path_rename)
459 {
460     DPL::ScopedDir sd(rootTest);
461
462     struct stat st;
463     memset(&st, 0, sizeof(struct stat));
464     Path path = Path(rootTest) / "touchDir";
465     Path dirpath = Path(rootTest) / "directory";
466     Path path2 = dirpath / "touchDir2";
467
468     MakeDir(dirpath);
469
470     MakeEmptyFile(path);
471     RUNNER_ASSERT_MSG(lstat(path.Fullpath().c_str(), &st) == 0, "File should be created");
472     RUNNER_ASSERT(path.Exists());
473     RUNNER_ASSERT(!path2.Exists());
474
475     Rename(path, path2);
476     RUNNER_ASSERT(!path.Exists());
477     RUNNER_ASSERT(path2.Exists());
478
479     Rename(path2, path);
480     RUNNER_ASSERT(path.Exists());
481     RUNNER_ASSERT(!path2.Exists());
482 }
483
484 /*
485 Name: path_rename_xdev
486 Description: tests path renaming between devices
487 Expected: path is successfully renamed
488 */
489 RUNNER_TEST(path_rename_xdev)
490 {
491     //assuming /opt/usr and /usr is normally on other partitions on device
492     //TODO: better
493     Path path = Path("/opt/usr") / "touchDir";
494     Path dirpath = path / "directory";
495     Path filepath = path / "file.txt";
496
497     Path path2 = Path("/usr") / "touchDir2";
498     Path dirpath2 = path2 / "directory";
499     Path filepath2 = path2 / "file.txt";
500
501     TryRemove(path);
502
503     MakeDir(path);
504     MakeDir(dirpath);
505     MakeEmptyFile(filepath);
506
507     RUNNER_ASSERT(path.Exists());
508     RUNNER_ASSERT(dirpath.Exists());
509     RUNNER_ASSERT(filepath.Exists());
510     RUNNER_ASSERT(!path2.Exists());
511     RUNNER_ASSERT(!dirpath2.Exists());
512     RUNNER_ASSERT(!filepath2.Exists());
513
514     Rename(path, path2);
515     RUNNER_ASSERT(!path.Exists());
516     RUNNER_ASSERT(!dirpath.Exists());
517     RUNNER_ASSERT(!filepath.Exists());
518     RUNNER_ASSERT(path2.Exists());
519     RUNNER_ASSERT(dirpath2.Exists());
520     RUNNER_ASSERT(filepath2.Exists());
521
522     Rename(path2, path);
523     RUNNER_ASSERT(path.Exists());
524     RUNNER_ASSERT(dirpath.Exists());
525     RUNNER_ASSERT(filepath.Exists());
526     RUNNER_ASSERT(!path2.Exists());
527     RUNNER_ASSERT(!dirpath2.Exists());
528     RUNNER_ASSERT(!filepath2.Exists());
529
530     Remove(path);
531 }
532
533 /**
534  * Name: path_basename
535  * Description: check basename equivalents
536  * Expected: failure
537  */
538 RUNNER_TEST(path_basename)
539 {
540     DPL::ScopedDir sd(rootTest);
541     Path path = Path(rootTest) / "directory" / "touch.txt";
542     RUNNER_ASSERT(path.DirectoryName() == path.DirectoryPath().Fullpath());
543     RUNNER_ASSERT(path.DirectoryPath().DirectoryName() == path.DirectoryPath().DirectoryPath().Fullpath());
544 }
545
546 /**
547  * Name: path_safe
548  * Description: check if operations cannot be executed on root directory
549  *
550  * This is check because of default path is root and it should not be used usually
551  * Default constructor is unfortnatelly easier to use
552  *
553  * Expected: failure
554  */
555 RUNNER_TEST(path_safe)
556 {
557     DPL::ScopedDir sd(rootTest);
558     Path normal = Path(rootTest) / "directory" / "touch.txt";
559     Path root("/");
560     ROOTGUARD_TESTMETHOD( Rename(normal, root) );
561     ROOTGUARD_TESTMETHOD( Rename(root, root) );
562     ROOTGUARD_TESTMETHOD( Rename(root, normal) );
563     ROOTGUARD_TESTMETHOD( CopyDir(normal, root) );
564     ROOTGUARD_TESTMETHOD( CopyDir(root, root) );
565     ROOTGUARD_TESTMETHOD( CopyDir(root, normal) );
566     ROOTGUARD_TESTMETHOD( CopyFile(normal, root) );
567     ROOTGUARD_TESTMETHOD( CopyFile(root, root) );
568     ROOTGUARD_TESTMETHOD( CopyFile(root, normal) );
569     ROOTGUARD_TESTMETHOD( Remove(root) );
570     ROOTGUARD_TESTMETHOD( MakeEmptyFile(root) );
571     ROOTGUARD_TESTMETHOD( MakeDir(root) );
572 }
573
574 /**
575  * Name: path_size
576  * Description: check testing size of file
577  * Expected: correct size
578  */
579 RUNNER_TEST(path_size)
580 {
581     DPL::ScopedDir sd(rootTest);
582     Path path = Path(rootTest) / "touch.txt";
583     DPL::Utils::MakeEmptyFile(path);
584     RUNNER_ASSERT(path.Size() == 0);
585
586     {
587         DPL::FileOutput out(path.Fullpath());
588         DPL::BinaryQueue bq;
589         bq.AppendCopy("123456789", 9);
590         out.Write(bq, bq.Size());
591         out.Close();
592         RUNNER_ASSERT(path.Size() == 9);
593     }
594
595     {
596         DPL::FileOutput out(path.Fullpath());
597         DPL::BinaryQueue bq;
598         bq.AppendCopy("123456789", 4);
599         out.Write(bq, bq.Size());
600         out.Close();
601         RUNNER_ASSERT(path.Size() == 4);
602     }
603 }
604
605 /**
606 Name: path_copy
607 Description: tests path coping directory andfiles
608 Expected: coping should be done
609 */
610 RUNNER_TEST(path_copy_directory)
611 {
612     DPL::ScopedDir sd(rootTest);
613
614     Path path = Path(rootTest) / "sourceDir";
615     Path innerPath = Path(rootTest) / "sourceDir" / "level1" ;
616     Path innerPath2 = Path(rootTest) / "sourceDir" / "level1" / "level2";
617     Path file1 = Path(rootTest) / "sourceDir" / "level1" / "level2" / "file1.txt";
618     Path file2 = Path(rootTest) / "sourceDir" / "level1" / "level2" / "file2.txt";
619     Path file3 = Path(rootTest) / "sourceDir" / "level1" / "file3.txt";
620     Path file4 = Path(rootTest) / "sourceDir" /  "file4.txt";
621
622     Path tfile1 = Path(rootTest) / "targetDir" / "level1" / "level2" / "file1.txt";
623     Path tfile2 = Path(rootTest) / "targetDir" / "level1" / "level2" / "file2.txt";
624     Path tfile3 = Path(rootTest) / "targetDir" / "level1" / "file3.txt";
625     Path tfile4 = Path(rootTest) / "targetDir" /  "file4.txt";
626
627     Path target = Path(rootTest) / "targetDir";
628
629     DPL::Utils::MakeDir(path);
630     DPL::Utils::MakeDir(innerPath);
631     DPL::Utils::MakeDir(innerPath2);
632     DPL::Utils::MakeEmptyFile(file1);
633     DPL::Utils::MakeEmptyFile(file2);
634     DPL::Utils::MakeEmptyFile(file3);
635     DPL::Utils::MakeEmptyFile(file4);
636
637     DPL::Utils::CopyDir(path, target);
638
639     RUNNER_ASSERT_MSG(tfile1.Exists(), tfile1.Fullpath() + " not exists");
640     RUNNER_ASSERT_MSG(tfile1.IsFile(), tfile1.Fullpath() + " is not file");
641     RUNNER_ASSERT_MSG(tfile2.Exists(), tfile2.Fullpath() + " not exists");
642     RUNNER_ASSERT_MSG(tfile2.IsFile(), tfile2.Fullpath() + " is not file");
643     RUNNER_ASSERT_MSG(tfile3.Exists(), tfile3.Fullpath() + " not exists");
644     RUNNER_ASSERT_MSG(tfile3.IsFile(), tfile3.Fullpath() + " is not file");
645     RUNNER_ASSERT_MSG(tfile4.Exists(), tfile4.Fullpath() + " not exists");
646     RUNNER_ASSERT_MSG(tfile4.IsFile(), tfile4.Fullpath() + " is not file");
647 }
648
649 /*
650 Name: path_copy_inner
651 Description: tests path coping to subdirectory
652 Expected: coping shoudl fail
653 */
654 RUNNER_TEST(path_copy_inner)
655 {
656     DPL::ScopedDir sd(rootTest);
657
658     Path path = Path(rootTest) / "touchDir";
659     Path inner = Path(rootTest) / "touchDir" / "innerDirectory";
660
661     bool exceptionCatched = false;
662     Try
663     {
664         DPL::Utils::CopyDir(path, inner);
665     }
666     Catch(DPL::Utils::Path::CannotCopy)
667     {
668         exceptionCatched = true;
669     }
670     RUNNER_ASSERT_MSG(exceptionCatched, "Copy should fail");
671 }
672
673 /*
674 Name: issubpath
675 Description: tests method compare if one path is subpath of another
676 Expected: correct results
677 */
678 RUNNER_TEST(path_issubpath)
679 {
680     Path path1 = Path(rootTest) / "touchDir/asd/sdf";
681     Path path2 = Path(rootTest) / "touchDir/asd/sdf/123";
682     Path path3 = Path(rootTest) / "touchDir/asd/sdno";
683     Path path4 = Path("/");
684
685     RUNNER_ASSERT(path1.isSubPath(path2));
686     RUNNER_ASSERT(!path1.isSubPath(path3));
687     RUNNER_ASSERT(!path1.isSubPath(path4));
688
689     RUNNER_ASSERT(!path2.isSubPath(path1));
690     RUNNER_ASSERT(!path2.isSubPath(path3));
691     RUNNER_ASSERT(!path2.isSubPath(path4));
692
693     RUNNER_ASSERT(path4.isSubPath(path1));
694     RUNNER_ASSERT(path4.isSubPath(path2));
695     RUNNER_ASSERT(path4.isSubPath(path3));
696 }
697
698 /*
699 Name: path_rename_same
700 Description: tests if renam does not brokens file if target location is equal to source location
701 Expected: path is avaliable
702 */
703 RUNNER_TEST(path_rename_same)
704 {
705     DPL::ScopedDir sd(rootTest);
706
707     struct stat st;
708     memset(&st, 0, sizeof(struct stat));
709     Path path = Path(rootTest) / "touchDir";
710
711     MakeDir(path);
712     Rename(path, path);
713     RUNNER_ASSERT(path.Exists());
714 }
715
716 /*
717 Name: path_iterate_not_directory
718 Description: iterates not a directory
719 Expected: success full constrution
720 */
721 RUNNER_TEST(path_iterate_not_directory)
722 {
723     DPL::ScopedDir sd(rootTest);
724
725     Path fileTest = Path(rootTest) / "file.txt";
726     MakeEmptyFile(fileTest);
727
728     bool passed = false;
729     Try
730     {
731         FOREACH(file, fileTest)
732         {
733
734         }
735     }
736     Catch(Path::NotDirectory)
737     {
738         passed = true;
739     }
740     RUNNER_ASSERT(passed);
741 }
742
743 /*
744 Name: path_construction
745 Description: constructs paths in many ways
746 Expected: success full constrution
747 */
748 RUNNER_TEST(path_iterate_empty_directory)
749 {
750     DPL::ScopedDir sd(rootTest);
751
752     Path dirTest = Path(rootTest) / "directory";
753     MakeDir(dirTest);
754
755     bool passed = true;
756     Try
757     {
758         FOREACH(file, dirTest)
759         {
760             passed = false;
761             LogError("Directory should be empty");
762         }
763     }
764     Catch(Path::NotDirectory)
765     {
766         passed = false;
767         LogError("Directory should exists");
768     }
769     RUNNER_ASSERT(passed);
770 }
771
772 /*
773 Name: path_construction
774 Description: constructs paths in many ways
775 Expected: success full constrution
776 */
777 RUNNER_TEST(path_iterate_notempty_directory)
778 {
779     DPL::ScopedDir sd(rootTest);
780
781     Path dirTest = Path(rootTest) / "directory";
782
783     Path path1 = Path(rootTest) / "directory" / "file1";
784     Path path2 = Path(rootTest) / "directory" / "file2";
785     Path path3 = Path(rootTest) / "directory" / "file3";
786
787     std::set<std::string> resultSet;
788     std::set<std::string> testSet;
789     testSet.insert(path1.Fullpath());
790     testSet.insert(path2.Fullpath());
791     testSet.insert(path3.Fullpath());
792
793     MakeDir(dirTest);
794     MakeEmptyFile(path1);
795     MakeEmptyFile(path2);
796     MakeEmptyFile(path3);
797
798     FOREACH(file, dirTest)
799     {
800         resultSet.insert(file->Fullpath());
801     }
802
803     RUNNER_ASSERT_MSG(testSet == resultSet, "Testing");
804 }
805
806 /*
807 Name: path_construction
808 Description: constructs paths in many ways
809 Expected: success full constrution
810 */
811 RUNNER_TEST(path_iterator_copy_constructor)
812 {
813     DPL::ScopedDir sd(rootTest);
814
815     Path dirTest = Path(rootTest) / "directory";
816
817     Path path1 = Path(rootTest) / "directory" / "file1";
818     Path path2 = Path(rootTest) / "directory" / "file2";
819     Path path3 = Path(rootTest) / "directory" / "file3";
820
821     MakeDir(dirTest);
822     MakeEmptyFile(path1);
823     MakeEmptyFile(path2);
824     MakeEmptyFile(path3);
825
826     std::shared_ptr<Path::Iterator> iter1(new Path::Iterator((Path(rootTest) / "directory").Fullpath().c_str()));
827
828     //as it's input iterator it's guaranteed for one element to be iterate only once
829     (*iter1)++;
830     std::shared_ptr<Path::Iterator> iter2(new Path::Iterator( (*iter1)));
831     iter1.reset();
832     (*iter2)++;
833     ++(*iter2);
834     RUNNER_ASSERT_MSG(*iter2 == dirTest.end(), "Iterator is in broken state");
835     iter2.reset();
836 }