diff --git a/Testing/Unit/CMakeLists.txt b/Testing/Unit/CMakeLists.txt index 0e92b5a3dcfdaae64617d9dd983efeb558214089..17d66ca7225d3a1e017d817ac8d8e7c40d11be70 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 0000000000000000000000000000000000000000..9f2b7ef3eeaf6c66923099c297779d8476b96857 --- /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 0000000000000000000000000000000000000000..835845d15b56febeb9f8d8ca19b81b8a344555b3 --- /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 0000000000000000000000000000000000000000..e9aa4e4afd6f58cc26420fdd947bfbc29817cae9 --- /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 0000000000000000000000000000000000000000..61d4dcade79545c7c85210f663d9ca07390e3f5c --- /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 725fa981e0ae8768ee500485f613190eb9edecea..f9ffd22ea257a7954d09c9e4554df86957f1e69b 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 8bdb97a716b0e259a1016dabd86123a5311d3244..0000000000000000000000000000000000000000 --- 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