Skip to content
Snippets Groups Projects
Commit 36c567fd authored by Kasper Marstal's avatar Kasper Marstal
Browse files

ENH: ELASTIX-1 Simplified adding test data

Test data can now be added by only placing a content link in the
Testing/Unit/Data/Input and Baseline folders. Prevously, the dev
also had to add the path of the content link to a CMake variable.
parent 3e04a279
No related branches found
No related tags found
No related merge requests found
# 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()
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()
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" )
......
#---------------------------------------------------------------------
# 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()
......@@ -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
#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
#ifndef __ElastixTestHarness_h
#define __ElastixTestHarness_h
#include "elxTestHarnessPaths"
#endif // __ElastixTestHarness_h
\ No newline at end of file
#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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment