]> Creatis software - clitk.git/blob - tests/tools/toolTestRunner.cxx
obsolete dartConfig file
[clitk.git] / tests / tools / toolTestRunner.cxx
1 /*=========================================================================
2   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
3
4   Authors belong to:
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
8
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.
12
13   It is distributed under dual licence
14
15   - BSD        See included LICENSE.txt file
16   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ===========================================================================*/
18 #include <iostream>
19 #include <sstream>
20 #include <string>
21 #include <fstream>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <itksys/SystemTools.hxx>
25 const int NO_OUTPUT_OPTION=-1;
26 int getOutputOptionIndex(int argc, char** argv){
27   for(int i=1; i<argc; i++){
28       std::string s = argv[i];
29       if(s=="-o"){
30          return i+1;
31       }
32   }
33   return NO_OUTPUT_OPTION;
34 }
35 char* getTmpFileName(){
36   char buffer [L_tmpnam];
37   char * pointer;
38
39   char* back = tmpnam (buffer);
40   if(back==NULL){
41     std::cout<<"fail to get temporary file name"<<std::endl;
42     exit(1);
43   }
44   return pointer;
45 }
46 //todo, check if files exist
47 /**
48  * argv
49  * [1] executable
50  * [2] random options
51  * [2.x] -o
52  * [2.x+1] outFileName
53  * [3] reference file
54  * 
55  * [2.x] and [2.x+1] are optional
56  */
57 int main(int argc, char** argv){
58   std::ostringstream cmd_line;
59   for(int i=1; i<argc; i++){
60       cmd_line<<argv[i]<<" ";
61   }
62   int outputOptionIndex = getOutputOptionIndex(argc, argv);
63   char* outFile;
64   if(NO_OUTPUT_OPTION==outputOptionIndex){
65     outFile = getTmpFileName();
66     cmd_line<<" "<<outFile;
67   }else{
68     outFile = argv[outputOptionIndex];
69   }
70   
71   std::cout<<"running "<<cmd_line.str()<<std::endl;
72   system(cmd_line.str().c_str());
73   //files should be equal, so if this is the case return success=0
74   char* refFile = argv[argc-1];
75   std::cout<<"comapring "<<outFile<<" to "<<refFile<<std::endl;
76   bool fail = (itksys::SystemTools::FilesDiffer(outFile, refFile))?0:1;
77   remove(outFile);
78   return fail;
79 }