]> Creatis software - clitk.git/blobdiff - tests/tools/toolTestRunner.cxx
Reindentation of the ggo file
[clitk.git] / tests / tools / toolTestRunner.cxx
index 42226b781d9634bc1919c97d16391b3bd0da49e5..212321106ec1a32458977c592be1e19a4274a8a6 100644 (file)
@@ -57,6 +57,65 @@ void assertFalse(int fail, const std::string &message=""){
     exit(1);
   }
 }
+bool isLineToIgnore(const std::string line){
+       if(std::string::npos == line.find_first_of("ITK_InputFilterName")){
+               return true;
+       }
+       return false;
+}
+bool mhdCmp(const std::string &file, const std::string &refFile){
+       bool sameFiles = true;
+       std::ifstream in(file.c_str());
+       std::ifstream ref(file.c_str());
+       std::string line;
+       std::string refLine;
+       while ( in.good() && ref.good()){
+               getline (in,line);
+               //does the line begins by an attribute to ignore
+               if(isLineToIgnore(line)){
+                       continue;
+               }
+               
+               getline(ref,refLine);
+               while(isLineToIgnore(refLine)){
+                       getline(ref,refLine);
+               }
+               if(line!=refLine){
+                       sameFiles = false;
+                       break;
+               }
+       }
+       in.close();
+       ref.close();
+       //check files same length
+       return sameFiles;
+}
+
+#ifdef _WIN32
+void dosToUnixFile(std::string dosFile, std::string unixedFile){
+               
+       std::ifstream ifile(dosFile.c_str(),std::ios::binary);
+       ifile.seekg(0,std::ios_base::end);
+       long s=ifile.tellg();
+       char *buffer=new char[s];
+       ifile.seekg(0);
+       ifile.read(buffer,s);
+       ifile.close();
+       std::string txt(buffer,s);
+       delete[] buffer;
+       size_t off=0;
+       while ((off=txt.find("\r\n",off))!=std::string::npos)
+               txt.replace(off,sizeof("\r\n")-1,"\n");
+       std::ofstream ofile(unixedFile.c_str());
+       ofile.write(txt.c_str(),txt.size());
+       
+}
+#endif
+
+std::string mhdToRawName(const std::string &mhdName){
+       int found = mhdName.find_last_of(".");
+  return mhdName.substr(0, found)+".raw";
+}
 /**
  * argv
  * [1] executable
@@ -69,7 +128,8 @@ void assertFalse(int fail, const std::string &message=""){
 int main(int argc, char** argv){
   //reference file must exist or we fail
   char* refFile = argv[argc-1];
-  assertFalse(!(itksys::SystemTools::FileExists(refFile, true)), "refFile "+std::string(refFile)+" doesn't exist");
+       std::string strRefFile = std::string(refFile);
+  assertFalse(!(itksys::SystemTools::FileExists(refFile, true)), "refFile "+strRefFile+" doesn't exist");
   
   std::ostringstream cmd_line;
   cmd_line<<CLITK_TEST_TOOLS_PATH;
@@ -91,17 +151,21 @@ int main(int argc, char** argv){
   //run the command line
   system(cmd_line.str().c_str());
   
-  //compare source files
-  assertFalse((itksys::SystemTools::FilesDiffer(outFile.c_str(), refFile)), "Source Files are different");
-  
-  //eventually raw files associated
-  //should be passed as a boolean to check also for raw or not
-  
-  std::string refRawFile = std::string(refFile)+".raw";
+       assertFalse(!itksys::SystemTools::FileExists(outFile.c_str(), true), "no mhd have been generated");
   
+       //compare source files
+#ifdef _WIN32
+       std::string unixedOutFile= getTmpFileName();
+       //replace \r\n
+       dosToUnixFile(outFile, unixedOutFile);
+       assertFalse(!mhdCmp(unixedOutFile, refFile), "Generated mhd file != ref File");
+  remove(unixedOutFile.c_str());
+#else
+  assertFalse(!mhdCmp(outFile.c_str(), refFile), "Generated mhd file != ref File");
+#endif
+  std::string refRawFile = mhdToRawName(strRefFile);
+  std::string rawFile = mhdToRawName(outFile);
   
-  int found=outFile.find_last_of(".");
-  std::string rawFile = outFile.substr(0, found)+".raw";
   if((itksys::SystemTools::FileExists(refRawFile.c_str(), true))){
     //compare the raw stuff
     if((itksys::SystemTools::FileExists(rawFile.c_str(), true))){
@@ -117,3 +181,5 @@ int main(int argc, char** argv){
   //success
   return 0;
 }
+
+