44 #include <visp3/core/vpIoTools.h> 49 void checkReadBinaryValue(std::ifstream &file,
const T checkValue)
53 if (value != checkValue) {
55 ss <<
"Read: " << value <<
" ; Expected: " << checkValue;
61 void checkReadBinaryValue<float>(std::ifstream &file,
const float checkValue)
65 if (!
vpMath::equal(value, checkValue, std::numeric_limits<float>::epsilon())) {
67 ss <<
"Read: " << value <<
" ; Expected: " << checkValue;
73 void checkReadBinaryValue<double>(std::ifstream &file,
const double checkValue)
77 if (!
vpMath::equal(value, checkValue, std::numeric_limits<double>::epsilon())) {
79 ss <<
"Read: " << value <<
" ; Expected: " << checkValue;
85 int main(
int argc,
const char **argv)
89 std::cout <<
"The directory separator character is '" << c <<
"' (Windows platform)." << std::endl;
91 std::cout <<
"The directory separator character is '" << c <<
"' (Unix like platform)." << std::endl;
95 std::string pathname =
"C:\\Program Files (x86)\\Java\\jre7";
97 std::string pathname =
"/usr/bin/java";
101 std::cout <<
"Name of " << pathname <<
" is " <<
vpIoTools::getName(pathname) << std::endl;
103 if (argc == 3 && std::string(argv[1]) == std::string(
"-i")) {
105 std::cout <<
"Name of " << argv[2] <<
" is " <<
vpIoTools::getName(argv[2]) << std::endl;
108 std::string windowsPathnameStyle =
"\\usr\\bin\\java";
109 std::cout <<
"Parent of " << windowsPathnameStyle <<
" is " <<
vpIoTools::getParent(windowsPathnameStyle)
111 std::cout <<
"Name of " << windowsPathnameStyle <<
" is " <<
vpIoTools::getName(windowsPathnameStyle) << std::endl;
113 std::string parent =
"/usr/toto/", child =
"\\blabla\\java";
115 std::cout <<
"Create file path from parent=" << parent <<
" and child=" << child <<
" is " 118 std::string expandPath =
"~/Documents/fictional directory/fictional file";
119 std::cout <<
"Path for " << expandPath <<
" is " <<
vpIoTools::path(expandPath) << std::endl;
121 std::cout <<
"Test get name with an empty pathname=" <<
vpIoTools::getName(
"") << std::endl;
124 expandPath =
"~/Documents/fictional dir/fictional file.txt";
125 std::cout <<
"Get name with a unix expand pathname " << expandPath <<
"=" <<
vpIoTools::getName(expandPath)
127 std::cout <<
"Get parent with a unix expand pathname " << expandPath <<
"=" <<
vpIoTools::getParent(expandPath)
136 pathname =
"c:/dir/fictional directory/fictional file.txt";
139 pathname =
"/home/user/Documents/fictional directory/fictional file.txt";
142 pathname =
"~/Documents/fictional directory/fictional file.txt";
145 pathname =
"fictional directory/fictional file.txt";
149 unsigned int nbFail = 0, nbOk = 0;
161 std::cout <<
"Fail=" <<
vpIoTools::splitDrive(
"c:\\foo\\bar").second <<
" should be=\\foo\\bar" << std::endl;
174 std::cout <<
"Fail=" <<
vpIoTools::splitDrive(
"c:/foo/bar").second <<
" should be=/foo/bar" << std::endl;
177 if (strcmp(
vpIoTools::splitDrive(
"\\\\conky\\mountpoint\\foo\\bar").first.c_str(),
"\\\\conky\\mountpoint") == 0) {
182 <<
" should be=\\\\conky\\mountpoint" << std::endl;
184 if (strcmp(
vpIoTools::splitDrive(
"\\\\conky\\mountpoint\\foo\\bar").second.c_str(),
"\\foo\\bar") == 0) {
188 std::cout <<
"Fail=" <<
vpIoTools::splitDrive(
"\\\\conky\\mountpoint\\foo\\bar").second <<
" should be=\\foo\\bar" 192 if (strcmp(
vpIoTools::splitDrive(
"//conky/mountpoint/foo/bar").first.c_str(),
"//conky/mountpoint") == 0) {
196 std::cout <<
"Fail=" <<
vpIoTools::splitDrive(
"//conky/mountpoint/foo/bar").first <<
" should be=//conky/mountpoint" 203 std::cout <<
"Fail=" <<
vpIoTools::splitDrive(
"//conky/mountpoint/foo/bar").second <<
" should be=/foo/bar" 212 <<
" should be=" << std::endl;
215 "\\\\\\conky\\mountpoint\\foo\\bar") == 0) {
220 <<
" should be=\\\\\\conky\\mountpoint\\foo\\bar" << std::endl;
227 std::cout <<
"Fail=" <<
vpIoTools::splitDrive(
"///conky/mountpoint/foo/bar").first <<
" should be=" << std::endl;
229 if (strcmp(
vpIoTools::splitDrive(
"///conky/mountpoint/foo/bar").second.c_str(),
"///conky/mountpoint/foo/bar") == 0) {
234 <<
" should be=///conky/mountpoint/foo/bar" << std::endl;
242 <<
" should be=" << std::endl;
245 "\\\\conky\\\\mountpoint\\foo\\bar") == 0) {
250 <<
" should be=\\\\conky\\\\mountpoint\\foo\\bar" << std::endl;
257 std::cout <<
"Fail=" <<
vpIoTools::splitDrive(
"//conky//mountpoint/foo/bar").first <<
" should be=" << std::endl;
259 if (strcmp(
vpIoTools::splitDrive(
"//conky//mountpoint/foo/bar").second.c_str(),
"//conky//mountpoint/foo/bar") == 0) {
264 <<
" should be=//conky//mountpoint/foo/bar" << std::endl;
267 std::cout <<
"Test vpIoTools::splitDrive (Win32) - passed: " << nbOk <<
"/" << (nbOk + nbFail) << std::endl;
270 std::cerr <<
"Failed test: vpIoTools::splitDrive (Win32)" << std::endl;
350 std::cout <<
"Test vpIoTools::getFileExtension (WIN32 platform) - passed: " << nbOk <<
"/" << (nbOk + nbFail)
354 std::cerr <<
"Failed test: vpIoTools::getFileExtension (WIN32 platform)" << std::endl;
445 std::cout <<
"Test vpIoTools::getFileExtension (Unix-like platform) - passed: " << nbOk <<
"/" << (nbOk + nbFail)
451 std::string username, directory_filename;
454 std::string tmp_dir =
"C:/temp/" + username;
455 #elif (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) 456 std::string tmp_dir =
"/tmp/" + username;
459 directory_filename = tmp_dir +
"/test_directory1/test directory 2/";
460 #elif (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) 461 directory_filename = tmp_dir +
"/test_directory1/test directory 2/";
465 std::cout <<
"Create directories: " << directory_filename
469 directory_filename = tmp_dir +
"/test_directory1/test directory 3";
470 #elif (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) 471 directory_filename = tmp_dir +
"/test_directory1/test directory 3";
474 std::cout <<
"Create directories: " << directory_filename
478 directory_filename =
"C:\\temp/" + username +
"\\test_directory1\\test directory 4";
479 #elif (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) 480 directory_filename =
"/tmp\\" + username +
"\\test_directory1\\test directory 4";
484 std::cout <<
"Create directories: " << directory_filename
488 directory_filename =
"C:\\temp/" + username +
"\\test_directory1\\test directory 5 . dir/test directory 6";
489 #elif (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) 490 directory_filename =
"/tmp\\" + username +
"\\test_directory1\\test directory 5 . dir/test directory 6";
493 std::cout <<
"Create directories: " << directory_filename
498 std::cerr <<
"Cannot remove directory: " << tmp_dir <<
"/test_directory1" << std::endl;
501 std::cerr <<
"Exception: " << e.
what() << std::endl;
506 std::string username =
"";
508 std::ofstream dummy_file;
512 std::string path1 =
"tmp/test/file.txt";
513 std::string path2 =
"tmp/test/../test/file.txt";
520 std::cout <<
"vpIoTools::isSamePathname(" << path1 <<
", " << path2 <<
")? " << res << std::endl;
521 nbOk = res ? nbOk + 1 : nbOk;
522 nbFail = res ? nbFail : nbFail + 1;
524 path1 =
".\\tmp/test/file.txt";
526 std::cout <<
"vpIoTools::isSamePathname(" << path1 <<
", " << path2 <<
")? " << res << std::endl;
527 nbOk = res ? nbOk + 1 : nbOk;
528 nbFail = res ? nbFail : nbFail + 1;
530 path1 =
".\\tmp/test\\../fake dir/..\\test\\file.txt";
532 std::cout <<
"vpIoTools::isSamePathname(" << path1 <<
", " << path2 <<
")? " << res << std::endl;
533 nbOk = res ? nbOk + 1 : nbOk;
534 nbFail = res ? nbFail : nbFail + 1;
536 path2 =
"/tmp/test/../test/file.txt";
538 std::cout <<
"vpIoTools::isSamePathname(" << path1 <<
", " << path2 <<
")? " << res << std::endl;
539 nbOk = res ? nbOk : nbOk + 1;
540 nbFail = res ? nbFail + 1 : nbFail;
542 std::cout <<
"Test vpIoTools::isSamePathname (WIN32 platform) - passed: " << nbOk <<
"/" << (nbOk + nbFail)
545 std::cerr <<
"Failed test: vpIoTools::isSamePathname (WIN32 platform)" << std::endl;
554 std::string path1 =
"/tmp/" + username +
"/test/file.txt";
555 std::string path2 =
"/tmp/" + username +
"/test/../test/file.txt";
556 dummy_file.open(path1.c_str());
557 if (!dummy_file.is_open()) {
567 std::cout <<
"vpIoTools::isSamePathname(" << path1 <<
", " << path2 <<
")? " << res << std::endl;
568 nbOk = res ? nbOk + 1 : nbOk;
569 nbFail = res ? nbFail : nbFail + 1;
571 path1 =
"\\tmp/" + username +
"/./test/file.txt";
573 std::cout <<
"vpIoTools::isSamePathname(" << path1 <<
", " << path2 <<
")? " << res << std::endl;
574 nbOk = res ? nbOk + 1 : nbOk;
575 nbFail = res ? nbFail : nbFail + 1;
577 path1 =
"\\tmp/" + username +
"/test\\../dummy dir/..\\test\\file.txt";
579 std::cout <<
"vpIoTools::isSamePathname(" << path1 <<
", " << path2 <<
")? " << res << std::endl;
580 nbOk = res ? nbOk + 1 : nbOk;
581 nbFail = res ? nbFail : nbFail + 1;
583 path2 =
"/tmp/" + username +
"/test/../test";
585 std::cout <<
"vpIoTools::isSamePathname(" << path1 <<
", " << path2 <<
")? " << res << std::endl;
586 nbOk = res ? nbOk : nbOk + 1;
587 nbFail = res ? nbFail + 1 : nbFail;
589 path1 =
"/tmp/" + username +
"/test/";
591 std::cout <<
"vpIoTools::isSamePathname(" << path1 <<
", " << path2 <<
")? " << res << std::endl;
592 nbOk = res ? nbOk + 1 : nbOk;
593 nbFail = res ? nbFail : nbFail + 1;
595 std::cout <<
"Test vpIoTools::isSamePathname (Unix platform) - passed: " << nbOk <<
"/" << (nbOk + nbFail)
600 std::cerr <<
"Cannot remove directory: " <<
"/tmp/" << username <<
"/test" << std::endl;
603 std::cerr <<
"Cannot remove directory: " <<
"/tmp/" << username <<
"/dummy dir" << std::endl;
607 std::cerr <<
"Failed test: vpIoTools::isSamePathname (Unix platform)" << std::endl;
614 path1 =
"/tmp/" + username +
615 "/directory (1) with ' quote and spaces/file with ' quote (1) and " 617 dummy_file.open(path1.c_str());
618 if (!dummy_file.is_open()) {
624 std::cerr <<
"Problem with checkFilename(" << path1 <<
")!" << std::endl;
627 std::cout <<
"Test vpIoTools::checkFilename() is ok." << std::endl;
630 if (!
vpIoTools::remove(
"/tmp/" + username +
"/directory (1) with ' quote and spaces")) {
631 std::cerr <<
"Cannot remove directory: " <<
"/tmp/" << username <<
"/directory (1) with ' quote and spaces" << std::endl;
637 std::ifstream file_endianness(filename_endianness.c_str(), std::ios::in | std::ios::binary);
638 if (file_endianness.is_open()) {
639 checkReadBinaryValue<short>(file_endianness, std::numeric_limits<short>::min());
640 checkReadBinaryValue<short>(file_endianness, std::numeric_limits<short>::max());
642 checkReadBinaryValue<unsigned short>(file_endianness, std::numeric_limits<unsigned short>::min());
643 checkReadBinaryValue<unsigned short>(file_endianness, std::numeric_limits<unsigned short>::max());
645 checkReadBinaryValue<int>(file_endianness, std::numeric_limits<int>::min());
646 checkReadBinaryValue<int>(file_endianness, std::numeric_limits<int>::max());
648 checkReadBinaryValue<unsigned int>(file_endianness, std::numeric_limits<unsigned int>::min());
649 checkReadBinaryValue<unsigned int>(file_endianness, std::numeric_limits<unsigned int>::max());
651 checkReadBinaryValue<float>(file_endianness, -std::numeric_limits<float>::max());
652 checkReadBinaryValue<float>(file_endianness, std::numeric_limits<float>::max());
654 checkReadBinaryValue<double>(file_endianness, -std::numeric_limits<double>::max());
655 checkReadBinaryValue<double>(file_endianness, std::numeric_limits<double>::max());
657 std::cout <<
"Test endianness is ok." << std::endl;
659 std::cout <<
"Cannot open file: " << filename_endianness << std::endl;
663 std::cout << std::endl <<
"End" << std::endl;
Used to indicate that a value is not in the allowed range.
static bool equal(double x, double y, double s=0.001)
error that can be emited by ViSP classes.
const char * what() const