]> Creatis software - clitk.git/blobdiff - tests/tools/toolTestRunner.cxx
tmpnam_s for windows
[clitk.git] / tests / tools / toolTestRunner.cxx
index 26001a0768ea92a11b3845b09bcadf19b8981e5d..7237c686323869d285771c2bee2977ff31b2b99c 100644 (file)
@@ -23,6 +23,7 @@
 #include <stdlib.h>
 #include <itksys/SystemTools.hxx>
 const int NO_OUTPUT_OPTION=-1;
+const int TEST_EXITED=1;
 int getOutputOptionIndex(int argc, char** argv){
   for(int i=1; i<argc; i++){
       std::string s = argv[i];
@@ -32,14 +33,27 @@ int getOutputOptionIndex(int argc, char** argv){
   }
   return NO_OUTPUT_OPTION;
 }
+
 std::string getTmpFileName(){
-  char buffer [L_tmpnam];
-  char* back = tmpnam (buffer);
-  if(back==NULL){
-    exit(1);
+  
+  
+  #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(back);
+  return std::string(fileName);
 }
+
+
 /**
  * argv
  * [1] executable
@@ -70,6 +84,7 @@ int main(int argc, char** argv){
   std::string outFile;
   if(NO_OUTPUT_OPTION==outputOptionIndex){
     outFile = getTmpFileName();
+    std::cout<<outFile<<std::endl;
     cmd_line<<">"<<outFile;
   }else{
     //todo test this else branch
@@ -79,8 +94,6 @@ int main(int argc, char** argv){
   //run the command line
   system(cmd_line.str().c_str());
   
-  exit(1);
-  
   //files should be equal, so if this is the case return success=0
   int fail = (itksys::SystemTools::FilesDiffer(outFile.c_str(), refFile))?1:0;
   remove(outFile.c_str());