From 62b7a4bdad57640d03ae5212a8d80f3e31b1fd86 Mon Sep 17 00:00:00 2001 From: Kasper Marstal <kaspermarstal@gmail.com> Date: Fri, 14 Aug 2015 17:30:47 +0200 Subject: [PATCH] ENH: ELASTIX-1 Add Test data manager --- Testing/Unit/CMakeLists.txt | 28 ++++++++++++++--- Testing/Unit/elxDataDirectories.h | 8 +++++ Testing/Unit/elxDataDirectories.h.in | 8 +++++ Testing/Unit/elxDataManager.cxx | 30 ++++++++++++++++++ Testing/Unit/elxDataManager.h | 47 ++++++++++++++++++++++++++++ Testing/Unit/elxExampleUnitTest.cxx | 27 ++++++++-------- Testing/Unit/elxTestHarness.h.in | 7 ----- 7 files changed, 130 insertions(+), 25 deletions(-) create mode 100644 Testing/Unit/elxDataDirectories.h create mode 100644 Testing/Unit/elxDataDirectories.h.in create mode 100644 Testing/Unit/elxDataManager.cxx create mode 100644 Testing/Unit/elxDataManager.h delete mode 100644 Testing/Unit/elxTestHarness.h.in diff --git a/Testing/Unit/CMakeLists.txt b/Testing/Unit/CMakeLists.txt index 0e92b5a3..17d66ca7 100644 --- a/Testing/Unit/CMakeLists.txt +++ b/Testing/Unit/CMakeLists.txt @@ -1,24 +1,42 @@ -#--------------------------------------------------------------------- +# --------------------------------------------------------------------- # To add a test to the build system, append it to the list below. # Any GoogleTests in these files are automatically added to CTest and -# the Kibana dashboard. +# the elastix dashboard. set( ElastixUnitTestFilenames elxExampleUnitTest.cxx + itkRegistration.cxx ) -#--------------------------------------------------------------------- +# --------------------------------------------------------------------- # Set data directories set( ELASTIX_UNITTEST_INPUT_DATA_DIR ${CMAKE_CURRENT_BINARY_DIR}/Data/Input ) +set( ELASTIX_UNITTEST_OUTPUT_DATA_DIR ${CMAKE_CURRENT_BINARY_DIR}/Data/Output ) set( ELASTIX_UNITTEST_BASELINE_DATA_DIR ${CMAKE_CURRENT_BINARY_DIR}/Data/Baseline ) +if( NOT EXISTS ${ELASTIX_UNITTEST_OUTPUT_DATA_DIR} ) + file( MAKE_DIRECTORY ${ELASTIX_UNITTEST_OUTPUT_DATA_DIR} ) +endif() + +if( NOT EXISTS ${ELASTIX_UNITTEST_OUTPUT_DATA_DIR} ) + message( FATAL_ERROR + "Could not create directory for output data. Make sure elastix has permission to write to disk." + ) +endif() + configure_file( - ${CMAKE_CURRENT_SOURCE_DIR}/elxTestHarness.h.in - ${CMAKE_CURRENT_BINARY_DIR}/elxTestHarness.h + ${CMAKE_CURRENT_SOURCE_DIR}/elxDataDirectories.h.in + ${CMAKE_CURRENT_SOURCE_DIR}/elxDataDirectories.h ESCAPE_QUOTES ) # Build tests +add_library( DataManager elxDataManager.cxx ) + +list( APPEND TEST_LIBRARIES + DataManager +) + foreach( ElastixUnitTestFilename ${ElastixUnitTestFilenames} ) # Build tests executables string( REPLACE ".cxx" "" ElastixUnitTest ${ElastixUnitTestFilename} ) diff --git a/Testing/Unit/elxDataDirectories.h b/Testing/Unit/elxDataDirectories.h new file mode 100644 index 00000000..9f2b7ef3 --- /dev/null +++ b/Testing/Unit/elxDataDirectories.h @@ -0,0 +1,8 @@ +#ifndef __elxTestDataDirectories_h +#define __elxTestDataDirectories_h + +#define ELASTIX_UNITTEST_INPUT_DATA_DIR "/Users/kasper/Development/build/SuperElastix/Elastix-build/Testing/Unit/Data/Input" +#define ELASTIX_UNITTEST_OUTPUT_DATA_DIR "/Users/kasper/Development/build/SuperElastix/Elastix-build/Testing/Unit/Data/Output" +#define ELASTIX_UNITTEST_BASELINE_DATA_DIR "/Users/kasper/Development/build/SuperElastix/Elastix-build/Testing/Unit/Data/Baseline" + +#endif // __elxTestDataDirectories_h diff --git a/Testing/Unit/elxDataDirectories.h.in b/Testing/Unit/elxDataDirectories.h.in new file mode 100644 index 00000000..835845d1 --- /dev/null +++ b/Testing/Unit/elxDataDirectories.h.in @@ -0,0 +1,8 @@ +#ifndef __elxTestDataDirectories_h +#define __elxTestDataDirectories_h + +#define ELASTIX_UNITTEST_INPUT_DATA_DIR "@ELASTIX_UNITTEST_INPUT_DATA_DIR@" +#define ELASTIX_UNITTEST_OUTPUT_DATA_DIR "@ELASTIX_UNITTEST_OUTPUT_DATA_DIR@" +#define ELASTIX_UNITTEST_BASELINE_DATA_DIR "@ELASTIX_UNITTEST_BASELINE_DATA_DIR@" + +#endif // __elxTestDataDirectories_h \ No newline at end of file diff --git a/Testing/Unit/elxDataManager.cxx b/Testing/Unit/elxDataManager.cxx new file mode 100644 index 00000000..e9aa4e4a --- /dev/null +++ b/Testing/Unit/elxDataManager.cxx @@ -0,0 +1,30 @@ +#ifndef __DataManager_cxx +#define __DataManager_cxx + +#include "elxDataManager.h" + +std::string +DataManager +::GetInput( const std::string filename ) const +{ + const std::string path = this->GetInputDirectory() + this->GetPathSeparator() + filename; + return path; +} + +std::string +DataManager +::GetOutput( const std::string filename ) const +{ + const std::string path = this->GetOutputDirectory() + this->GetPathSeparator() + filename; + return path; +} + +std::string +DataManager +::GetBaseline( const std::string filename ) const +{ + const std::string path = this->GetBaselineDirectory() + this->GetPathSeparator() + filename; + return path; +} + +#endif // __elxTestData_cxx \ No newline at end of file diff --git a/Testing/Unit/elxDataManager.h b/Testing/Unit/elxDataManager.h new file mode 100644 index 00000000..61d4dcad --- /dev/null +++ b/Testing/Unit/elxDataManager.h @@ -0,0 +1,47 @@ +#ifndef __DataManager_h +#define __DataManager_h + +#include <string> + +#include "itkMacro.h" +#include "itkProcessObject.h" + +#include "elxDataDirectories.h" + +class DataManager +{ +public: + + DataManager() + { + this->m_InputDirectory = ELASTIX_UNITTEST_INPUT_DATA_DIR; + this->m_OutputDirectory = ELASTIX_UNITTEST_OUTPUT_DATA_DIR; + this->m_BaselineDirectory = ELASTIX_UNITTEST_BASELINE_DATA_DIR; + } + + std::string GetInputDirectory( void ) const { return this->m_InputDirectory; }; + std::string GetOutputDirectory( void ) const { return this->m_InputDirectory; }; + std::string GetBaselineDirectory( void ) const { return this->m_InputDirectory; }; + + std::string GetInput( const std::string filename ) const; + std::string GetOutput( const std::string filename ) const; + std::string GetBaseline( const std::string filename ) const; + + std::string GetPathSeparator () const + { +#ifdef WIN32 + return ";"; +#else + return ":"; +#endif + } + +private: + + std::string m_InputDirectory; + std::string m_BaselineDirectory; + std::string m_OutputDirectory; + +}; + +#endif // #define __DataManager_h \ No newline at end of file diff --git a/Testing/Unit/elxExampleUnitTest.cxx b/Testing/Unit/elxExampleUnitTest.cxx index 725fa981..f9ffd22e 100644 --- a/Testing/Unit/elxExampleUnitTest.cxx +++ b/Testing/Unit/elxExampleUnitTest.cxx @@ -17,24 +17,25 @@ TEST( GoogleTest, Example0 ) TEST( GoogleTest, Example1 ) { - // Record random number between 0 and 9 - int MetricValue = rand() % 10; - RecordProperty("MetricValue", MetricValue); - ASSERT_TRUE( true ); + // 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() % 10 + 10; - RecordProperty("MetricValue", MetricValue); - ASSERT_TRUE( true ); + // Record random number between 10 and 19 + int MetricValue = rand() % 10 + 10; + RecordProperty("MetricValue", MetricValue); + RecordProperty("OverlapCoefficient", 1); + ASSERT_TRUE( true ); } TEST( GoogleTest, Example3 ) { - // Record random number between 20 and 29 - int MetricValue = rand() % 10 + 20; - RecordProperty("MetricValue", MetricValue); - ASSERT_TRUE( true ); -} \ No newline at end of file + // Record random number between 20 and 29 + int MetricValue = rand() % 10 + 20; + RecordProperty("MetricValue", MetricValue); + ASSERT_TRUE( true ); +} diff --git a/Testing/Unit/elxTestHarness.h.in b/Testing/Unit/elxTestHarness.h.in deleted file mode 100644 index 8bdb97a7..00000000 --- a/Testing/Unit/elxTestHarness.h.in +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef __ElastixTestHarness_h -#define __ElastixTestHarness_h - -#define ELASTIX_UNITTEST_INPUT_DATA_DIR "@ELASTIX_UNITTEST_INPUT_DATA_DIR@" -#define ELASTIX_INITTEST_BASELINE_DATA_DIR "@ELASTIX_UNITTEST_BASELINE_DATA_DIR@" - -#endif // __ElastixTestHarness_h \ No newline at end of file -- GitLab