]> Creatis software - clitk.git/commitdiff
Romulo:
authordsarrut <dsarrut>
Thu, 7 Apr 2011 13:43:53 +0000 (13:43 +0000)
committerdsarrut <dsarrut>
Thu, 7 Apr 2011 13:43:53 +0000 (13:43 +0000)
- Including automated test procedures in clitk
- CMakeLists.txt now includes the "tests" subdir
- tests subdir contains building instructions and source code for all tests
  + subdir structure mirrors that of $CLITK3HOME
  + tests/CMakeLists.txt contains building instructions
- see also build/tests and build/Testing (committed separately)

CMakeLists.txt
tests/CMakeLists.txt [new file with mode: 0755]
tests/tools/clitkImageInfoTest.cxx [new file with mode: 0755]
tests/tools/clitkWriteDicomSeriesTest.cxx [new file with mode: 0755]

index 0becec0cc565972e71d1c1089fe252cab7053c65..c007a11c870295618cbd5497d25253bf1a5fa006 100644 (file)
@@ -11,9 +11,6 @@ PROJECT(clitk)
 #=========================================================
 INCLUDE(cmake/common.cmake)
 #=========================================================
-#Support for the CTest dashboard testing system
-INCLUDE(CTest)
-#=========================================================
 
 #=========================================================
 # Find ITK (required)
@@ -78,6 +75,7 @@ add_subdirectory(tools)
 add_subdirectory(segmentation)
 add_subdirectory(registration)
 
+
 # Compilation options
 OPTION(CLITK_EXPERIMENTAL "Enable experimental software and features" OFF)
 OPTION(CLITK_BUILD_TOOLS "Build command-line tools" OFF)
@@ -89,5 +87,15 @@ IF (CLITK_BUILD_VV)
   add_subdirectory(vv)
 ENDIF(CLITK_BUILD_VV)
 
+
+#=========================================================
+#Support for the CTest dashboard testing system
+INCLUDE(CTest)
+#=========================================================
+add_subdirectory(tests)
+add_subdirectory(tests/tools)
+#=========================================================
+
+
 #=========================================================
 
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..822aada
--- /dev/null
@@ -0,0 +1,17 @@
+# Add test apps and test executions to this part
+# Test apps are compiled as any other app in the
+# project. Test executions are run using "make test"
+#
+IF (BUILD_TESTING)
+
+  # clitkImageInfo
+  ADD_EXECUTABLE(clitkImageInfoTest tools/clitkImageInfoTest.cxx)
+  TARGET_LINK_LIBRARIES(clitkImageInfoTest ITKIO)
+  ADD_TEST(NAME clitkImageInfoTest COMMAND clitkImageInfoTest)
+
+  # clitkWriteDicomSeries
+  ADD_EXECUTABLE(clitkWriteDicomSeriesTest tools/clitkWriteDicomSeriesTest.cxx)
+  TARGET_LINK_LIBRARIES(clitkWriteDicomSeriesTest ITKIO)
+  ADD_TEST(NAME clitkWriteDicomSeriesTest COMMAND clitkWriteDicomSeriesTest)
+
+ENDIF(BUILD_TESTING)
\ No newline at end of file
diff --git a/tests/tools/clitkImageInfoTest.cxx b/tests/tools/clitkImageInfoTest.cxx
new file mode 100755 (executable)
index 0000000..7642d08
--- /dev/null
@@ -0,0 +1,51 @@
+#include <cstdlib>
+#include <cstdio>
+
+#include <iostream>
+#include <sstream>
+#include <cassert>
+
+#include <itksys/SystemTools.hxx>
+
+const size_t NUMTESTS=2;
+
+// test files
+const char mhd_files[NUMTESTS][128] = {
+  "data/4d/mhd/00.mhd",
+  "data/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] = {
+  "data/tools/clitkImageInfoTestValidate3D.out",
+  "data/tools/clitkImageInfoTestValidate4D.out"
+};
+
+int main(int argc, char** argv)
+{
+  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;
+}
\ No newline at end of file
diff --git a/tests/tools/clitkWriteDicomSeriesTest.cxx b/tests/tools/clitkWriteDicomSeriesTest.cxx
new file mode 100755 (executable)
index 0000000..0d00592
--- /dev/null
@@ -0,0 +1,41 @@
+#include <cstdlib>
+#include <cstdio>
+
+#include <iostream>
+#include <sstream>
+#include <cassert>
+
+#include <itksys/SystemTools.hxx>
+
+const size_t NUMTESTS=1;
+
+const char mhd_files[NUMTESTS][128] = {
+  "data/3d/mhd/CT_UNTAGGED2MM_0.mhd"
+};
+
+const char dcm_dirs[NUMTESTS][128] = {
+  "data/3d/dcm/1.2.840.113704.1.111.5556.1240990904.26"
+};
+
+int main(int argc, char** argv)
+{
+  bool failed = false;
+  for (size_t i = 0; i < NUMTESTS; i++) {
+    std::ostringstream cmd_line;
+    cmd_line << "clitkWriteDicomSeries -i " << mhd_files[i] << " -d " << dcm_dirs[i] << " -o dcm --verbose";
+
+    std::cout << "Executing " << cmd_line.str() << std::endl;
+    int err = system(cmd_line.str().c_str());
+    if (err != 0)
+    {
+      failed = true;
+      std::cout << "FAILED (errno = " << err << ")" << std::endl;
+    }
+    else
+    {
+      itksys::SystemTools::RemoveADirectory("dcm");
+      std::cout << "PASSED" << std::endl;
+    }
+  }
+  return failed ? -1 : 0;
+}
\ No newline at end of file