Changeset 497 for library/tests
- Timestamp:
- 08/11/09 09:56:48 (15 years ago)
- Location:
- library/tests
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
library/tests/test_util.cpp
r493 r497 2 2 #include "stat/exp_family.h" 3 3 #include <fstream> 4 #include <stdexcept>5 #include <string>6 #include <errno.h>7 #include <fcntl.h>8 #include <string.h>9 #include <stdio.h>10 #include <sys/stat.h>11 #include <sys/types.h>12 13 #ifdef WIN3214 #include "dirent.h"15 #include <direct.h>16 #define rmdir _rmdir17 #define unlink _unlink18 #else19 #include <dirent.h>20 #include <unistd.h>21 #endif22 4 23 5 namespace bdm { … … 32 14 src.read ( buffer, sizeof ( buffer ) - 1 ); 33 15 return std::string ( buffer ); 34 }35 36 bool remove_all ( const char *path ) {37 DIR *dir;38 dirent *de;39 40 bool rv = true;41 if ( ( dir = opendir ( path ) ) != 0 ) {42 try {43 std::string top ( path );44 top += "/";45 46 while ( ( de = readdir ( dir ) ) != 0 ) {47 if ( strcmp ( de->d_name, "." ) && strcmp ( de->d_name, ".." ) ) {48 std::string subpath ( top );49 subpath += de->d_name;50 remove_all ( subpath.c_str() );51 }52 }53 } catch ( ... ) {54 closedir ( dir );55 throw;56 }57 58 closedir ( dir );59 60 if ( rmdir ( path ) ) {61 std::string msg = "can't remove dir ";62 msg += path;63 throw std::runtime_error ( msg );64 }65 } else {66 if ( ( errno == ENOTDIR ) || // Linux67 ( errno == EINVAL ) ) { // Windows68 if ( unlink ( path ) ) {69 std::string msg = "can't remove file ";70 msg += path;71 throw std::runtime_error ( msg );72 }73 } else {74 if ( errno != ENOENT ) {75 std::string msg = "can't remove ";76 msg += path;77 throw std::runtime_error ( msg );78 } else {79 // it wasn't there in the first place80 rv = false;81 }82 }83 }84 85 return rv;86 16 } 87 17 -
library/tests/test_util.h
r486 r497 28 28 std::string load_test_file ( const char *fname ); 29 29 30 /*! \brief Recursively removes directories and files.31 32 path is the name (absolute or relative) of the file or directory to33 be removed (must not be empty). Returns true on success, false when34 path couldn't be removed because it didn't exist, throws an35 exception otherwise.36 */37 bool remove_all ( const char *path );38 39 30 double normcoef ( const epdf *ep, const itpp::vec &xb, const itpp::vec &yb, 40 31 int xn = 100, int yn = 100 );