From 39e22c039d0de25c4f1e1c60027e4351cb30e445 Mon Sep 17 00:00:00 2001 From: dsarrut Date: Thu, 7 Apr 2011 13:43:53 +0000 Subject: [PATCH] Romulo: - 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 | 14 +++++-- tests/CMakeLists.txt | 17 ++++++++ tests/tools/clitkImageInfoTest.cxx | 51 +++++++++++++++++++++++ tests/tools/clitkWriteDicomSeriesTest.cxx | 41 ++++++++++++++++++ 4 files changed, 120 insertions(+), 3 deletions(-) create mode 100755 tests/CMakeLists.txt create mode 100755 tests/tools/clitkImageInfoTest.cxx create mode 100755 tests/tools/clitkWriteDicomSeriesTest.cxx diff --git a/CMakeLists.txt b/CMakeLists.txt index 0becec0..c007a11 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 index 0000000..822aada --- /dev/null +++ b/tests/CMakeLists.txt @@ -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 index 0000000..7642d08 --- /dev/null +++ b/tests/tools/clitkImageInfoTest.cxx @@ -0,0 +1,51 @@ +#include +#include + +#include +#include +#include + +#include + +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 index 0000000..0d00592 --- /dev/null +++ b/tests/tools/clitkWriteDicomSeriesTest.cxx @@ -0,0 +1,41 @@ +#include +#include + +#include +#include +#include + +#include + +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 -- 2.47.1