From 48f10b1f1a924899be2c0b085a4a083e1f606858 Mon Sep 17 00:00:00 2001 From: mpech Date: Fri, 16 Sep 2011 11:12:43 +0200 Subject: [PATCH] replacing \r\n by \n in generated mhd files when running toolTestRunner --- tests/tools/CMakeLists.txt | 5 ++-- tests/tools/toolTestRunner.cxx | 43 +++++++++++++++++++++++++++++----- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/tests/tools/CMakeLists.txt b/tests/tools/CMakeLists.txt index 3d5e87f..9ceb93c 100644 --- a/tests/tools/CMakeLists.txt +++ b/tests/tools/CMakeLists.txt @@ -19,7 +19,6 @@ ADD_EXECUTABLE(toolTestRunner ${srcs}) TARGET_LINK_LIBRARIES(toolTestRunner vvLib ${vvExternalLibs}) SET(exe ${EXECUTABLE_OUTPUT_PATH}/toolTestRunner) SET(p ${CLITK_TEST_DATA_PATH}) -SET(tmpFile "feve51zd") #========================================================= # clitkImageInfo ADD_TEST(clitkImageInfo_4d ${exe} clitkImageInfo ${p}Deformation4D.mhd ${p}Deformation4D_ref.info) @@ -45,6 +44,6 @@ ADD_TEST(clitkGetDirection_3d ${exe} clitkGetDirection -i ${p}Lung3D.mhd ${p}Lu ADD_TEST(clitkBinarizeBGl0.1356_4d ${exe} clitkBinarizeImage -i ${p}Deformation4D.mhd --mode BG -l 0.1356 -o Deformation4D_ref.binarizeBGl0.1356.mhd ${p}Deformation4D_ref.binarizeBGl0.1356) ADD_TEST(clitkBinarizeFGl0.1556_3d ${exe} clitkBinarizeImage -i ${p}Lung3D.mhd --mode FG -l 0.1556 -o Lung3D_ref.binarizeFGl0.1556.mhd ${p}Lung3D_ref.binarizeFGl0.1556) -UNSET(tmpFile) UNSET(exe) -UNSET(p) \ No newline at end of file +UNSET(p) + diff --git a/tests/tools/toolTestRunner.cxx b/tests/tools/toolTestRunner.cxx index 42226b7..8a49c43 100644 --- a/tests/tools/toolTestRunner.cxx +++ b/tests/tools/toolTestRunner.cxx @@ -57,6 +57,27 @@ void assertFalse(int fail, const std::string &message=""){ exit(1); } } + +#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 /** * argv * [1] executable @@ -91,15 +112,23 @@ 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 + //compare source files +#ifdef _WIN32 + std::string unixedOutFile= getTmpFileName(); + //replace \r\n + dosToUnixFile(outFile, unixedOutFile); + assertFalse((itksys::SystemTools::FilesDiffer(unixedOutFile.c_str(), refFile)), "Generated mhd file != ref File"); + remove(unixedOutFile.c_str()); +#else + assertFalse((itksys::SystemTools::FilesDiffer(outFile.c_str(), refFile)), "Generated mhd file != ref File"); +#endif + + //eventually raw files associated + //should be passed as a boolean to check also for raw or not std::string refRawFile = std::string(refFile)+".raw"; - - + int found=outFile.find_last_of("."); std::string rawFile = outFile.substr(0, found)+".raw"; if((itksys::SystemTools::FileExists(refRawFile.c_str(), true))){ @@ -117,3 +146,5 @@ int main(int argc, char** argv){ //success return 0; } + + -- 2.47.1