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_1 ${exe} clitkImageInfo ${p}Deformation4D.mhd ${p}Deformation4D_ref.info)
-ADD_TEST(clitkImageInfo_2 ${exe} clitkImageInfo ${p}Lung3D.mhd ${p}Lung3D_ref.info)
+ADD_TEST(clitkImageInfo_4d ${exe} clitkImageInfo ${p}Deformation4D.mhd ${p}Deformation4D_ref.info)
+ADD_TEST(clitkImageInfo_3d ${exe} clitkImageInfo ${p}Lung3D.mhd ${p}Lung3D_ref.info)
#=========================================================
# clitkGetSpacing
-ADD_TEST(clitkGetSpacing_1 ${exe} clitkGetSpacing -i ${p}Deformation4D.mhd ${p}Deformation4D_ref.spacing)
-ADD_TEST(clitkGetSpacing_2 ${exe} clitkGetSpacing -i ${p}Lung3D.mhd ${p}Lung3D_ref.spacing)
+ADD_TEST(clitkGetSpacing_4d ${exe} clitkGetSpacing -i ${p}Deformation4D.mhd ${p}Deformation4D_ref.spacing)
+ADD_TEST(clitkGetSpacing_3d ${exe} clitkGetSpacing -i ${p}Lung3D.mhd ${p}Lung3D_ref.spacing)
#=========================================================
# clitkGetOrigin
-ADD_TEST(clitkGetOrigin_1 ${exe} clitkGetOrigin -i ${p}Deformation4D.mhd ${p}Deformation4D_ref.origin)
-ADD_TEST(clitkGetOrigin_2 ${exe} clitkGetOrigin -i ${p}Lung3D.mhd ${p}Lung3D_ref.origin)
+ADD_TEST(clitkGetOrigin_4d ${exe} clitkGetOrigin -i ${p}Deformation4D.mhd ${p}Deformation4D_ref.origin)
+ADD_TEST(clitkGetOrigin_3d ${exe} clitkGetOrigin -i ${p}Lung3D.mhd ${p}Lung3D_ref.origin)
#=========================================================
# clitkGetSize
-ADD_TEST(clitkGetSize_1 ${exe} clitkGetSize -i ${p}Deformation4D.mhd ${p}Deformation4D_ref.size)
-ADD_TEST(clitkGetSize_2 ${exe} clitkGetSize -i ${p}Lung3D.mhd ${p}Lung3D_ref.size)
+ADD_TEST(clitkGetSize_4d ${exe} clitkGetSize -i ${p}Deformation4D.mhd ${p}Deformation4D_ref.size)
+ADD_TEST(clitkGetSize_3d ${exe} clitkGetSize -i ${p}Lung3D.mhd ${p}Lung3D_ref.size)
#=========================================================
# clitkGetDirection
-ADD_TEST(clitkGetDirection_1 ${exe} clitkGetDirection -i ${p}Deformation4D.mhd ${p}Deformation4D_ref.direction)
+ADD_TEST(clitkGetDirection_4d ${exe} clitkGetDirection -i ${p}Deformation4D.mhd ${p}Deformation4D_ref.direction)
+ADD_TEST(clitkGetDirection_3d ${exe} clitkGetDirection -i ${p}Lung3D.mhd ${p}Lung3D_ref.direction)
+#=========================================================
+# clitkBinarize
+ADD_TEST(clitkBinarizeBGl0.1356_4d ${exe} clitkBinarizeImage -i ${p}Deformation4D.mhd --mode BG -l 0.1356 -o ${tmpFile}.mhd ${p}Deformation4D_ref.binarizeBGl0.1356)
ADD_TEST(clitkGetDirection_2 ${exe} clitkGetDirection -i ${p}Lung3D.mhd ${p}Lung3D_ref.direction)
-
-
-
-
+UNSET(tmpFile)
UNSET(exe)
UNSET(p)
\ No newline at end of file
}
std::string getTmpFileName(){
-
-
- #ifdef _WIN32
- char fileName[L_tmpnam_s];
- errno_t err = tmpnam_s(fileName);
- #else
- char fileName[] = "/tmp/vvTempXXXXXX";
- int err=0;
- int fd = mkstemp(fileName);
- if(fd==-1) err=1;
- #endif
+#ifdef _WIN32
+ char fileName[L_tmpnam_s];
+ errno_t err = tmpnam_s(fileName);
+#else
+ char fileName[] = "/tmp/vvTempXXXXXX";
+ int err=0;
+ int fd = mkstemp(fileName);
+ if(fd==-1) err=1;
+#endif
if(err){
std::cout<<"couldnot create file. Exiting"<<std::endl;
exit(TEST_EXITED);
return std::string(fileName);
}
-
+void assertFalse(int fail, const std::string &message=""){
+ if(fail){
+ std::cout<<message<<std::endl;
+ exit(1);
+ }
+}
/**
* argv
* [1] executable
* [2] random options
* [2.x] -o
- * [2.x+1] outFileName
* [3] reference file
*
- * [2.x] and [2.x+1] are optional
+ * [2.x] is optional. If set a temporary file will be generated. So NO need to pass a random outputFileName
*/
int main(int argc, char** argv){
//reference file must exist or we fail
char* refFile = argv[argc-1];
- if(!(itksys::SystemTools::FileExists(refFile, true))){
- std::cout<<"refFile "<<refFile<<" doesn't exist"<<std::endl;
- return 1;
- }
+ assertFalse(!(itksys::SystemTools::FileExists(refFile, true)), "refFile "+std::string(refFile)+" doesn't exist");
std::ostringstream cmd_line;
cmd_line<<CLITK_TEST_TOOLS_PATH;
int outputOptionIndex = getOutputOptionIndex(argc, argv);
std::string outFile;
if(NO_OUTPUT_OPTION==outputOptionIndex){
- outFile = getTmpFileName();
- std::cout<<outFile<<std::endl;
- cmd_line<<">"<<outFile;
+ outFile = getTmpFileName();
+ cmd_line<<">"<<outFile;
}else{
- //todo test this else branch
- outFile = std::string(CLITK_TEST_DATA_PATH);
- outFile += argv[outputOptionIndex];
+ outFile = argv[argc-2];
}
+ std::cout<<cmd_line.str()<<std::endl;;
//run the command line
system(cmd_line.str().c_str());
- //files should be equal, so if this is the case return success=0
- int fail = (itksys::SystemTools::FilesDiffer(outFile.c_str(), refFile))?1:0;
+ //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";
+
+
+ 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))){
+ std::cout<<"Checking raws"<<std::endl;
+ assertFalse(itksys::SystemTools::FilesDiffer(refRawFile.c_str(), rawFile.c_str()), "Raws are different");
+ }
+ //file is not removed if there is a fail
+ remove(rawFile.c_str());
+ }
+ //neither the mhd is
remove(outFile.c_str());
- return fail;
+
+ //success
+ return 0;
}