47 #include <visp3/core/vpIoTools.h>
51 main(
int argc,
const char ** argv)
56 std::cout <<
"The directory separator character is '" << c <<
"' (Windows platform)." << std::endl;
59 std::cout <<
"The directory separator character is '" << c <<
"' (Unix like platform)." << std::endl;
63 std::string pathname =
"C:\\Program Files (x86)\\Java\\jre7";
65 std::string pathname =
"/usr/bin/java";
69 std::cout <<
"Name of " << pathname <<
" is " <<
vpIoTools::getName(pathname) << std::endl;
72 if(argc == 3 && std::string(argv[1]) == std::string(
"-i"))
75 std::cout <<
"Name of " << argv[2] <<
" is " <<
vpIoTools::getName(argv[2]) << std::endl;
78 std::string windowsPathnameStyle =
"\\usr\\bin\\java";
79 std::cout <<
"Parent of " << windowsPathnameStyle <<
" is " <<
vpIoTools::getParent(windowsPathnameStyle) << std::endl;
80 std::cout <<
"Name of " << windowsPathnameStyle <<
" is " <<
vpIoTools::getName(windowsPathnameStyle) << std::endl;
82 std::string parent =
"/usr/toto/", child =
"\\blabla\\java";
84 std::cout <<
"Create file path from parent=" << parent <<
" and child=" << child <<
" is "
87 std::string expandPath =
"~/Documents/fictional directory/fictional file";
88 std::cout <<
"Path for " << expandPath <<
" is " <<
vpIoTools::path(expandPath) << std::endl;
90 std::cout <<
"Test get name with an empty pathname=" <<
vpIoTools::getName(
"") << std::endl;
93 expandPath =
"~/Documents/fictional dir/fictional file.txt";
94 std::cout <<
"Get name with a unix expand pathname " << expandPath <<
"=" <<
vpIoTools::getName(expandPath) << std::endl;
95 std::cout <<
"Get parent with a unix expand pathname " << expandPath <<
"=" <<
vpIoTools::getParent(expandPath) << std::endl;
103 pathname =
"c:/dir/fictional directory/fictional file.txt";
106 pathname =
"/home/user/Documents/fictional directory/fictional file.txt";
109 pathname =
"~/Documents/fictional directory/fictional file.txt";
112 pathname =
"fictional directory/fictional file.txt";
117 unsigned int nbFail = 0, nbOk = 0;
131 std::cout <<
"Fail=" <<
vpIoTools::splitDrive(
"c:\\foo\\bar").second <<
" should be=\\foo\\bar" << std::endl;
146 std::cout <<
"Fail=" <<
vpIoTools::splitDrive(
"c:/foo/bar").second <<
" should be=/foo/bar" << std::endl;
149 if(strcmp(
vpIoTools::splitDrive(
"\\\\conky\\mountpoint\\foo\\bar").first.c_str(),
"\\\\conky\\mountpoint") == 0) {
154 std::cout <<
"Fail=" <<
vpIoTools::splitDrive(
"\\\\conky\\mountpoint\\foo\\bar").first <<
" should be=\\\\conky\\mountpoint" << std::endl;
156 if(strcmp(
vpIoTools::splitDrive(
"\\\\conky\\mountpoint\\foo\\bar").second.c_str(),
"\\foo\\bar") == 0) {
161 std::cout <<
"Fail=" <<
vpIoTools::splitDrive(
"\\\\conky\\mountpoint\\foo\\bar").second <<
" should be=\\foo\\bar" << std::endl;
164 if(strcmp(
vpIoTools::splitDrive(
"//conky/mountpoint/foo/bar").first.c_str(),
"//conky/mountpoint") == 0) {
169 std::cout <<
"Fail=" <<
vpIoTools::splitDrive(
"//conky/mountpoint/foo/bar").first <<
" should be=//conky/mountpoint" << std::endl;
176 std::cout <<
"Fail=" <<
vpIoTools::splitDrive(
"//conky/mountpoint/foo/bar").second <<
" should be=/foo/bar" << std::endl;
184 std::cout <<
"Fail=" <<
vpIoTools::splitDrive(
"\\\\\\conky\\mountpoint\\foo\\bar").first <<
" should be=" << std::endl;
187 "\\\\\\conky\\mountpoint\\foo\\bar") == 0) {
192 std::cout <<
"Fail=" <<
vpIoTools::splitDrive(
"\\\\\\conky\\mountpoint\\foo\\bar").second <<
" should be=\\\\\\conky\\mountpoint\\foo\\bar" << std::endl;
200 std::cout <<
"Fail=" <<
vpIoTools::splitDrive(
"///conky/mountpoint/foo/bar").first <<
" should be=" << std::endl;
202 if(strcmp(
vpIoTools::splitDrive(
"///conky/mountpoint/foo/bar").second.c_str(),
"///conky/mountpoint/foo/bar") == 0) {
207 std::cout <<
"Fail=" <<
vpIoTools::splitDrive(
"///conky/mountpoint/foo/bar").second <<
" should be=///conky/mountpoint/foo/bar" << std::endl;
215 std::cout <<
"Fail=" <<
vpIoTools::splitDrive(
"\\\\conky\\\\mountpoint\\foo\\bar").first <<
" should be=" << std::endl;
218 "\\\\conky\\\\mountpoint\\foo\\bar") == 0) {
223 std::cout <<
"Fail=" <<
vpIoTools::splitDrive(
"\\\\conky\\\\mountpoint\\foo\\bar").second <<
" should be=\\\\conky\\\\mountpoint\\foo\\bar" << std::endl;
231 std::cout <<
"Fail=" <<
vpIoTools::splitDrive(
"//conky//mountpoint/foo/bar").first <<
" should be=" << std::endl;
233 if(strcmp(
vpIoTools::splitDrive(
"//conky//mountpoint/foo/bar").second.c_str(),
"//conky//mountpoint/foo/bar") == 0) {
238 std::cout <<
"Fail=" <<
vpIoTools::splitDrive(
"//conky//mountpoint/foo/bar").second <<
" should be=//conky//mountpoint/foo/bar" << std::endl;
241 std::cout <<
"Test vpIoTools::splitDrive (Win32) - passed: " << nbOk <<
"/" << (nbOk+nbFail) << std::endl;
244 std::cerr <<
"Failed test: vpIoTools::splitDrive (Win32)" << std::endl;
335 std::cout <<
"Test vpIoTools::getFileExtension (WIN32 platform) - passed: " << nbOk <<
"/" << (nbOk+nbFail) << std::endl;
338 std::cerr <<
"Failed test: vpIoTools::getFileExtension (WIN32 platform)" << std::endl;
441 std::cout <<
"Test vpIoTools::getFileExtension (Unix-like platform) - passed: " << nbOk <<
"/" << (nbOk+nbFail) << std::endl;
447 std::string path1 =
"tmp/test/file.txt";
448 std::string path2 =
"tmp/test/../test/file.txt";
455 std::cout <<
"vpIoTools::isSamePathname(" << path1 <<
", " << path2 <<
")? " << res << std::endl;
456 nbOk = res ? nbOk+1 : nbOk;
457 nbFail = res ? nbFail : nbFail+1;
459 path1 =
".\\tmp/test/file.txt";
461 std::cout <<
"vpIoTools::isSamePathname(" << path1 <<
", " << path2 <<
")? " << res << std::endl;
462 nbOk = res ? nbOk+1 : nbOk;
463 nbFail = res ? nbFail : nbFail+1;
465 path1 =
".\\tmp/test\\../fake dir/..\\test\\file.txt";
467 std::cout <<
"vpIoTools::isSamePathname(" << path1 <<
", " << path2 <<
")? " << res << std::endl;
468 nbOk = res ? nbOk+1 : nbOk;
469 nbFail = res ? nbFail : nbFail+1;
471 path2 =
"/tmp/test/../test/file.txt";
473 std::cout <<
"vpIoTools::isSamePathname(" << path1 <<
", " << path2 <<
")? " << res << std::endl;
474 nbOk = res ? nbOk : nbOk+1;
475 nbFail = res ? nbFail+1 : nbFail;
477 std::cout <<
"Test vpIoTools::isSamePathname (WIN32 platform) - passed: " << nbOk <<
"/" << (nbOk+nbFail) << std::endl;
479 std::cerr <<
"Failed test: vpIoTools::isSamePathname (WIN32 platform)" << std::endl;
486 std::string username =
"";
492 std::string path1 =
"/tmp/" + username +
"/test/file.txt";
493 std::string path2 =
"/tmp/" + username +
"/test/../test/file.txt";
494 std::ofstream dummy_file(path1.c_str());
495 if (!dummy_file.is_open()) {
505 std::cout <<
"vpIoTools::isSamePathname(" << path1 <<
", " << path2 <<
")? " << res << std::endl;
506 nbOk = res ? nbOk+1 : nbOk;
507 nbFail = res ? nbFail : nbFail+1;
509 path1 =
"\\tmp/" + username +
"/./test/file.txt";
511 std::cout <<
"vpIoTools::isSamePathname(" << path1 <<
", " << path2 <<
")? " << res << std::endl;
512 nbOk = res ? nbOk+1 : nbOk;
513 nbFail = res ? nbFail : nbFail+1;
515 path1 =
"\\tmp/" + username +
"/test\\../dummy dir/..\\test\\file.txt";
517 std::cout <<
"vpIoTools::isSamePathname(" << path1 <<
", " << path2 <<
")? " << res << std::endl;
518 nbOk = res ? nbOk+1 : nbOk;
519 nbFail = res ? nbFail : nbFail+1;
521 path2 =
"/tmp/" + username +
"/test/../test";
523 std::cout <<
"vpIoTools::isSamePathname(" << path1 <<
", " << path2 <<
")? " << res << std::endl;
524 nbOk = res ? nbOk : nbOk+1;
525 nbFail = res ? nbFail+1 : nbFail;
527 path1 =
"/tmp/" + username +
"/test/";
529 std::cout <<
"vpIoTools::isSamePathname(" << path1 <<
", " << path2 <<
")? " << res << std::endl;
530 nbOk = res ? nbOk+1 : nbOk;
531 nbFail = res ? nbFail : nbFail+1;
533 std::cout <<
"Test vpIoTools::isSamePathname (Unix platform) - passed: " << nbOk <<
"/" << (nbOk+nbFail) << std::endl;
535 std::cerr <<
"Failed test: vpIoTools::isSamePathname (Unix platform)" << std::endl;
541 std::cout << std::endl <<
"End" << std::endl;