vvMainTest.cxx
)
ADD_EXECUTABLE(toolsTest ${CUSTOM_TEST_SRC})
-ADD_DEFINITIONS(-DTOOLS_PATH=\"${PROJECT_BINARY_DIR}/bin/\")
+ADD_DEFINITIONS(-DCLITK_TEST_TOOLS_PATH=\"${PROJECT_BINARY_DIR}/bin/\")
TARGET_LINK_LIBRARIES(toolsTest vvLib ${vvExternalLibs} gtest)
# Add all tests found in the source code, calling the executable to run them
ADD_EXECUTABLE(toolTestRunner ${srcs})
TARGET_LINK_LIBRARIES(toolTestRunner vvLib ${vvExternalLibs})
SET(exe ${EXECUTABLE_OUTPUT_PATH}/toolTestRunner)
+SET(p ${CLITK_TEST_DATA_PATH})
#=========================================================
# clitkImageInfo
-ADD_TEST(clitkImageInfo_1 ${exe} clitkImageInfo Deformation4D.mhd Deformation4D_ref.info)
-ADD_TEST(clitkImageInfo_2 ${exe} clitkImageInfo Lung3D.mhd Lung3D_ref.info)
+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)
#=========================================================
# clitkGetSpacing
-ADD_TEST(clitkGetSpacing_1 ${exe} clitkGetSpacing Deformation4D.mhd Cropped_Deformation4D_ref.spacing)
-ADD_TEST(clitkGetSpacing_2 ${exe} clitkGetSpacing Lung3D.mhd Cropped_Deformation4D_ref.spacing)
-UNSET(exe)
\ No newline at end of file
+ADD_TEST(clitkGetSpacing_1 ${exe} clitkGetSpacing ${p}Deformation4D.mhd ${p}Deformation4D_ref.spacing)
+ADD_TEST(clitkGetSpacing_2 ${exe} clitkGetSpacing ${p}Lung3D.mhd ${p}Deformation4D_ref.spacing)
+UNSET(exe)
+UNSET(p)
\ No newline at end of file
}
return NO_OUTPUT_OPTION;
}
-char* getTmpFileName(){
+inline char* getTmpFileName(){
char buffer [L_tmpnam];
- char * pointer;
-
char* back = tmpnam (buffer);
if(back==NULL){
- std::cout<<"fail to get temporary file name"<<std::endl;
exit(1);
}
- return pointer;
+ return back;
}
-//todo, check if files exist
/**
* argv
* [1] executable
* [2.x] and [2.x+1] are optional
*/
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;
+ }
+
std::ostringstream cmd_line;
- for(int i=1; i<argc; i++){
+ cmd_line<<CLITK_TEST_TOOLS_PATH;
+ for(int i=1; i<argc-1; i++){
+ //we should ensure the file exists, find an -i index or a long file name maybe?
cmd_line<<argv[i]<<" ";
}
+
+ //look for the need of generating an output file
int outputOptionIndex = getOutputOptionIndex(argc, argv);
char* outFile;
if(NO_OUTPUT_OPTION==outputOptionIndex){
outFile = getTmpFileName();
- cmd_line<<" "<<outFile;
+ cmd_line<<" > "<<outFile;
}else{
- outFile = argv[outputOptionIndex];
+ //todo test this else branch
+ std::string s = std::string(CLITK_TEST_DATA_PATH);
+ s+=argv[outputOptionIndex];
+ //DO NOT MODIFY outFile
+ outFile = (char*)s.c_str();
}
- std::cout<<"running "<<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
- char* refFile = argv[argc-1];
- std::cout<<"comapring "<<outFile<<" to "<<refFile<<std::endl;
- bool fail = (itksys::SystemTools::FilesDiffer(outFile, refFile))?0:1;
+ int fail = (itksys::SystemTools::FilesDiffer(outFile, refFile))?1:0;
remove(outFile);
return fail;
}