2 * Copyright (c) 2013 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.
18 * @author Tomasz Iwanek (t.iwanek@samsung.com)
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>
38 using namespace DPL::Utils;
41 //do not used path here we test it
42 std::string rootTest = "/tmp/wrttest/";
45 #define ROOTGUARD_TESTMETHOD(FUNC) \
47 bool catched = false; \
50 } Catch(Path::RootDirectoryError) { \
53 RUNNER_ASSERT_MSG(catched, "Use of method should be protected against root diretory"); \
56 RUNNER_TEST_GROUP_INIT(DPL_Path)
60 Description: constructs paths in many ways
61 Expected: success full constrution
63 RUNNER_TEST(path_mkfile)
65 DPL::ScopedDir sd(rootTest);
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());
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());
82 Description: tries to craete file when it exists
85 RUNNER_TEST(path_mkfile_exists)
87 DPL::ScopedDir sd(rootTest);
89 Path path = Path(rootTest) / "touch.txt";
91 RUNNER_ASSERT(path.Exists());
92 bool cannotCreate2ndTime = false;
97 Catch(Path::AlreadyExists)
99 cannotCreate2ndTime = true;
101 RUNNER_ASSERT_MSG(cannotCreate2ndTime, "File created should not be able to be created second time");
105 Name: path_exists_and_is_file_or_dir
106 Description: test for checking for existence of directory or file
109 RUNNER_TEST(path_exists_and_is_file_or_dir)
111 DPL::ScopedDir sd(rootTest);
113 Path file = Path(rootTest) / "testfile.txt";
115 RUNNER_ASSERT_MSG(file.ExistsAndIsFile(), "File should exist");
116 RUNNER_ASSERT_MSG(!file.ExistsAndIsDir(), "It should not be a directory");
118 Path dir = Path(rootTest) / "testdir";
120 RUNNER_ASSERT_MSG(dir.ExistsAndIsDir(), "Directory should exist");
121 RUNNER_ASSERT_MSG(!dir.ExistsAndIsFile(), "Is should not be a file");
125 Name: path_mkfile_invalid_path
126 Description: tries to create file in not exisitng directory
127 Expected: failure at creation
129 RUNNER_TEST(path_mkfile_invalid_path)
131 DPL::ScopedDir sd(rootTest);
133 Path path = Path(rootTest) / "not_existing" / "touch.txt";
134 bool cannotCreate = false;
139 Catch(Path::OperationFailed)
143 RUNNER_ASSERT_MSG(cannotCreate, "File created should not be able to be created");
148 Description: creates valid directory
149 Expected: success direcotry creation
151 RUNNER_TEST(path_mkdir)
153 DPL::ScopedDir sd(rootTest);
156 memset(&st, 0, sizeof(struct stat));
157 Path path = Path(rootTest) / "touchDir";
158 RUNNER_ASSERT_MSG(lstat(path.Fullpath().c_str(), &st) != 0, "Directory should not be created");
159 RUNNER_ASSERT(!path.Exists());
161 RUNNER_ASSERT_MSG(lstat(path.Fullpath().c_str(), &st) == 0, "Directory should be created");
162 RUNNER_ASSERT(path.Exists());
163 RUNNER_ASSERT(!path.IsFile());
164 RUNNER_ASSERT(path.IsDir());
165 RUNNER_ASSERT(!path.IsSymlink());
170 Description: chekc if symlink is correctly recognized
171 Expected: method isSymlink returns true
173 RUNNER_TEST(path_symlink)
175 DPL::ScopedDir sd(rootTest);
178 memset(&st, 0, sizeof(struct stat));
179 Path path = Path(rootTest) / "symlink";
180 RUNNER_ASSERT_MSG(lstat(path.Fullpath().c_str(), &st) != 0, "Symlink should not be created");
181 RUNNER_ASSERT(!path.Exists());
182 (void)symlink("/nonexistisfile/file/file/file ", path.Fullpath().c_str());
183 RUNNER_ASSERT_MSG(lstat(path.Fullpath().c_str(), &st) == 0, "Symlink should be created");
184 RUNNER_ASSERT(path.Exists());
185 RUNNER_ASSERT(!path.IsFile());
186 RUNNER_ASSERT(!path.IsDir());
187 RUNNER_ASSERT(path.IsSymlink());
191 Name: path_construction_empty
192 Description: tries to construct empty path
195 RUNNER_TEST(path_construction_empty)
200 Path path1(std::string(""));
202 Catch(Path::EmptyPath)
206 RUNNER_ASSERT_MSG(passed, "Construction with empty path do not fails");
210 Name: path_construction_root
211 Description: tries to construct root path
214 RUNNER_TEST(path_construction_root)
216 Path path1(std::string("/"));
217 RUNNER_ASSERT(path1.Fullpath() == "/");
218 RUNNER_ASSERT(path1.Filename() == "");
222 RUNNER_ASSERT(path1.DirectoryName() == "/");
224 Catch(Path::InternalError)
228 RUNNER_ASSERT_MSG(passed, "Directory name for root should be an error");
232 Name: path_construction_1
233 Description: constructs paths in many ways
234 Expected: success full constrution
236 RUNNER_TEST(path_construction_1)
238 DPL::ScopedFree<char> sf(getcwd(NULL, 0));
240 Path path1(std::string("/test/bin/file"));
241 RUNNER_ASSERT(path1.Fullpath() == "/test/bin/file");
242 RUNNER_ASSERT(path1.Filename() == "file");
243 RUNNER_ASSERT(path1.DirectoryName() == "/test/bin");
247 Name: path_construction_2
248 Description: constructs paths in many ways
249 Expected: success full constrution
251 RUNNER_TEST(path_construction_2)
253 DPL::ScopedFree<char> sf(getcwd(NULL, 0));
254 std::string cwd(sf.Get());
259 Path path2(std::string("test/bin/file.eas"));
260 RUNNER_ASSERT(path2.Fullpath() == cwd + "/test/bin/file.eas");
261 RUNNER_ASSERT(path2.Filename() == "file.eas");
262 RUNNER_ASSERT(path2.DirectoryName() == cwd + "/test/bin");
266 Name: path_construction_3
267 Description: constructs paths in many ways
268 Expected: success full constrution
270 RUNNER_TEST(path_construction_3)
272 DPL::ScopedFree<char> sf(getcwd(NULL, 0));
273 std::string cwd(sf.Get());
278 Path path3("test/23/abc");
279 RUNNER_ASSERT(path3.Fullpath() == cwd + "/test/23/abc");
280 RUNNER_ASSERT(path3.Filename() == "abc");
281 RUNNER_ASSERT(path3.DirectoryName() == cwd + "/test/23");
285 Name: path_construction_4
286 Description: constructs paths in many ways
287 Expected: success full constrution
289 RUNNER_TEST(path_construction_4)
291 DPL::ScopedFree<char> sf(getcwd(NULL, 0));
293 Path path4("/test/bin/abc");
294 RUNNER_ASSERT(path4.Fullpath() == "/test/bin/abc");
295 RUNNER_ASSERT(path4.Filename() == "abc");
296 RUNNER_ASSERT(path4.DirectoryName() == "/test/bin");
300 Name: path_construction_5
301 Description: constructs paths in many ways
302 Expected: success full constrution
304 RUNNER_TEST(path_construction_5)
306 DPL::ScopedFree<char> sf(getcwd(NULL, 0));
307 std::string cwd(sf.Get());
312 Path path5(DPL::String(L"test/bin/file.st.exe"));
313 RUNNER_ASSERT(path5.Fullpath() == cwd + "/test/bin/file.st.exe");
314 RUNNER_ASSERT(path5.Filename() == "file.st.exe");
315 RUNNER_ASSERT(path5.DirectoryName() == cwd + "/test/bin");
319 Name: path_construction_6
320 Description: constructs paths in many ways
321 Expected: success full constrution
323 RUNNER_TEST(path_construction_6)
325 DPL::ScopedFree<char> sf(getcwd(NULL, 0));
327 Path path6(DPL::String(L"/test/bin/file"));
328 RUNNER_ASSERT(path6.Fullpath() == "/test/bin/file");
329 RUNNER_ASSERT(path6.Filename() == "file");
330 RUNNER_ASSERT(path6.DirectoryName() == "/test/bin");
334 Name: path_construction_7
335 Description: constructs paths in many ways
336 Expected: success full constrution
338 RUNNER_TEST(path_construction_7)
340 DPL::ScopedFree<char> sf(getcwd(NULL, 0));
341 std::string cwd(sf.Get());
346 Path path7 = Path("test") / "a///23/lol";
347 RUNNER_ASSERT(path7.Fullpath() == cwd + "/test/a/23/lol");
348 RUNNER_ASSERT(path7.Filename() == "lol");
349 RUNNER_ASSERT(path7.DirectoryName() == cwd + "/test/a/23");
353 Name: path_construction_8
354 Description: constructs paths in many ways
355 Expected: success full constrution
357 RUNNER_TEST(path_construction_8)
359 DPL::ScopedFree<char> sf(getcwd(NULL, 0));
361 Path path8 = Path("/test/bin/") / "123" / "dir1.dll";
362 RUNNER_ASSERT(path8.Fullpath() == "/test/bin/123/dir1.dll");
363 RUNNER_ASSERT(path8.Filename() == "dir1.dll");
364 RUNNER_ASSERT(path8.DirectoryName() == "/test/bin/123");
368 Name: path_construction_9
369 Description: constructs paths in many ways
370 Expected: success full constrution
372 RUNNER_TEST(path_construction_9)
374 DPL::ScopedFree<char> sf(getcwd(NULL, 0));
376 Path path9 = Path("/test/bin/file.txt//");
377 RUNNER_ASSERT(path9.Fullpath() == "/test/bin/file.txt");
378 RUNNER_ASSERT(path9.Filename() == "file.txt");
379 RUNNER_ASSERT(path9.DirectoryName() == "/test/bin");
383 Name: path_construction_10
384 Description: constructs paths by appending
385 Expected: success full constrution
387 RUNNER_TEST(path_construction_10)
389 Path path10 = Path("/test/");
391 path10 /= std::string("two");
392 path10 /= DPL::String(L"three");
393 RUNNER_ASSERT(path10.Fullpath() == "/test/one/two/three");
394 RUNNER_ASSERT(path10.Filename() == "three");
395 RUNNER_ASSERT(path10.DirectoryName() == "/test/one/two");
400 Description: tests removing paths
401 Expected: successfull path remove
403 RUNNER_TEST(path_remove_valid)
405 DPL::ScopedDir sd(rootTest);
408 memset(&st, 0, sizeof(struct stat));
409 Path path = Path(rootTest) / "touchDir";
410 RUNNER_ASSERT(!path.Exists());
413 RUNNER_ASSERT_MSG(lstat(path.Fullpath().c_str(), &st) == 0, "Directory should be created");
414 RUNNER_ASSERT(path.Exists());
417 RUNNER_ASSERT_MSG(lstat(path.Fullpath().c_str(), &st) != 0, "Directory should not be created");
418 RUNNER_ASSERT(!path.Exists());
421 RUNNER_ASSERT_MSG(lstat(path.Fullpath().c_str(), &st) == 0, "File should be created");
422 RUNNER_ASSERT(path.Exists());
425 RUNNER_ASSERT_MSG(lstat(path.Fullpath().c_str(), &st) != 0, "File should not be created");
426 RUNNER_ASSERT(!path.Exists());
430 Name: path_try_remove
431 Description: tests removing paths
432 Expected: successfull path remove once
434 RUNNER_TEST(path_try_remove_valid)
436 DPL::ScopedDir sd(rootTest);
439 memset(&st, 0, sizeof(struct stat));
440 Path path = Path(rootTest) / "touchDir";
441 RUNNER_ASSERT(!path.Exists());
444 RUNNER_ASSERT_MSG(lstat(path.Fullpath().c_str(), &st) == 0, "Directory should be created");
445 RUNNER_ASSERT(path.Exists());
447 RUNNER_ASSERT(TryRemove(path));
448 RUNNER_ASSERT(!TryRemove(path));
449 RUNNER_ASSERT_MSG(lstat(path.Fullpath().c_str(), &st) != 0, "Directory should not be created");
450 RUNNER_ASSERT(!path.Exists());
453 RUNNER_ASSERT_MSG(lstat(path.Fullpath().c_str(), &st) == 0, "File should be created");
454 RUNNER_ASSERT(path.Exists());
456 RUNNER_ASSERT(TryRemove(path));
457 RUNNER_ASSERT(!TryRemove(path));
458 RUNNER_ASSERT_MSG(lstat(path.Fullpath().c_str(), &st) != 0, "File should not be created");
459 RUNNER_ASSERT(!path.Exists());
463 Name: path_remove_invalid
464 Description: tests removing invalid paths
465 Expected: failure at path remove
467 RUNNER_TEST(path_remove_invalid)
469 DPL::ScopedDir sd(rootTest);
471 Path path = Path(rootTest) / "touchDir";
473 bool removedNotExisting = true;
478 Catch(Path::OperationFailed)
480 removedNotExisting = false;
482 RUNNER_ASSERT_MSG(!removedNotExisting, "Removing not existing file");
487 Description: tests path renaming
488 Expected: path is successfully renamed
490 RUNNER_TEST(path_rename)
492 DPL::ScopedDir sd(rootTest);
495 memset(&st, 0, sizeof(struct stat));
496 Path path = Path(rootTest) / "touchDir";
497 Path dirpath = Path(rootTest) / "directory";
498 Path path2 = dirpath / "touchDir2";
503 RUNNER_ASSERT_MSG(lstat(path.Fullpath().c_str(), &st) == 0, "File should be created");
504 RUNNER_ASSERT(path.Exists());
505 RUNNER_ASSERT(!path2.Exists());
508 RUNNER_ASSERT(!path.Exists());
509 RUNNER_ASSERT(path2.Exists());
512 RUNNER_ASSERT(path.Exists());
513 RUNNER_ASSERT(!path2.Exists());
517 Name: path_rename_xdev
518 Description: tests path renaming between devices
519 Expected: path is successfully renamed
521 RUNNER_TEST(path_rename_xdev)
523 //assuming /opt/usr and /usr is normally on other partitions on device
525 Path path = Path("/opt/usr") / "touchDir";
526 Path dirpath = path / "directory";
527 Path filepath = path / "file.txt";
529 Path path2 = Path("/usr") / "touchDir2";
530 Path dirpath2 = path2 / "directory";
531 Path filepath2 = path2 / "file.txt";
537 MakeEmptyFile(filepath);
539 RUNNER_ASSERT(path.Exists());
540 RUNNER_ASSERT(dirpath.Exists());
541 RUNNER_ASSERT(filepath.Exists());
542 RUNNER_ASSERT(!path2.Exists());
543 RUNNER_ASSERT(!dirpath2.Exists());
544 RUNNER_ASSERT(!filepath2.Exists());
547 RUNNER_ASSERT(!path.Exists());
548 RUNNER_ASSERT(!dirpath.Exists());
549 RUNNER_ASSERT(!filepath.Exists());
550 RUNNER_ASSERT(path2.Exists());
551 RUNNER_ASSERT(dirpath2.Exists());
552 RUNNER_ASSERT(filepath2.Exists());
555 RUNNER_ASSERT(path.Exists());
556 RUNNER_ASSERT(dirpath.Exists());
557 RUNNER_ASSERT(filepath.Exists());
558 RUNNER_ASSERT(!path2.Exists());
559 RUNNER_ASSERT(!dirpath2.Exists());
560 RUNNER_ASSERT(!filepath2.Exists());
566 * Name: path_basename
567 * Description: check basename equivalents
570 RUNNER_TEST(path_basename)
572 DPL::ScopedDir sd(rootTest);
573 Path path = Path(rootTest) / "directory" / "touch.txt";
574 RUNNER_ASSERT(path.DirectoryName() == path.DirectoryPath().Fullpath());
575 RUNNER_ASSERT(path.DirectoryPath().DirectoryName() == path.DirectoryPath().DirectoryPath().Fullpath());
580 * Description: check if operations cannot be executed on root directory
582 * This is check because of default path is root and it should not be used usually
583 * Default constructor is unfortnatelly easier to use
587 RUNNER_TEST(path_safe)
589 DPL::ScopedDir sd(rootTest);
590 Path normal = Path(rootTest) / "directory" / "touch.txt";
592 ROOTGUARD_TESTMETHOD( Rename(normal, root) );
593 ROOTGUARD_TESTMETHOD( Rename(root, root) );
594 ROOTGUARD_TESTMETHOD( Rename(root, normal) );
595 ROOTGUARD_TESTMETHOD( CopyDir(normal, root) );
596 ROOTGUARD_TESTMETHOD( CopyDir(root, root) );
597 ROOTGUARD_TESTMETHOD( CopyDir(root, normal) );
598 ROOTGUARD_TESTMETHOD( CopyFile(normal, root) );
599 ROOTGUARD_TESTMETHOD( CopyFile(root, root) );
600 ROOTGUARD_TESTMETHOD( CopyFile(root, normal) );
601 ROOTGUARD_TESTMETHOD( Remove(root) );
602 ROOTGUARD_TESTMETHOD( MakeEmptyFile(root) );
603 ROOTGUARD_TESTMETHOD( MakeDir(root) );
608 * Description: check testing size of file
609 * Expected: correct size
611 RUNNER_TEST(path_size)
613 DPL::ScopedDir sd(rootTest);
614 Path path = Path(rootTest) / "touch.txt";
615 DPL::Utils::MakeEmptyFile(path);
616 RUNNER_ASSERT(path.Size() == 0);
619 DPL::FileOutput out(path.Fullpath());
621 bq.AppendCopy("123456789", 9);
622 out.Write(bq, bq.Size());
624 RUNNER_ASSERT(path.Size() == 9);
628 DPL::FileOutput out(path.Fullpath());
630 bq.AppendCopy("123456789", 4);
631 out.Write(bq, bq.Size());
633 RUNNER_ASSERT(path.Size() == 4);
639 Description: tests path coping directory andfiles
640 Expected: coping should be done
642 RUNNER_TEST(path_copy_directory)
644 DPL::ScopedDir sd(rootTest);
646 Path path = Path(rootTest) / "sourceDir";
647 Path innerPath = Path(rootTest) / "sourceDir" / "level1" ;
648 Path innerPath2 = Path(rootTest) / "sourceDir" / "level1" / "level2";
649 Path file1 = Path(rootTest) / "sourceDir" / "level1" / "level2" / "file1.txt";
650 Path file2 = Path(rootTest) / "sourceDir" / "level1" / "level2" / "file2.txt";
651 Path file3 = Path(rootTest) / "sourceDir" / "level1" / "file3.txt";
652 Path file4 = Path(rootTest) / "sourceDir" / "file4.txt";
654 Path tfile1 = Path(rootTest) / "targetDir" / "level1" / "level2" / "file1.txt";
655 Path tfile2 = Path(rootTest) / "targetDir" / "level1" / "level2" / "file2.txt";
656 Path tfile3 = Path(rootTest) / "targetDir" / "level1" / "file3.txt";
657 Path tfile4 = Path(rootTest) / "targetDir" / "file4.txt";
659 Path target = Path(rootTest) / "targetDir";
661 DPL::Utils::MakeDir(path);
662 DPL::Utils::MakeDir(innerPath);
663 DPL::Utils::MakeDir(innerPath2);
664 DPL::Utils::MakeEmptyFile(file1);
665 DPL::Utils::MakeEmptyFile(file2);
666 DPL::Utils::MakeEmptyFile(file3);
667 DPL::Utils::MakeEmptyFile(file4);
669 DPL::Utils::CopyDir(path, target);
671 RUNNER_ASSERT_MSG(tfile1.Exists(), tfile1.Fullpath() + " not exists");
672 RUNNER_ASSERT_MSG(tfile1.IsFile(), tfile1.Fullpath() + " is not file");
673 RUNNER_ASSERT_MSG(tfile2.Exists(), tfile2.Fullpath() + " not exists");
674 RUNNER_ASSERT_MSG(tfile2.IsFile(), tfile2.Fullpath() + " is not file");
675 RUNNER_ASSERT_MSG(tfile3.Exists(), tfile3.Fullpath() + " not exists");
676 RUNNER_ASSERT_MSG(tfile3.IsFile(), tfile3.Fullpath() + " is not file");
677 RUNNER_ASSERT_MSG(tfile4.Exists(), tfile4.Fullpath() + " not exists");
678 RUNNER_ASSERT_MSG(tfile4.IsFile(), tfile4.Fullpath() + " is not file");
682 Name: path_copy_inner
683 Description: tests path coping to subdirectory
684 Expected: coping shoudl fail
686 RUNNER_TEST(path_copy_inner)
688 DPL::ScopedDir sd(rootTest);
690 Path path = Path(rootTest) / "touchDir";
691 Path inner = Path(rootTest) / "touchDir" / "innerDirectory";
693 bool exceptionCatched = false;
696 DPL::Utils::CopyDir(path, inner);
698 Catch(DPL::Utils::Path::CannotCopy)
700 exceptionCatched = true;
702 RUNNER_ASSERT_MSG(exceptionCatched, "Copy should fail");
707 Description: tests method compare if one path is subpath of another
708 Expected: correct results
710 RUNNER_TEST(path_issubpath)
712 Path path1 = Path(rootTest) / "touchDir/asd/sdf";
713 Path path2 = Path(rootTest) / "touchDir/asd/sdf/123";
714 Path path3 = Path(rootTest) / "touchDir/asd/sdno";
715 Path path4 = Path("/");
717 RUNNER_ASSERT(path1.isSubPath(path2));
718 RUNNER_ASSERT(!path1.isSubPath(path3));
719 RUNNER_ASSERT(!path1.isSubPath(path4));
721 RUNNER_ASSERT(!path2.isSubPath(path1));
722 RUNNER_ASSERT(!path2.isSubPath(path3));
723 RUNNER_ASSERT(!path2.isSubPath(path4));
725 RUNNER_ASSERT(path4.isSubPath(path1));
726 RUNNER_ASSERT(path4.isSubPath(path2));
727 RUNNER_ASSERT(path4.isSubPath(path3));
731 Name: path_rename_same
732 Description: tests if renam does not brokens file if target location is equal to source location
733 Expected: path is avaliable
735 RUNNER_TEST(path_rename_same)
737 DPL::ScopedDir sd(rootTest);
740 memset(&st, 0, sizeof(struct stat));
741 Path path = Path(rootTest) / "touchDir";
745 RUNNER_ASSERT(path.Exists());
749 Name: path_iterate_not_directory
750 Description: iterates not a directory
751 Expected: success full constrution
753 RUNNER_TEST(path_iterate_not_directory)
755 DPL::ScopedDir sd(rootTest);
757 Path fileTest = Path(rootTest) / "file.txt";
758 MakeEmptyFile(fileTest);
763 FOREACH(file, fileTest)
768 Catch(Path::NotDirectory)
772 RUNNER_ASSERT(passed);
776 Name: path_construction
777 Description: constructs paths in many ways
778 Expected: success full constrution
780 RUNNER_TEST(path_iterate_empty_directory)
782 DPL::ScopedDir sd(rootTest);
784 Path dirTest = Path(rootTest) / "directory";
790 FOREACH(file, dirTest)
793 LogError("Directory should be empty");
796 Catch(Path::NotDirectory)
799 LogError("Directory should exists");
801 RUNNER_ASSERT(passed);
805 Name: path_construction
806 Description: constructs paths in many ways
807 Expected: success full constrution
809 RUNNER_TEST(path_iterate_notempty_directory)
811 DPL::ScopedDir sd(rootTest);
813 Path dirTest = Path(rootTest) / "directory";
815 Path path1 = Path(rootTest) / "directory" / "file1";
816 Path path2 = Path(rootTest) / "directory" / "file2";
817 Path path3 = Path(rootTest) / "directory" / "file3";
819 std::set<std::string> resultSet;
820 std::set<std::string> testSet;
821 testSet.insert(path1.Fullpath());
822 testSet.insert(path2.Fullpath());
823 testSet.insert(path3.Fullpath());
826 MakeEmptyFile(path1);
827 MakeEmptyFile(path2);
828 MakeEmptyFile(path3);
830 FOREACH(file, dirTest)
832 resultSet.insert(file->Fullpath());
835 RUNNER_ASSERT_MSG(testSet == resultSet, "Testing");
839 Name: path_construction
840 Description: constructs paths in many ways
841 Expected: success full constrution
843 RUNNER_TEST(path_iterator_copy_constructor)
845 DPL::ScopedDir sd(rootTest);
847 Path dirTest = Path(rootTest) / "directory";
849 Path path1 = Path(rootTest) / "directory" / "file1";
850 Path path2 = Path(rootTest) / "directory" / "file2";
851 Path path3 = Path(rootTest) / "directory" / "file3";
854 MakeEmptyFile(path1);
855 MakeEmptyFile(path2);
856 MakeEmptyFile(path3);
858 std::shared_ptr<Path::Iterator> iter1(new Path::Iterator((Path(rootTest) / "directory").Fullpath().c_str()));
860 //as it's input iterator it's guaranteed for one element to be iterate only once
862 std::shared_ptr<Path::Iterator> iter2(new Path::Iterator( (*iter1)));
866 RUNNER_ASSERT_MSG(*iter2 == dirTest.end(), "Iterator is in broken state");
871 Name: path_extension_test
872 Description: Tests if file extension is correct
873 Expected: Proper recognition of extensions
875 RUNNER_TEST(path_extension_test)
877 Path path1("/path/to/file.dot");
878 Path path2("/path/to/file..dot");
879 Path path3("/path/to/file..dot.");
880 Path path4("/path/to/file..dot.dot");
881 Path path5("/path/to.dot/file");
882 Path path6("./path/to/file");
883 Path path7("./path/to/file");
884 Path path8("/path/../file.xml");
885 Path path9("/path/../file.XML");
886 Path path10("/path/../file.myfileextension");
888 RUNNER_ASSERT(path1.Extension() == "dot");
889 RUNNER_ASSERT(path2.Extension() == "dot");
890 RUNNER_ASSERT(path3.Extension() == "");
891 RUNNER_ASSERT(path4.Extension() == "dot");
892 RUNNER_ASSERT(path5.Extension() == "");
893 RUNNER_ASSERT(path6.Extension() == "");
894 RUNNER_ASSERT(path7.Extension() == "");
895 RUNNER_ASSERT(path8.Extension() == "xml");
896 RUNNER_ASSERT(path9.Extension() != "xml");
897 RUNNER_ASSERT(path10.Extension() == "myfileextension");
901 Name: path_has_extension_test
902 Description: Tests if file extension is correct
903 Expected: Proper recognition of extensions
905 RUNNER_TEST(path_has_extension_test)
908 Path dirTest = Path("extension");
910 Path path1 = dirTest / "file1.XML";
911 Path path2 = dirTest / "file2.JPG";
912 Path path3 = dirTest / "file3.";
913 Path path4 = dirTest / "file4";
914 Path path5 = dirTest / "file5.HTML";
915 Path path6 = dirTest / "file6.JS";
916 Path path7 = dirTest / "file7.VERY_VERY_LONG_EXTENSION";
917 Path path8 = dirTest / "file8.VERY.VERY.LONG.EXTENSION.WITH.DOTS";
919 RUNNER_ASSERT_MSG(path1.hasExtension("XML"), "Problem with comparison");
920 RUNNER_ASSERT_MSG(path2.hasExtension("JPG"), "Problem with comparison");
921 RUNNER_ASSERT_MSG(path5.hasExtension("HTML"), "Problem with comparison");
922 RUNNER_ASSERT_MSG(path6.hasExtension("JS"), "Problem with comparison");
923 RUNNER_ASSERT_MSG(path7.hasExtension("VERY_VERY_LONG_EXTENSION"),
924 "Problem with comparison");
925 RUNNER_ASSERT_MSG(path8.hasExtension("DOTS"), "Problem with comparison");
927 RUNNER_ASSERT_MSG(!path1.hasExtension(".XML"),
928 "Wrong argument in hasExtension() function");
929 RUNNER_ASSERT_MSG(!path1.hasExtension("MXL"),
930 "Wrong argument in hasExtension() function");
931 RUNNER_ASSERT_MSG(!path2.hasExtension(".JPG"),
932 "Wrong argument in hasExtension() function");
933 RUNNER_ASSERT_MSG(!path5.hasExtension(".HTML"),
934 "Wrong argument in hasExtension() function");
935 RUNNER_ASSERT_MSG(!path6.hasExtension(".JS"),
936 "Wrong argument in hasExtension() function");
938 RUNNER_ASSERT_MSG(path3.hasExtension(""), "Extension length is 0");
940 RUNNER_ASSERT_MSG(path4.hasExtension(""), "Extension length is 0");
944 Name: path_create_temp_dir
945 Description: tests if temp dir was created
946 Expected: temp dir exists
948 RUNNER_TEST(path_create_temp_dir)
950 Path p1 = CreateTempPath(Path("/usr/tmp/"));
951 Path p2 = CreateTempPath(Path("/opt/usr/apps/tmp/"));
952 Path p3 = CreateTempPath(Path("/opt/usr/apps/tmp/"));
954 RUNNER_ASSERT_MSG(p1.Exists(), "Temp dir doesn't exists");
955 RUNNER_ASSERT_MSG(p2.Exists(), "Temp dir doesn't exists");
956 RUNNER_ASSERT_MSG(p3.Exists(), "Temp dir doesn't exists");
957 RUNNER_ASSERT_MSG(p2.Fullpath() != p3.Fullpath(), "Each temp path should be unique due to having tv_usec in dir name.");