48 #include <visp3/core/vpIoTools.h> 50 int main(
int argc,
const char **argv)
54 std::cout <<
"The directory separator character is '" << c <<
"' (Windows platform)." << std::endl;
56 std::cout <<
"The directory separator character is '" << c <<
"' (Unix like platform)." << std::endl;
60 std::string pathname =
"C:\\Program Files (x86)\\Java\\jre7";
62 std::string pathname =
"/usr/bin/java";
66 std::cout <<
"Name of " << pathname <<
" is " <<
vpIoTools::getName(pathname) << std::endl;
68 if (argc == 3 && std::string(argv[1]) == std::string(
"-i")) {
70 std::cout <<
"Name of " << argv[2] <<
" is " <<
vpIoTools::getName(argv[2]) << std::endl;
73 std::string windowsPathnameStyle =
"\\usr\\bin\\java";
74 std::cout <<
"Parent of " << windowsPathnameStyle <<
" is " <<
vpIoTools::getParent(windowsPathnameStyle)
76 std::cout <<
"Name of " << windowsPathnameStyle <<
" is " <<
vpIoTools::getName(windowsPathnameStyle) << std::endl;
78 std::string parent =
"/usr/toto/", child =
"\\blabla\\java";
80 std::cout <<
"Create file path from parent=" << parent <<
" and child=" << child <<
" is " 83 std::string expandPath =
"~/Documents/fictional directory/fictional file";
84 std::cout <<
"Path for " << expandPath <<
" is " <<
vpIoTools::path(expandPath) << std::endl;
86 std::cout <<
"Test get name with an empty pathname=" <<
vpIoTools::getName(
"") << std::endl;
89 expandPath =
"~/Documents/fictional dir/fictional file.txt";
90 std::cout <<
"Get name with a unix expand pathname " << expandPath <<
"=" <<
vpIoTools::getName(expandPath)
92 std::cout <<
"Get parent with a unix expand pathname " << expandPath <<
"=" <<
vpIoTools::getParent(expandPath)
101 pathname =
"c:/dir/fictional directory/fictional file.txt";
104 pathname =
"/home/user/Documents/fictional directory/fictional file.txt";
107 pathname =
"~/Documents/fictional directory/fictional file.txt";
110 pathname =
"fictional directory/fictional file.txt";
114 unsigned int nbFail = 0, nbOk = 0;
126 std::cout <<
"Fail=" <<
vpIoTools::splitDrive(
"c:\\foo\\bar").second <<
" should be=\\foo\\bar" << std::endl;
139 std::cout <<
"Fail=" <<
vpIoTools::splitDrive(
"c:/foo/bar").second <<
" should be=/foo/bar" << std::endl;
142 if (strcmp(
vpIoTools::splitDrive(
"\\\\conky\\mountpoint\\foo\\bar").first.c_str(),
"\\\\conky\\mountpoint") == 0) {
147 <<
" should be=\\\\conky\\mountpoint" << std::endl;
149 if (strcmp(
vpIoTools::splitDrive(
"\\\\conky\\mountpoint\\foo\\bar").second.c_str(),
"\\foo\\bar") == 0) {
153 std::cout <<
"Fail=" <<
vpIoTools::splitDrive(
"\\\\conky\\mountpoint\\foo\\bar").second <<
" should be=\\foo\\bar" 157 if (strcmp(
vpIoTools::splitDrive(
"//conky/mountpoint/foo/bar").first.c_str(),
"//conky/mountpoint") == 0) {
161 std::cout <<
"Fail=" <<
vpIoTools::splitDrive(
"//conky/mountpoint/foo/bar").first <<
" should be=//conky/mountpoint" 168 std::cout <<
"Fail=" <<
vpIoTools::splitDrive(
"//conky/mountpoint/foo/bar").second <<
" should be=/foo/bar" 177 <<
" should be=" << std::endl;
180 "\\\\\\conky\\mountpoint\\foo\\bar") == 0) {
185 <<
" should be=\\\\\\conky\\mountpoint\\foo\\bar" << std::endl;
192 std::cout <<
"Fail=" <<
vpIoTools::splitDrive(
"///conky/mountpoint/foo/bar").first <<
" should be=" << std::endl;
194 if (strcmp(
vpIoTools::splitDrive(
"///conky/mountpoint/foo/bar").second.c_str(),
"///conky/mountpoint/foo/bar") == 0) {
199 <<
" should be=///conky/mountpoint/foo/bar" << std::endl;
207 <<
" should be=" << std::endl;
210 "\\\\conky\\\\mountpoint\\foo\\bar") == 0) {
215 <<
" should be=\\\\conky\\\\mountpoint\\foo\\bar" << std::endl;
222 std::cout <<
"Fail=" <<
vpIoTools::splitDrive(
"//conky//mountpoint/foo/bar").first <<
" should be=" << std::endl;
224 if (strcmp(
vpIoTools::splitDrive(
"//conky//mountpoint/foo/bar").second.c_str(),
"//conky//mountpoint/foo/bar") == 0) {
229 <<
" should be=//conky//mountpoint/foo/bar" << std::endl;
232 std::cout <<
"Test vpIoTools::splitDrive (Win32) - passed: " << nbOk <<
"/" << (nbOk + nbFail) << std::endl;
235 std::cerr <<
"Failed test: vpIoTools::splitDrive (Win32)" << std::endl;
315 std::cout <<
"Test vpIoTools::getFileExtension (WIN32 platform) - passed: " << nbOk <<
"/" << (nbOk + nbFail)
319 std::cerr <<
"Failed test: vpIoTools::getFileExtension (WIN32 platform)" << std::endl;
410 std::cout <<
"Test vpIoTools::getFileExtension (Unix-like platform) - passed: " << nbOk <<
"/" << (nbOk + nbFail)
416 std::string username, directory_filename;
419 directory_filename =
"C:/temp/" + username +
"/test_directory1/test directory 2/";
420 #elif (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) 421 directory_filename =
"/tmp/" + username +
"/test_directory1/test directory 2/";
425 std::cout <<
"Create directories: " << directory_filename
429 directory_filename =
"C:/temp/" + username +
"/test_directory1/test directory 3";
430 #elif (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) 431 directory_filename =
"/tmp/" + username +
"/test_directory1/test directory 3";
434 std::cout <<
"Create directories: " << directory_filename
438 directory_filename =
"C:\\temp/" + username +
"\\test_directory1\\test directory 4";
439 #elif (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) 440 directory_filename =
"/tmp\\" + username +
"\\test_directory1\\test directory 4";
444 std::cout <<
"Create directories: " << directory_filename
448 directory_filename =
"C:\\temp/" + username +
"\\test_directory1\\test directory 5 . dir/test directory 6";
449 #elif (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) 450 directory_filename =
"/tmp\\" + username +
"\\test_directory1\\test directory 5 . dir/test directory 6";
453 std::cout <<
"Create directories: " << directory_filename
456 std::cerr <<
"Exception: " << e.
what() << std::endl;
461 std::string username =
"";
463 std::ofstream dummy_file;
467 std::string path1 =
"tmp/test/file.txt";
468 std::string path2 =
"tmp/test/../test/file.txt";
475 std::cout <<
"vpIoTools::isSamePathname(" << path1 <<
", " << path2 <<
")? " << res << std::endl;
476 nbOk = res ? nbOk + 1 : nbOk;
477 nbFail = res ? nbFail : nbFail + 1;
479 path1 =
".\\tmp/test/file.txt";
481 std::cout <<
"vpIoTools::isSamePathname(" << path1 <<
", " << path2 <<
")? " << res << std::endl;
482 nbOk = res ? nbOk + 1 : nbOk;
483 nbFail = res ? nbFail : nbFail + 1;
485 path1 =
".\\tmp/test\\../fake dir/..\\test\\file.txt";
487 std::cout <<
"vpIoTools::isSamePathname(" << path1 <<
", " << path2 <<
")? " << res << std::endl;
488 nbOk = res ? nbOk + 1 : nbOk;
489 nbFail = res ? nbFail : nbFail + 1;
491 path2 =
"/tmp/test/../test/file.txt";
493 std::cout <<
"vpIoTools::isSamePathname(" << path1 <<
", " << path2 <<
")? " << res << std::endl;
494 nbOk = res ? nbOk : nbOk + 1;
495 nbFail = res ? nbFail + 1 : nbFail;
497 std::cout <<
"Test vpIoTools::isSamePathname (WIN32 platform) - passed: " << nbOk <<
"/" << (nbOk + nbFail)
500 std::cerr <<
"Failed test: vpIoTools::isSamePathname (WIN32 platform)" << std::endl;
509 std::string path1 =
"/tmp/" + username +
"/test/file.txt";
510 std::string path2 =
"/tmp/" + username +
"/test/../test/file.txt";
511 dummy_file.open(path1.c_str());
512 if (!dummy_file.is_open()) {
522 std::cout <<
"vpIoTools::isSamePathname(" << path1 <<
", " << path2 <<
")? " << res << std::endl;
523 nbOk = res ? nbOk + 1 : nbOk;
524 nbFail = res ? nbFail : nbFail + 1;
526 path1 =
"\\tmp/" + username +
"/./test/file.txt";
528 std::cout <<
"vpIoTools::isSamePathname(" << path1 <<
", " << path2 <<
")? " << res << std::endl;
529 nbOk = res ? nbOk + 1 : nbOk;
530 nbFail = res ? nbFail : nbFail + 1;
532 path1 =
"\\tmp/" + username +
"/test\\../dummy dir/..\\test\\file.txt";
534 std::cout <<
"vpIoTools::isSamePathname(" << path1 <<
", " << path2 <<
")? " << res << std::endl;
535 nbOk = res ? nbOk + 1 : nbOk;
536 nbFail = res ? nbFail : nbFail + 1;
538 path2 =
"/tmp/" + username +
"/test/../test";
540 std::cout <<
"vpIoTools::isSamePathname(" << path1 <<
", " << path2 <<
")? " << res << std::endl;
541 nbOk = res ? nbOk : nbOk + 1;
542 nbFail = res ? nbFail + 1 : nbFail;
544 path1 =
"/tmp/" + username +
"/test/";
546 std::cout <<
"vpIoTools::isSamePathname(" << path1 <<
", " << path2 <<
")? " << res << std::endl;
547 nbOk = res ? nbOk + 1 : nbOk;
548 nbFail = res ? nbFail : nbFail + 1;
550 std::cout <<
"Test vpIoTools::isSamePathname (Unix platform) - passed: " << nbOk <<
"/" << (nbOk + nbFail)
553 std::cerr <<
"Failed test: vpIoTools::isSamePathname (Unix platform)" << std::endl;
560 path1 =
"/tmp/" + username +
561 "/directory (1) with ' quote and spaces/file with ' quote (1) and " 563 dummy_file.open(path1.c_str());
564 if (!dummy_file.is_open()) {
570 std::cerr <<
"Problem with checkFilename(" << path1 <<
")!" << std::endl;
573 std::cout <<
"Test vpIoTools::checkFilename() is ok." << std::endl;
575 std::cout << std::endl <<
"End" << std::endl;
error that can be emited by ViSP classes.
const char * what() const