diff --git a/Code/Testing/otbTestHelper.cxx b/Code/Testing/otbTestHelper.cxx index 82ae01f81344999052cb4254c57af897d2ee0ceb..6d2e0d93456f6a45cdbb8ee23ea8588d69d0e155 100644 --- a/Code/Testing/otbTestHelper.cxx +++ b/Code/Testing/otbTestHelper.cxx @@ -26,6 +26,9 @@ #include <cctype> #include <algorithm> +#include "itksys/SystemTools.hxx" +#include "itksys/Directory.hxx" + #include "otbImage.h" #include "otbVectorImage.h" #include "otbImageFileReader.h" @@ -1010,29 +1013,26 @@ std::map<std::string, int> TestHelper::RegressionTestBaselines(char *baselineFil std::map<std::string, int> baselines; baselines[std::string(baselineFilename)] = 0; - std::string originalBaseline(baselineFilename); + std::string myPath = itksys::SystemTools::GetFilenamePath( baselineFilename ); + itksys::Directory myDir; + myDir.Load( myPath.c_str() ); + const unsigned int nbFiles = myDir.GetNumberOfFiles(); - int x = 0; - std::string::size_type suffixPos = originalBaseline.find_last_of("."); - std::string::size_type maxPathPos = originalBaseline.find_last_of("/"); - std::string suffix; - if ((suffixPos != std::string::npos) && ((suffixPos>maxPathPos) || (maxPathPos==std::string::npos))) - { - suffix = originalBaseline.substr(suffixPos, originalBaseline.length()); - originalBaseline.erase(suffixPos, originalBaseline.length()); - } - while (++x) + const std::string originalBaseline = itksys::SystemTools::GetFilenameWithoutLastExtension(baselineFilename); + const unsigned int sizeRef = originalBaseline.size(); + + myPath.append("/"); + for(unsigned int i=0; i<nbFiles; i++) { - std::ostringstream filename; - filename << originalBaseline << "." << x << suffix; - std::ifstream filestream(filename.str().c_str()); - if (!filestream) + const std::string curFilename = itksys::SystemTools::GetFilenameWithoutLastExtension( myDir.GetFile( i ) ); + + if( curFilename.substr(0, sizeRef) == originalBaseline ) { - break; + std::string myFile = myPath; + baselines[myFile.append(myDir.GetFile( i ) )] = 0; } - baselines[filename.str()] = 0; - filestream.close(); } + return baselines; }