diff --git a/CMake/elxGoogleTestWinConfig.cmake b/CMake/elxGoogleTestWinConfig.cmake index e72a8726f26a278eca4fcdee0471de494b67035d..4b1198035cc6b283ab067a7a7990ca27ef2adb36 100644 --- a/CMake/elxGoogleTestWinConfig.cmake +++ b/CMake/elxGoogleTestWinConfig.cmake @@ -1,6 +1,5 @@ +# GoogleTest needs static linking include( ${CMAKE_SOURCE_DIR}/CMake/elxCompilerFlags.cmake ) - foreach( CompilerFlag ${CompilerFlags} ) - # GoogleTest needs static linking string( REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}" ) endforeach() diff --git a/CMake/elxWinConfig.cmake b/CMake/elxWinConfig.cmake new file mode 100644 index 0000000000000000000000000000000000000000..35dab0a369545509c13b3c700128cca062457c88 --- /dev/null +++ b/CMake/elxWinConfig.cmake @@ -0,0 +1,17 @@ +string( LENGTH "${CMAKE_CURRENT_SOURCE_DIR}" n ) +if( n GREATER 50 ) +message( + FATAL_ERROR + "ITK source code directory path length is too long (${n} > 50)." + "Please move the ITK source code directory to a directory with a shorter path." + ) +endif() + +string( LENGTH "${CMAKE_CURRENT_BINARY_DIR}" n ) +if( n GREATER 50 ) +message( + FATAL_ERROR + "ITK build directory path length is too long (${n} > 50)." + "Please set the ITK build directory to a directory with a shorter path." + ) +endif() diff --git a/CMakeLists.txt b/CMakeLists.txt index a50193ad594d9bb936e834a77c47dc9b5a60c8b0..d15c9c47aba0ea77ad0cb26bddd574c42b6d6af8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,12 +1,17 @@ cmake_minimum_required( VERSION 2.8 ) +if( CMAKE_HOST_WIN32 ) + include( elxWinConfig.cmake ) +endif() + #--------------------------------------------------------------------- -project( elastix ) +project( Elastix ) #--------------------------------------------------------------------- # ITK find_package( ITK REQUIRED ) +set( ITK_NO_IO_FACTORY_REGISTER_MANAGER 1 ) include( ${ITK_USE_FILE} ) include( "${CMAKE_CURRENT_SOURCE_DIR}/CMake/elxRequiredITKModules.cmake" ) diff --git a/Testing/CMakeLists.txt b/Testing/CMakeLists.txt index 30ddd1ec093b16e0242510cb49da8395166adebc..4b259cbbade4450e579a01154cc37d649e2d0259 100644 --- a/Testing/CMakeLists.txt +++ b/Testing/CMakeLists.txt @@ -1,9 +1,20 @@ #--------------------------------------------------------------------- # Setup GoogleTest -if( NOT EXISTS "${CMAKE_SOURCE_DIR}/Testing/GoogleTest/.git" ) - message( FATAL_ERROR "Could not find GoogleTest submodule. Please run -git submodule update --init in the source directory to compile tests." ) +find_package( Git ) +if( NOT EXISTS "${CMAKE_SOURCE_DIR}/Testing/GoogleTest/.git" AND GIT_EXECUTABLE ) + execute_process( + COMMAND ${GIT_EXECUTABLE} submodule update --init + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + OUTPUT_QUIET + ) +endif() + +if( NOT EXISTS ${CMAKE_SOURCE_DIR}/Testing/GoogleTest/.git ) + message( + FATAL_ERROR "Could not find GoogleTest submodule. Please run + git submodule update --init in the source directory to compile tests." + ) endif() if( ${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC" ) @@ -21,7 +32,7 @@ set( TEST_LIBRARIES ) #--------------------------------------------------------------------- -# Setup ExternalData +# Download unit test and benchmark data # ExternalData module was introduced in CMake version 2.8.11 cmake_minimum_required( VERSION 2.8.11 ) @@ -33,11 +44,28 @@ list( APPEND ExternalData_URL_TEMPLATES "https://midas3.kitware.com/midas/api/rest?method=midas.bitstream.download&checksum=%(hash)&algorithm=%(algo)" ) +# Scan the Data directory for content links on the form "[filename].[ext].md5". +# The content links contains md5 hashes that are checked for consistensy +# against corresponding files downloaded from servers in +# ExternalData_URL_TEMPLATES. These files are placed in a corresponding +# location in the build directory. +file( GLOB_RECURSE ElastixDataContentLinks "*.md5" ) +foreach(ElastixDataContentLink ${ElastixDataContentLinks}) + string( REGEX REPLACE "\\.md5$" "" ElastixDataContentLink ${ElastixDataContentLink} ) + ExternalData_Expand_Arguments( ElastixData + ElastixDataFilenames + DATA{${ElastixDataContentLink}} + ) +endforeach() + +# Test data is downloaded when this target is built +ExternalData_Add_Target( ElastixData ) + #--------------------------------------------------------------------- -# Include tests +# Build tests add_subdirectory( Unit ) -# Include benchmarks +# Build benchmarks if( ${ELASTIX_BUILD_BENCHMARKING} ) - add_subdirectory( Benchmark ) + add_subdirectory( Benchmark ) endif() diff --git a/Testing/Unit/CMakeLists.txt b/Testing/Unit/CMakeLists.txt index 964055b2590a407b7ae5928b51025faf9cc563bb..82ce81f679b2afafd86db08cc5818afad03ff953 100644 --- a/Testing/Unit/CMakeLists.txt +++ b/Testing/Unit/CMakeLists.txt @@ -2,30 +2,31 @@ # To add a test to the build system, append it to the list below. # Any GoogleTests in these files are automatically added to CTest. -set( ElastixUnitTestSource +set( ElastixUnitTestFilenames elxExampleUnitTest.cxx ) #--------------------------------------------------------------------- -# To add data to a tests, create a list "${filename}Data" (without -# the filename extension) and add data to this list. -set( elxExampleTestData - DATA{${CMAKE_BINARY_DIR}/Testing/Data/Input/BrainProtonDensitySliceR10X13Y17.png} -) +# Set test harness data directories +set( ELASTIX_TEST_DATA_INPUT_DIR ${CMAKE_CURRENT_DIR}/Data/Input ) +set( ELASTIX_TEST_DATA_BASELINE_DIR ${CMAKE_CURRENT_DIR}/Data/Baseline ) -#--------------------------------------------------------------------- -# Build test executables +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/elxTestHarnessPaths.h.in + ${CMAKE_CURRENT_BINARY_DIR}/elxTestHarnessPaths.h + ESCAPE_QUOTES +) -foreach( ElastixUnitTestFilename ${ElastixUnitTestSource} ) +# Build tests executables +foreach( ElastixUnitTestFilename ${ElastixUnitTestFilenames} ) string( REPLACE ".cxx" "" ElastixUnitTest ${ElastixUnitTestFilename} ) - add_executable( ${ElastixUnitTest} ${ElastixUnitTestFilename} ) - target_link_libraries( ${ElastixUnitTest} ${ELASTIX_LIBRARIES} ${ITK_LIBRARIES} ${TEST_LIBRARIES} ) + add_executable( "${ElastixUnitTest}" ${ElastixUnitTestFilename} ) + target_link_libraries( "${ElastixUnitTest}" ${ELASTIX_LIBRARIES} ${ITK_LIBRARIES} ${TEST_LIBRARIES} ) - ExternalData_Add_Test( "${ElastixUnitTest}ExternalDataTarget" + ExternalData_Add_Test( ElastixUnitTestData NAME ${ElastixUnitTest} - COMMAND ${ElastixUnitTest} ${${ElastixUnitTest}Data} + COMMAND "${ElastixUnitTest}" -gtest_output ) +endforeach() - ExternalData_Add_Target( "${ElastixUnitTest}ExternalDataTarget"} ) -endforeach() \ No newline at end of file diff --git a/Testing/Data/Input/BrainProtonDensitySlice.png.md5 b/Testing/Unit/Data/Input/BrainProtonDensitySlice.png.md5 similarity index 100% rename from Testing/Data/Input/BrainProtonDensitySlice.png.md5 rename to Testing/Unit/Data/Input/BrainProtonDensitySlice.png.md5 diff --git a/Testing/Data/Input/BrainProtonDensitySliceR10X13Y17.png.md5 b/Testing/Unit/Data/Input/BrainProtonDensitySliceR10X13Y17.png.md5 similarity index 100% rename from Testing/Data/Input/BrainProtonDensitySliceR10X13Y17.png.md5 rename to Testing/Unit/Data/Input/BrainProtonDensitySliceR10X13Y17.png.md5 diff --git a/Testing/Unit/elxExampleUnitTest.cxx b/Testing/Unit/elxExampleUnitTest.cxx index 1b3cfafc3e4748e901286b667bf0f3b3d3162ba4..68326895a242f4183904adf3ee7a54e03bd816a3 100644 --- a/Testing/Unit/elxExampleUnitTest.cxx +++ b/Testing/Unit/elxExampleUnitTest.cxx @@ -1,19 +1,40 @@ -#include "itkImage.h" -#include "itkImageFileReader.h" -#include "itkImageFileWriter.h" +#include <stdlib.h> +#include <time.h> #include "gtest/gtest.h" -TEST( GoogleTest, GoogleTest ) { - /** - * This example demonstrates the GoogleTest framework. - * - * When the test is built, the ExternalData CMake module - * scans the Testing/Data directory for content links on - * the form "[filename].[ext].md5" (text files with hashes). - * The content links are replaced with files from the file - * repository and checked for hash consistensy. - */ +/** + * This example demonstrates the elastix framework. + * We run a couple of tests that outputs numbers for + * use on the dashboard. + */ +TEST( GoogleTest, Example0 ) +{ + srand( time( NULL ) ); ASSERT_TRUE( true ); +} + +TEST( GoogleTest, Example1 ) +{ + // Record random number between 0 and 9 + int MetricValue = rand() % 10; + RecordProperty("MetricValue", MetricValue); + ASSERT_TRUE( true ); +} + +TEST( GoogleTest, Example2 ) +{ + // Record random number between 10 and 19 + int MetricValue = rand() % 20 + 10; + RecordProperty("MetricValue", MetricValue); + ASSERT_TRUE( true ); +} + +TEST( GoogleTest, Example3 ) +{ + // Record random number between 20 and 29 + int MetricValue = rand() % 30 + 20; + RecordProperty("MetricValue", MetricValue); + ASSERT_TRUE( true ); } \ No newline at end of file diff --git a/Testing/Unit/elxTestHarness.h b/Testing/Unit/elxTestHarness.h new file mode 100644 index 0000000000000000000000000000000000000000..2817180f622951d9c3d157d0c9cd44582bcb4d21 --- /dev/null +++ b/Testing/Unit/elxTestHarness.h @@ -0,0 +1,6 @@ +#ifndef __ElastixTestHarness_h +#define __ElastixTestHarness_h + +#include "elxTestHarnessPaths" + +#endif // __ElastixTestHarness_h \ No newline at end of file diff --git a/Testing/Unit/elxTestHarnessPaths.h.in b/Testing/Unit/elxTestHarnessPaths.h.in new file mode 100644 index 0000000000000000000000000000000000000000..06b4750aa04393e0c6952c25fbe4c4eccb41c4a3 --- /dev/null +++ b/Testing/Unit/elxTestHarnessPaths.h.in @@ -0,0 +1,7 @@ +#ifndef __ElastixTestHarness_h +#define __ElastixTestHarness_h + +#define ELASTIX_TEST_DATA_INPUT_DIR "@ELASTIX_TEST_DATA_INPUT_DIR@" +#define ELASTIX_TEST_DATA_BASELINE_DIR "@ELASTIX_TEST_DATA_BASELINE_DIR@" + +#endif // __ElastixTestHarness_h \ No newline at end of file