]> Creatis software - clitk.git/blobdiff - tests/tools/clitkImageInfoTest.cxx
tests with google tests coupled with cdash reporting
[clitk.git] / tests / tools / clitkImageInfoTest.cxx
index e7cc921d49d54534c91570d8e8efd652d9ba5dbf..5e7476bc9add5f989fd1efd62fd42b2a1454c05c 100644 (file)
   - BSD        See included LICENSE.txt file
   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
 ===========================================================================*/
-#include <cstdlib>
-#include <cstdio>
-
 #include <iostream>
 #include <sstream>
 #include <string>
-
+#include <fstream>
+#include "gtest/gtest.h"
+#include "stdio.h"
 #include <itksys/SystemTools.hxx>
-
-
-const size_t NUMTESTS=2;
-
-// test files
-const char mhd_files[NUMTESTS][128] = {
-  CLITK_DATA_PATH"/4d/mhd/00.mhd",
-  CLITK_DATA_PATH"/4d/mhd/bh.mhd"
-};
-
-// pre-written validation files. the idea
-// is that the output generated from the test
-// files match the verification files
-const char validation_files[NUMTESTS][128] = {
-  CLITK_DATA_PATH"/tools/clitkImageInfoTestValidate3D.out",
-  CLITK_DATA_PATH"/tools/clitkImageInfoTestValidate4D.out"
-};
-
-int main(int argc, char** argv)
-{
-  system("pwd");
+static inline void compare(std::string mhd, std::string ref){
+  std::ostringstream cmd_line;
+  ASSERT_TRUE(itksys::SystemTools::FileExists(mhd.c_str(), true));
+  cmd_line << TOOLS_PATH<<"clitkImageInfo " << mhd << " > clitkImageInfoTest.out";
+  std::cout << "Executing " << cmd_line.str() << std::endl;
+  system(cmd_line.str().c_str());
   
-  bool failed = false;
-  for (size_t i = 0; i < NUMTESTS; i++) {
-    std::ostringstream cmd_line;
-    cmd_line << "clitkImageInfo " << mhd_files[i] << " > clitkImageInfoTest.out";
-
-    std::cout << "Executing " << cmd_line.str() << std::endl;
-    system(cmd_line.str().c_str());
-    
-    // compare output with validation file
-    std::cout << "Validating output against " << validation_files[i] << std::endl;
-    bool differ = itksys::SystemTools::FilesDiffer("clitkImageInfoTest.out", validation_files[i]);
-    if (differ)
-    {
-      failed = true;
-      std::cout << "FAILED: Program output and reference do not match." << std::endl;
-    }
-    else
-    {
-      itksys::SystemTools::RemoveFile("clitkImageInfoTest.out");
-      std::cout << "PASSED" << std::endl;
-    }
-  }
-  return failed ? -1 : 0;
+  bool differ = itksys::SystemTools::FilesDiffer("clitkImageInfoTest.out", ref.c_str());
+  remove("clitkImageInfoTest.out");
+  EXPECT_FALSE(differ);
+}
+TEST(clitkImageInfoTest, main){
+  std::string mhd1=std::string(CLITK_DATA_PATH)+"4d/mhd/00.mhd";
+  std::string ref1=std::string(CLITK_DATA_PATH)+"tools/clitkImageInfoTestValidate3D.out";
+  compare(mhd1, ref1);
+  
+  std::string mhd2=std::string(CLITK_DATA_PATH)+"4d/mhd/bh.mhd";
+  std::string ref2=std::string(CLITK_DATA_PATH)+"tools/clitkImageInfoTestValidate4D.out";
+  compare(mhd2, ref2);
 }
\ No newline at end of file