1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
5 - University of LYON http://www.universite-lyon.fr/
6 - Léon Bérard cancer center http://www.centreleonberard.fr
7 - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the copyright notices for more information.
13 It is distributed under dual licence
15 - BSD See included LICENSE.txt file
16 - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ===========================================================================*/
24 #include <itksys/SystemTools.hxx>
25 const int NO_OUTPUT_OPTION=-1;
26 const int TEST_EXITED=1;
27 int getOutputOptionIndex(int argc, char** argv){
28 for(int i=1; i<argc; i++){
29 std::string s = argv[i];
34 return NO_OUTPUT_OPTION;
37 std::string getTmpFileName(){
41 char fileName[L_tmpnam_s];
42 errno_t err = tmpnam_s(fileName);
44 char fileName[] = "/tmp/vvTempXXXXXX";
46 int fd = mkstemp(fileName);
50 std::cout<<"couldnot create file. Exiting"<<std::endl;
53 return std::string(fileName);
65 * [2.x] and [2.x+1] are optional
67 int main(int argc, char** argv){
68 //reference file must exist or we fail
69 char* refFile = argv[argc-1];
70 if(!(itksys::SystemTools::FileExists(refFile, true))){
71 std::cout<<"refFile "<<refFile<<" doesn't exist"<<std::endl;
75 std::ostringstream cmd_line;
76 cmd_line<<CLITK_TEST_TOOLS_PATH;
77 for(int i=1; i<argc-1; i++){
78 //we should ensure the file exists, find an -i index or a long file name maybe?
79 cmd_line<<argv[i]<<" ";
82 //look for the need of generating an output file
83 int outputOptionIndex = getOutputOptionIndex(argc, argv);
85 if(NO_OUTPUT_OPTION==outputOptionIndex){
86 outFile = getTmpFileName();
87 std::cout<<outFile<<std::endl;
88 cmd_line<<">"<<outFile;
90 //todo test this else branch
91 outFile = std::string(CLITK_TEST_DATA_PATH);
92 outFile += argv[outputOptionIndex];
94 //run the command line
95 system(cmd_line.str().c_str());
97 //files should be equal, so if this is the case return success=0
98 int fail = (itksys::SystemTools::FilesDiffer(outFile.c_str(), refFile))?1:0;
99 remove(outFile.c_str());