diff --git a/Core/Code/Common/mitkParameterizedTestCaller.h b/Core/Code/Common/mitkParameterizedTestCaller.h index e9500a95b1..05cd0c1863 100644 --- a/Core/Code/Common/mitkParameterizedTestCaller.h +++ b/Core/Code/Common/mitkParameterizedTestCaller.h @@ -1,124 +1,150 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef MITKPARAMETERIZEDTESTCALLER_H #define MITKPARAMETERIZEDTESTCALLER_H #include "cppunit/TestCase.h" #include #include extern std::vector globalCmdLineArgs; namespace mitk { template class ParameterizedTestCaller : public CppUnit::TestCase { typedef void (ParameterizedFixture::*TestMethod)(); public: /** * Constructor for TestCaller. This constructor builds a new ParameterizedFixture * instance owned by the ParameterizedTestCaller. * \param name name of this ParameterizedTestCaller * \param test the method this ParameterizedTestCaller calls in runTest() */ ParameterizedTestCaller(const std::string& name, TestMethod test) : TestCase(name) , m_OwnFixture(true) , m_Fixture(new ParameterizedFixture()) , m_Test(test) + , m_Parameter(globalCmdLineArgs) { } /** * Constructor for ParameterizedTestCaller. * This constructor does not create a new ParameterizedFixture instance but accepts * an existing one as parameter. The ParameterizedTestCaller will not own the * ParameterizedFixture object. * \param name name of this TestCaller * \param test the method this TestCaller calls in runTest() * \param fixture the Fixture to invoke the test method on. */ ParameterizedTestCaller(const std::string& name, TestMethod test, ParameterizedFixture& fixture) : TestCase(name) , m_OwnFixture(false) , m_Fixture(&fixture) , m_Test(test) + , m_Parameter(globalCmdLineArgs) { } /** * Constructor for ParameterizedTestCaller. * This constructor does not create a new ParameterizedFixture instance but accepts * an existing one as parameter. The ParameterizedTestCaller will own the * ParameterizedFixture object and delete it in its destructor. * \param name name of this TestCaller * \param test the method this TestCaller calls in runTest() * \param fixture the Fixture to invoke the test method on. */ ParameterizedTestCaller(const std::string& name, TestMethod test, ParameterizedFixture* fixture) : TestCase(name) , m_OwnFixture(true) , m_Fixture(fixture) , m_Test(test) + , m_Parameter(globalCmdLineArgs) + { + } + + /** + * Constructor for ParameterizedTestCaller. + * This constructor does not create a new ParameterizedFixture instance but accepts + * an existing one as parameter. The ParameterizedTestCaller will own the + * ParameterizedFixture object and delete it in its destructor. + * \param name name of this TestCaller + * \param test the method this TestCaller calls in runTest() + * \param fixture the Fixture to invoke the test method on. + * \param param A list of string parameters for the fixture. + */ + ParameterizedTestCaller(const std::string& name, TestMethod test, ParameterizedFixture* fixture, + const std::vector& param) + : TestCase(name) + , m_OwnFixture(true) + , m_Fixture(fixture) + , m_Test(test) + , m_Parameter(param) { } ~ParameterizedTestCaller() { if (m_OwnFixture) delete m_Fixture; } void runTest() { (m_Fixture->*m_Test)(); } void setUp() { - m_Fixture->setUpParameter(globalCmdLineArgs); + if (!m_Parameter.empty()) + { + m_Fixture->setUpParameter(m_Parameter); + } m_Fixture->setUp(); } void tearDown() { m_Fixture->tearDown(); } std::string toString() const { return "TestCaller " + getName(); } private: ParameterizedTestCaller(const ParameterizedTestCaller& other); ParameterizedTestCaller& operator =(const ParameterizedTestCaller& other); private: bool m_OwnFixture; ParameterizedFixture* m_Fixture; TestMethod m_Test; std::vector m_Parameter; }; } #endif // MITKPARAMETERIZEDTESTCALLER_H diff --git a/Core/Code/Common/mitkParameterizedTestFixture.h b/Core/Code/Common/mitkParameterizedTestFixture.h index f8b05bea8c..952bf34db3 100644 --- a/Core/Code/Common/mitkParameterizedTestFixture.h +++ b/Core/Code/Common/mitkParameterizedTestFixture.h @@ -1,38 +1,48 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef MITKPARAMETERIZEDTESTFIXTURE_H #define MITKPARAMETERIZEDTESTFIXTURE_H #include +#include + +#include #include #include namespace mitk { class ParameterizedTestFixture : public CppUnit::TestFixture { public: virtual void setUpParameter(const std::vector& parameter) {} +protected: + + static std::string getTestDataFilePath(const std::string& testData) + { + if (itksys::SystemTools::FileIsFullPath(testData.c_str())) return testData; + return std::string(MITK_DATA_DIR) + "/" + testData; + } }; } #endif // MITKPARAMETERIZEDTESTFIXTURE_H diff --git a/Core/Code/Common/mitkTestingMacros.h b/Core/Code/Common/mitkTestingMacros.h index e1d9e88681..8bb0bf0af4 100644 --- a/Core/Code/Common/mitkTestingMacros.h +++ b/Core/Code/Common/mitkTestingMacros.h @@ -1,281 +1,304 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include #include #include #include #include #include #include #include #include "cppunit/ui/text/TestRunner.h" namespace mitk { /** @brief Indicate a failed test. */ class TestFailedException : public std::exception { public: TestFailedException() {} }; } /** * @brief Output some text without generating a terminating newline. Include * * @ingroup MITKTestingAPI */ #define MITK_TEST_OUTPUT_NO_ENDL(x) \ std::cout x ; /** * @brief Output some text. * * @ingroup MITKTestingAPI */ #define MITK_TEST_OUTPUT(x) \ MITK_TEST_OUTPUT_NO_ENDL(x << "\n") /** * @brief Do some general test preparations. Must be called first in the * main test function. * * @deprecatedSince{2013_09} Use MITK_TEST_SUITE_REGISTRATION instead. * @ingroup MITKTestingAPI */ #define MITK_TEST_BEGIN(testName) \ std::string mitkTestName(#testName); \ mitk::TestManager::GetInstance()->Initialize(); \ try { /** * @brief Fail and finish test with message MSG * * @deprecatedSince{2013_09} Use CPPUNIT_FAIL instead * @ingroup MITKTestingAPI */ #define MITK_TEST_FAILED_MSG(MSG) \ MITK_TEST_OUTPUT(MSG) \ throw mitk::TestFailedException(); /** * @brief Must be called last in the main test function. * * @deprecatedSince{2013_09} Use MITK_TEST_SUITE_REGISTRATION isntead. * @ingroup MITKTestingAPI */ #define MITK_TEST_END() \ } catch (mitk::TestFailedException ex) { \ MITK_TEST_OUTPUT(<< "Further test execution skipped.") \ mitk::TestManager::GetInstance()->TestFailed(); \ } catch (std::exception ex) { \ MITK_TEST_OUTPUT(<< "std::exception occured " << ex.what()) \ mitk::TestManager::GetInstance()->TestFailed(); \ } \ if (mitk::TestManager::GetInstance()->NumberOfFailedTests() > 0) { \ MITK_TEST_OUTPUT(<< mitkTestName << ": [DONE FAILED] , subtests passed: " << \ mitk::TestManager::GetInstance()->NumberOfPassedTests() << " failed: " << \ mitk::TestManager::GetInstance()->NumberOfFailedTests() ) \ return EXIT_FAILURE; \ } else { \ MITK_TEST_OUTPUT(<< mitkTestName << ": " \ << mitk::TestManager::GetInstance()->NumberOfPassedTests() \ << " tests [DONE PASSED]") \ return EXIT_SUCCESS; \ } \ /** * @deprecatedSince{2013_09} Use CPPUNIT_ASSERT or CPPUNIT_ASSERT_MESSAGE instead. */ #define MITK_TEST_CONDITION(COND,MSG) \ MITK_TEST_OUTPUT_NO_ENDL(<< MSG) \ if ( ! (COND) ) { \ mitk::TestManager::GetInstance()->TestFailed(); \ MITK_TEST_OUTPUT(<< " [FAILED]\n" << "In " << __FILE__ \ << ", line " << __LINE__ \ << ": " #COND " : [FAILED]") \ } else { \ MITK_TEST_OUTPUT(<< " [PASSED]") \ mitk::TestManager::GetInstance()->TestPassed(); \ } /** * @deprecatedSince{2013_09} Use CPPUNIT_ASSERT or CPPUNIT_ASSERT_MESSAGE instead. */ #define MITK_TEST_CONDITION_REQUIRED(COND,MSG) \ MITK_TEST_OUTPUT_NO_ENDL(<< MSG) \ if ( ! (COND) ) { \ MITK_TEST_FAILED_MSG(<< " [FAILED]\n" << " +--> in " << __FILE__ \ << ", line " << __LINE__ \ << ", expression is false: \"" #COND "\"") \ } else { \ MITK_TEST_OUTPUT(<< " [PASSED]") \ mitk::TestManager::GetInstance()->TestPassed(); \ } /** * \brief Begin block which should be checked for exceptions * * @deprecatedSince{2013_09} Use CPPUNIT_ASSERT_THROW instead. * @ingroup MITKTestingAPI * * This macro, together with MITK_TEST_FOR_EXCEPTION_END, can be used * to test whether a code block throws an expected exception. The test FAILS if the * exception is NOT thrown. A simple example: * MITK_TEST_FOR_EXCEPTION_BEGIN(itk::ImageFileReaderException) typedef itk::ImageFileReader< itk::Image > ReaderType; ReaderType::Pointer reader = ReaderType::New(); reader->SetFileName("/tmp/not-existing"); reader->Update(); MITK_TEST_FOR_EXCEPTION_END(itk::ImageFileReaderException) * */ #define MITK_TEST_FOR_EXCEPTION_BEGIN(EXCEPTIONCLASS) \ try { /** * @deprecatedSince{2013_09} */ #define MITK_TEST_FOR_EXCEPTION_END(EXCEPTIONCLASS) \ mitk::TestManager::GetInstance()->TestFailed(); \ MITK_TEST_OUTPUT( << "Expected an '" << #EXCEPTIONCLASS << "' exception. [FAILED]") \ } \ catch (EXCEPTIONCLASS) { \ MITK_TEST_OUTPUT( << "Caught an expected '" << #EXCEPTIONCLASS \ << "' exception. [PASSED]") \ mitk::TestManager::GetInstance()->TestPassed(); \ } /** * @brief Simplified version of MITK_TEST_FOR_EXCEPTION_BEGIN / END for * a single statement * * @deprecatedSince{2013_09} Use CPPUNIT_ASSERT_THROW instead. * @ingroup MITKTestingAPI */ #define MITK_TEST_FOR_EXCEPTION(EXCEPTIONCLASS, STATEMENT) \ MITK_TEST_FOR_EXCEPTION_BEGIN(EXCEPTIONCLASS) \ STATEMENT ; \ MITK_TEST_FOR_EXCEPTION_END(EXCEPTIONCLASS) /** * @brief Testing macro to test if two objects are equal. * * @ingroup MITKTestingAPI * * This macro uses mitk::eps and the corresponding mitk::Equal methods for all * comparisons and will give verbose output on the dashboard/console. * Feel free to implement mitk::Equal for your own datatype or purpose. * * @deprecatedSince{2013_09} Use MITK_ASSERT_EQUAL instead. * * @param OBJ1 First object. * @param OBJ2 Second object. * @param MSG Message to appear with the test. */ #define MITK_TEST_EQUAL(OBJ1,OBJ2,MSG) \ MITK_TEST_CONDITION_REQUIRED( mitk::Equal(OBJ1, OBJ2, mitk::eps, true)==true, MSG) /** * @brief Testing macro to test if two objects are equal. * * @ingroup MITKTestingAPI * * This macro uses mitk::eps and the corresponding mitk::Equal methods for all * comparisons and will give verbose output on the dashboard/console. * Feel free to implement mitk::Equal for your own datatype or purpose. * * @param EXPECTED First object. * @param ACTUAL Second object. * @param MSG Message to appear with the test. */ #define MITK_ASSERT_EQUAL(EXPECTED, ACTUAL, MSG) \ CPPUNIT_ASSERT_MESSAGE(MSG, mitk::Equal(EXPECTED, ACTUAL, mitk::eps, true)) /** * @brief Testing macro to test if two objects are not equal. * * @ingroup MITKTestingAPI * * This macro uses mitk::eps and the corresponding mitk::Equal methods for all * comparisons and will give verbose output on the dashboard/console. * * @deprecatedSince{2013_09} Use MITK_ASSERT_NOT_EQUAL instead. * * @param OBJ1 First object. * @param OBJ2 Second object. * @param MSG Message to appear with the test. * * \sa MITK_TEST_EQUAL */ #define MITK_TEST_NOT_EQUAL(OBJ1,OBJ2,MSG) \ MITK_TEST_CONDITION_REQUIRED( mitk::Equal(OBJ1, OBJ2, mitk::eps, true)==false, MSG) /** * @brief Testing macro to test if two objects are not equal. * * @ingroup MITKTestingAPI * * This macro uses mitk::eps and the corresponding mitk::Equal methods for all * comparisons and will give verbose output on the dashboard/console. * * @param OBJ1 First object. * @param OBJ2 Second object. * @param MSG Message to appear with the test. * * \sa MITK_ASSERT_EQUAL */ #define MITK_ASSERT_NOT_EQUAL(OBJ1, OBJ2, MSG) \ CPPUNIT_ASSERT_MESSAGE(MSG, !mitk::Equal(OBJ1, OBJ2, mitk::eps, true)) /** * @brief Registers the given test suite. * * @ingroup MITKTestingAPI * * @param TESTSUITE_NAME The name of the test suite class, without "TestSuite" * at the end. */ #define MITK_TEST_SUITE_REGISTRATION(TESTSUITE_NAME) \ int TESTSUITE_NAME ## Test(int /*argc*/, char* /*argv*/[]) \ { \ CppUnit::TextUi::TestRunner runner; \ runner.addTest(TESTSUITE_NAME ## TestSuite::suite()); \ runner.run(); \ return EXIT_SUCCESS; \ } /** * @brief Adds a parameterized test to the current test suite. * * @ingroup MITKTestingAPI * * Use this macro after the CPPUNIT_TEST_SUITE() macro to add test cases - * which need parameters (e.g. from the command line). + * which need parameters from the command line. * * @param TESTMETHOD The name of the member function test. */ #define MITK_PARAMETERIZED_TEST(TESTMETHOD) \ CPPUNIT_TEST_SUITE_ADD_TEST( \ ( new mitk::ParameterizedTestCaller( \ context.getTestNameFor( #TESTMETHOD), \ &TestFixtureType::TESTMETHOD, \ - context.makeFixture() ) ) ) + context.makeFixture() ) ) ); + +/** + * @brief Adds a parameterized test to the current test suite. + * + * @ingroup MITKTestingAPI + * + * Use this macro after the CPPUNIT_TEST_SUITE() macro to add test cases + * which need one custom parameter. + * + * @param TESTMETHOD The name of the member function test. + * @param arg1 A custom string parameter being passed to the fixture. + */ +#define MITK_PARAMETERIZED_TEST_1(TESTMETHOD, arg1) \ +{ \ + std::vector args; \ + args.push_back(arg1); \ + CPPUNIT_TEST_SUITE_ADD_TEST( \ + ( new mitk::ParameterizedTestCaller( \ + context.getTestNameFor( #TESTMETHOD "_" arg1), \ + &TestFixtureType::TESTMETHOD, \ + context.makeFixture(), \ + args ) ) ); \ +} diff --git a/Core/Code/Testing/CMakeLists.txt b/Core/Code/Testing/CMakeLists.txt index 6e4063805f..bd2c3c2878 100644 --- a/Core/Code/Testing/CMakeLists.txt +++ b/Core/Code/Testing/CMakeLists.txt @@ -1,218 +1,212 @@ # The core tests need relaxed compiler flags... # TODO fix core tests to compile without these additional no-error flags if(MSVC_VERSION) # disable deprecated warnings (they would lead to errors) mitkFunctionCheckCAndCXXCompilerFlags("/wd4996" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) else() mitkFunctionCheckCAndCXXCompilerFlags("-Wno-error=deprecated" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) mitkFunctionCheckCAndCXXCompilerFlags("-Wno-error=deprecated-declarations" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) endif() MITK_CREATE_MODULE_TESTS(LABELS MITK-Core) # MITK_INSTALL_TARGETS(EXECUTABLES MitkTestDriver) mitkAddCustomModuleTest(mitkDICOMLocaleTest_spacingOk_CT mitkDICOMLocaleTest ${MITK_DATA_DIR}/spacing-ok-ct.dcm) mitkAddCustomModuleTest(mitkDICOMLocaleTest_spacingOk_MR mitkDICOMLocaleTest ${MITK_DATA_DIR}/spacing-ok-mr.dcm) mitkAddCustomModuleTest(mitkDICOMLocaleTest_spacingOk_SC mitkDICOMLocaleTest ${MITK_DATA_DIR}/spacing-ok-sc.dcm) mitkAddCustomModuleTest(mitkVolumeCalculatorTest_Png2D-bw mitkVolumeCalculatorTest ${MITK_DATA_DIR}/Png2D-bw.png ${MITK_DATA_DIR}/Pic2DplusT.nrrd) mitkAddCustomModuleTest(mitkEventMapperTest_Test1And2 mitkEventMapperTest ${MITK_DATA_DIR}/TestStateMachine1.xml ${MITK_DATA_DIR}/TestStateMachine2.xml) mitkAddCustomModuleTest(mitkEventConfigTest_CreateObjectInDifferentWays mitkEventConfigTest ${MITK_SOURCE_DIR}/Core/Code/Testing/Resources/Interactions/StatemachineConfigTest.xml) #mitkAddCustomModuleTest(mitkNodeDependentPointSetInteractorTest mitkNodeDependentPointSetInteractorTest ${MITK_DATA_DIR}/Pic3D.pic.gz ${MITK_DATA_DIR}/BallBinary30x30x30.pic.gz) mitkAddCustomModuleTest(mitkNodeDependentPointSetInteractorTest mitkNodeDependentPointSetInteractorTest ${MITK_DATA_DIR}/Pic3D.nrrd ${MITK_DATA_DIR}/BallBinary30x30x30.nrrd) mitkAddCustomModuleTest(mitkDataStorageTest_US4DCyl mitkDataStorageTest ${MITK_DATA_DIR}/US4DCyl.nrrd) mitkAddCustomModuleTest(mitkStateMachineFactoryTest_TestStateMachine1_2 mitkStateMachineFactoryTest ${MITK_DATA_DIR}/TestStateMachine1.xml ${MITK_DATA_DIR}/TestStateMachine2.xml) mitkAddCustomModuleTest(mitkDicomSeriesReaderTest_CTImage mitkDicomSeriesReaderTest ${MITK_DATA_DIR}/TinyCTAbdomen ${MITK_DATA_DIR}/DICOMReader/Broken-Series) mitkAddCustomModuleTest(mitkPointSetReaderTest mitkPointSetReaderTest ${MITK_DATA_DIR}/PointSetReaderTestData.mps) mitkAddCustomModuleTest(mitkImageTest_4DImageData mitkImageTest ${MITK_DATA_DIR}/US4DCyl.nrrd) mitkAddCustomModuleTest(mitkImageTest_2D+tImageData mitkImageTest ${MITK_DATA_DIR}/Pic2DplusT.nrrd) mitkAddCustomModuleTest(mitkImageTest_3DImageData mitkImageTest ${MITK_DATA_DIR}/Pic3D.nrrd) mitkAddCustomModuleTest(mitkImageTest_brainImage mitkImageTest ${MITK_DATA_DIR}/brain.mhd) #mitkAddCustomModuleTest(mitkImageTest_color2DImage mitkImageTest ${MITK_DATA_DIR}/NrrdWritingTestImage.jpg) mitkAddCustomModuleTest(mitkImageTest_3DImageData mitkImageGeneratorTest ${MITK_DATA_DIR}/Pic3D.nrrd) -mitkAddCustomModuleTest(mitkIOUtilTest mitkIOUtilTest #test for a randomly chosen Pic3D swivelled slice - ${MITK_DATA_DIR}/Pic3D.nrrd - ${MITK_DATA_DIR}/pointSet.mps - ${MITK_DATA_DIR}/binary.stl -) - mitkAddCustomModuleTest(mitkLevelWindowManagerTest mitkLevelWindowManagerTest ${MITK_DATA_DIR}/Pic3D.nrrd ) if(MITK_ENABLE_RENDERING_TESTING) ### since the rendering test's do not run in ubuntu, yet, we build them only for other systems or if the user explicitly sets the variable MITK_ENABLE_RENDERING_TESTING mitkAddCustomModuleTest(mitkImageVtkMapper2D_rgbaImage640x480 mitkImageVtkMapper2DTest ${MITK_DATA_DIR}/RenderingTestData/rgbaImage.png #input image to load in data storage -V ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/rgbaImage640x480REF.png #corresponding reference screenshot ) mitkAddCustomModuleTest(mitkImageVtkMapper2D_pic3d640x480 mitkImageVtkMapper2DTest #test for standard Pic3D axial slice ${MITK_DATA_DIR}/Pic3D.nrrd #input image to load in data storage -V ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/pic3d640x480REF.png #corresponding reference screenshot ) mitkAddCustomModuleTest(mitkImageVtkMapper2D_pic3dColorBlue640x480 mitkImageVtkMapper2DColorTest #test for color property (=blue) Pic3D sagittal slice ${MITK_DATA_DIR}/Pic3D.nrrd #input image to load in data storage -V ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/pic3dColorBlue640x480REF.png #corresponding reference screenshot ) mitkAddCustomModuleTest(mitkImageVtkMapper2D_pic3dLevelWindow640x480 mitkImageVtkMapper2DLevelWindowTest #test for levelwindow property (=blood) #Pic3D sagittal slice ${MITK_DATA_DIR}/Pic3D.nrrd #input image to load in data storage -V ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/pic3dLevelWindowBlood640x480REF.png #corresponding reference #screenshot ) mitkAddCustomModuleTest(mitkImageVtkMapper2D_pic3dOpacity640x480 mitkImageVtkMapper2DOpacityTest #test for opacity (=0.5) Pic3D coronal slice ${MITK_DATA_DIR}/Pic3D.nrrd #input image to load in data storage -V ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/pic3dOpacity640x480REF.png corresponding reference screenshot ) mitkAddCustomModuleTest(mitkImageVtkMapper2D_pic3dSwivel640x480 mitkImageVtkMapper2DSwivelTest #test for a randomly chosen Pic3D swivelled slice ${MITK_DATA_DIR}/Pic3D.nrrd #input image to load in data storage -V ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/pic3dSwivel640x480REF.png #corresponding reference screenshot ) mitkAddCustomModuleTest(mitkPointSetVtkMapper2D_openMeAlone640x480 mitkPointSetVtkMapper2DTest ${MITK_DATA_DIR}/RenderingTestData/openMeAlone.mps #input point set to load in data storage -V ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/openMeAlone640x480REF.png #corresponding reference screenshot ) mitkAddCustomModuleTest(mitkPointSetVtkMapper2D_Pic3DPointSetForPic3D640x480 mitkPointSetVtkMapper2DImageTest ${MITK_DATA_DIR}/Pic3D.nrrd ${MITK_DATA_DIR}/RenderingTestData/PointSetForPic3D.mps #input point set and image to load in data storage -V ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/Pic3DPointSetForPic3D640x480REF.png #corresponding reference screenshot ) mitkAddCustomModuleTest(mitkPointSetVtkMapper2D_openMeAloneGlyphType640x480 mitkPointSetVtkMapper2DGlyphTypeTest ${MITK_DATA_DIR}/RenderingTestData/openMeAlone.mps #input point set to load in data storage -V ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/openMeAloneGlyphType640x480REF.png #corresponding reference screenshot ) mitkAddCustomModuleTest(mitkPointSetVtkMapper2D_openMeAloneTransformed640x480 mitkPointSetVtkMapper2DTransformedPointsTest ${MITK_DATA_DIR}/RenderingTestData/openMeAlone.mps #input point set to load in data storage -V ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/openMeAloneTransformedPoints640x480REF.png #corresponding reference screenshot ) #Test reslice interpolation #note: nearest mode is already tested by swivel test mitkAddCustomModuleTest(ResliceInterpolationIsLinear mitkImageVtkMapper2DResliceInterpolationPropertyTest 1 #linear ${MITK_DATA_DIR}/Pic3D.nrrd -V ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/pic3dRefLinear.png #corresponding reference screenshot LINEAR ) mitkAddCustomModuleTest(ResliceInterpolationIsCubic mitkImageVtkMapper2DResliceInterpolationPropertyTest 3 #cubic ${MITK_DATA_DIR}/Pic3D.nrrd -V ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/pic3dRefCubic.png #corresponding reference screenshot CUBIC ) #End test reslice interpolation #Overlays mitkAddCustomModuleTest(mitkLabelOverlay3DRendering2DTest mitkLabelOverlay3DRendering2DTest #OverlayTest -V ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/mitkLabelOverlay3DRendering2DTest.png #corresponding reference screenshot ) mitkAddCustomModuleTest(mitkLabelOverlay3DRendering3DTest mitkLabelOverlay3DRendering3DTest #OverlayTest -V ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/mitkLabelOverlay3DRendering3DTest.png #corresponding reference screenshot ) mitkAddCustomModuleTest(mitkTextOverlay2DRenderingTest_ball mitkTextOverlay2DRenderingTest #OverlayTest ${MITK_DATA_DIR}/ball.stl #input image to load in data storage -V ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/mitkTextOverlay2DRenderingTest_ball.png #corresponding reference screenshot ) mitkAddCustomModuleTest(mitkTextOverlay2DLayouterRenderingTest_ball mitkTextOverlay2DLayouterRenderingTest #OverlayTest ${MITK_DATA_DIR}/ball.stl #input image to load in data storage -V ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/mitkTextOverlay2DLayouterRenderingTest_ball.png #corresponding reference screenshot ) mitkAddCustomModuleTest(mitkTextOverlay3DRendering2DTest_ball mitkTextOverlay3DRendering2DTest #OverlayTest ${MITK_DATA_DIR}/ball.stl #input image to load in data storage -V ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/mitkTextOverlay3DRendering2DTest_ball.png #corresponding reference screenshot ) mitkAddCustomModuleTest(mitkTextOverlay3DRendering3DTest_ball mitkTextOverlay3DRendering3DTest #OverlayTest ${MITK_DATA_DIR}/ball.stl #input image to load in data storage -V ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/mitkTextOverlay3DRendering3DTest_ball.png #corresponding reference screenshot ) mitkAddCustomModuleTest(mitkTextOverlay3DColorRenderingTest_ball mitkTextOverlay3DColorRenderingTest #OverlayTest ${MITK_DATA_DIR}/ball.stl #input image to load in data storage -V ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/mitkTextOverlay3DColorRenderingTest_ball.png #corresponding reference screenshot ) ##End of overlayTests # Testing of the rendering of binary images mitkAddCustomModuleTest(mitkImageVtkMapper2D_binaryTestImage640x480 mitkImageVtkMapper2DTest #test for standard Pic3D axial slice ${MITK_DATA_DIR}/RenderingTestData/binaryImage.nrrd #input image to load in data storage -V ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/binaryImage640x480REF.png #corresponding reference screenshot ) mitkAddCustomModuleTest(mitkImageVtkMapper2D_binaryTestImageWithRef640x480 mitkImageVtkMapper2DTest #test for standard Pic3D axial slice ${MITK_DATA_DIR}/Pic3D.nrrd ${MITK_DATA_DIR}/RenderingTestData/binaryImage.nrrd #input image to load in data storage -V ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/binaryImageWithRef640x480REF.png #corresponding reference screenshot ) # End of binary image tests mitkAddCustomModuleTest(mitkSurfaceVtkMapper3DTest_TextureProperty mitkSurfaceVtkMapper3DTest ${MITK_DATA_DIR}/ToF-Data/Kinect_LiverPhantom.vtp ${MITK_DATA_DIR}/ToF-Data/Kinect_LiverPhantom_RGBImage.nrrd -V ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/texturedLiver640x480REF.png #corresponding reference screenshot ) mitkAddCustomModuleTest(mitkImageVtkMapper2DTransferFunctionTest_Png2D-bw mitkImageVtkMapper2DTransferFunctionTest ${MITK_DATA_DIR}/Png2D-bw.png -V ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/Png2D-bw-TransferFunctionRGBImage640x480REF.png #corresponding reference screenshot ) #mitkAddCustomModuleTest(mitkImageVtkMapper2DLookupTableTest_Png2D-bw mitkImageVtkMapper2DLookupTableTest # ${MITK_DATA_DIR}/Png2D-bw.png # -V ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/Png2D-bw-LookupTableRGBImage640x480REF.png #corresponding reference screenshot #) mitkAddCustomModuleTest(mitkSurfaceGLMapper2DColorTest_RedBall mitkSurfaceGLMapper2DColorTest ${MITK_DATA_DIR}/ball.stl -V ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/ballColorRed640x480REF.png #corresponding reference screenshot ) mitkAddCustomModuleTest(mitkSurfaceGLMapper2DColorTest_DasArmeSchwein mitkSurfaceGLMapper2DColorTest ${MITK_DATA_DIR}/binary.stl -V ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/binaryColorRed640x480REF.png #corresponding reference screenshot ) mitkAddCustomModuleTest(mitkSurfaceGLMapper2DOpacityTest_BallOpacity mitkSurfaceGLMapper2DOpacityTest #opacity = 50% (0.5) ${MITK_DATA_DIR}/ball.stl -V ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/ballOpacity640x480REF.png #corresponding reference screenshot ) #Removed due to high rendering error. #mitkAddCustomModuleTest(mitkSurfaceVtkMapper3DTexturedSphereTest_Football mitkSurfaceVtkMapper3DTexturedSphereTest # ${MITK_DATA_DIR}/RenderingTestData/texture.jpg #input texture # -V # ${MITK_DATA_DIR}/RenderingTestData/ReferenceScreenshots/texturedSphere640x480REF.png corresponding reference screenshot #) SET_PROPERTY(TEST mitkImageVtkMapper2D_rgbaImage640x480 mitkImageVtkMapper2D_pic3d640x480 mitkImageVtkMapper2D_pic3dColorBlue640x480 mitkImageVtkMapper2D_pic3dLevelWindow640x480 mitkImageVtkMapper2D_pic3dSwivel640x480 mitkImageVtkMapper2DTransferFunctionTest_Png2D-bw mitkImageVtkMapper2D_pic3dOpacity640x480 mitkSurfaceGLMapper2DOpacityTest_BallOpacity mitkSurfaceGLMapper2DColorTest_DasArmeSchwein mitkSurfaceGLMapper2DColorTest_RedBall mitkSurfaceVtkMapper3DTest_TextureProperty mitkPointSetVtkMapper2D_Pic3DPointSetForPic3D640x480 mitkPointSetVtkMapper2D_openMeAlone640x480 mitkPointSetVtkMapper2D_openMeAloneGlyphType640x480 mitkPointSetVtkMapper2D_openMeAloneTransformed640x480 #mitkSurfaceVtkMapper3DTexturedSphereTest_Football PROPERTY RUN_SERIAL TRUE) endif() add_test(mitkPointSetLocaleTest ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TESTDRIVER} mitkPointSetLocaleTest ${MITK_DATA_DIR}/pointSet.mps) set_property(TEST mitkPointSetLocaleTest PROPERTY LABELS MITK-Core) add_test(mitkImageWriterTest_nrrdImage ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TESTDRIVER} mitkImageWriterTest ${MITK_DATA_DIR}/NrrdWritingTestImage.jpg) add_test(mitkImageWriterTest_2DPNGImage ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TESTDRIVER} mitkImageWriterTest ${MITK_DATA_DIR}/Png2D-bw.png) add_test(mitkImageWriterTest_rgbPNGImage ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TESTDRIVER} mitkImageWriterTest ${MITK_DATA_DIR}/RenderingTestData/rgbImage.png) add_test(mitkImageWriterTest_rgbaPNGImage ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TESTDRIVER} mitkImageWriterTest ${MITK_DATA_DIR}/RenderingTestData/rgbaImage.png) set_property(TEST mitkImageWriterTest_nrrdImage PROPERTY LABELS MITK-Core) set_property(TEST mitkImageWriterTest_2DPNGImage PROPERTY LABELS MITK-Core) set_property(TEST mitkImageWriterTest_rgbPNGImage PROPERTY LABELS MITK-Core) set_property(TEST mitkImageWriterTest_rgbaPNGImage PROPERTY LABELS MITK-Core) add_subdirectory(DICOMTesting) diff --git a/Core/Code/Testing/files.cmake b/Core/Code/Testing/files.cmake index 7ef459d238..6796cb7ed3 100644 --- a/Core/Code/Testing/files.cmake +++ b/Core/Code/Testing/files.cmake @@ -1,175 +1,175 @@ # tests with no extra command line parameter set(MODULE_TESTS + itkTotalVariationDenoisingImageFilterTest.cpp + #mitkAbstractTransformGeometryTest.cpp mitkAccessByItkTest.cpp - mitkCoreObjectFactoryTest.cpp - mitkMaterialTest.cpp mitkActionTest.cpp + mitkAffineTransformBaseTest.cpp + mitkBaseDataTest.cpp + mitkClippedSurfaceBoundsCalculatorTest.cpp + mitkCoreObjectFactoryTest.cpp mitkDispatcherTest.cpp mitkEnumerationPropertyTest.cpp mitkEventTest.cpp + mitkExceptionTest.cpp + mitkExtractSliceFilterTest.cpp mitkFocusManagerTest.cpp mitkGenericPropertyTest.cpp mitkGeometry2DTest.cpp - mitkGeometry3DTest.cpp mitkGeometry3DEqualTest.cpp + mitkGeometry3DTest.cpp mitkGeometryDataToSurfaceFilterTest.cpp mitkGlobalInteractionTest.cpp - mitkImageEqualTest.cpp + mitkGrabItkImageMemoryTest.cpp mitkImageDataItemTest.cpp - #mitkImageMapper2DTest.cpp + mitkImageDimensionConverterTest.cpp + mitkImageEqualTest.cpp mitkImageGeneratorTest.cpp - mitkBaseDataTest.cpp + #mitkImageMapper2DTest.cpp #mitkImageToItkTest.cpp mitkImportItkImageTest.cpp - mitkGrabItkImageMemoryTest.cpp mitkInstantiateAccessFunctionTest.cpp mitkInteractorTest.cpp + mitkIOUtilTest.cpp #mitkITKThreadingTest.cpp mitkLevelWindowTest.cpp + mitkLoggingAdapterTest.cpp + mitkLogTest.cpp + mitkMaterialTest.cpp mitkMessageTest.cpp + mitkNodePredicateSourceTest.cpp #mitkPipelineSmartPointerCorrectnessTest.cpp mitkPixelTypeTest.cpp mitkPlaneGeometryTest.cpp + mitkPlanePositionManagerTest.cpp mitkPointSetEqualTest.cpp mitkPointSetFileIOTest.cpp + mitkPointSetInteractorTest.cpp + mitkPointSetReaderTest.cpp mitkPointSetTest.cpp mitkPointSetWriterTest.cpp - mitkPointSetReaderTest.cpp - mitkPointSetInteractorTest.cpp - mitkPropertyTest.cpp + mitkPropertyAliasesTest.cpp + mitkPropertyDescriptionsTest.cpp + mitkPropertyExtensionsTest.cpp + mitkPropertyFiltersTest.cpp mitkPropertyListTest.cpp + mitkPropertyTest.cpp #mitkRegistrationBaseTest.cpp + mitkRenderingManagerTest.cpp #mitkSegmentationInterpolationTest.cpp + mitkShaderRepositoryTest.cpp mitkSlicedGeometry3DTest.cpp mitkSliceNavigationControllerTest.cpp - mitkStateMachineTest.cpp ##mitkStateMachineContainerTest.cpp ## rewrite test, indirect since no longer exported Bug 14529 + mitkStateMachineTest.cpp mitkStateTest.cpp - mitkSurfaceTest.cpp + mitkStepperTest.cpp mitkSurfaceEqualTest.cpp + mitkSurfaceTest.cpp mitkSurfaceToSurfaceFilterTest.cpp mitkTimeGeometryTest.cpp + mitkTransferFunctionTest.cpp mitkTransitionTest.cpp + mitkUIDGeneratorTest.cpp mitkUndoControllerTest.cpp - mitkVtkWidgetRenderingTest.cpp + mitkVectorTest.cpp mitkVerboseLimitedLinearUndoTest.cpp + mitkVtkWidgetRenderingTest.cpp mitkWeakPointerTest.cpp - mitkTransferFunctionTest.cpp - #mitkAbstractTransformGeometryTest.cpp - mitkStepperTest.cpp - itkTotalVariationDenoisingImageFilterTest.cpp - mitkRenderingManagerTest.cpp vtkMitkThickSlicesFilterTest.cpp - mitkNodePredicateSourceTest.cpp - mitkVectorTest.cpp - mitkClippedSurfaceBoundsCalculatorTest.cpp - mitkExceptionTest.cpp - mitkExtractSliceFilterTest.cpp - mitkLogTest.cpp - mitkImageDimensionConverterTest.cpp - mitkLoggingAdapterTest.cpp - mitkUIDGeneratorTest.cpp - mitkShaderRepositoryTest.cpp - mitkPlanePositionManagerTest.cpp - mitkAffineTransformBaseTest.cpp - mitkPropertyAliasesTest.cpp - mitkPropertyDescriptionsTest.cpp - mitkPropertyExtensionsTest.cpp - mitkPropertyFiltersTest.cpp ) # test with image filename as an extra command line parameter set(MODULE_IMAGE_TESTS mitkImageTimeSelectorTest.cpp #only runs on images mitkImageAccessorTest.cpp #only runs on images mitkDataNodeFactoryTest.cpp #runs on all types of data ) set(MODULE_SURFACE_TESTS mitkSurfaceVtkWriterTest.cpp #only runs on surfaces mitkDataNodeFactoryTest.cpp #runs on all types of data ) # list of images for which the tests are run set(MODULE_TESTIMAGES US4DCyl.nrrd Pic3D.nrrd Pic2DplusT.nrrd BallBinary30x30x30.nrrd Png2D-bw.png ) set(MODULE_TESTSURFACES binary.stl ball.stl ) set(MODULE_CUSTOM_TESTS - #mitkLabeledImageToSurfaceFilterTest.cpp - #mitkExternalToolsTest.cpp - mitkDataStorageTest.cpp mitkDataNodeTest.cpp - mitkDicomSeriesReaderTest.cpp + mitkDataStorageTest.cpp mitkDICOMLocaleTest.cpp - mitkEventMapperTest.cpp + mitkDicomSeriesReaderTest.cpp mitkEventConfigTest.cpp - mitkNodeDependentPointSetInteractorTest.cpp - mitkStateMachineFactoryTest.cpp - mitkPointSetLocaleTest.cpp + mitkEventMapperTest.cpp + #mitkExternalToolsTest.cpp mitkImageTest.cpp - mitkImageWriterTest.cpp - mitkImageVtkMapper2DTest.cpp + mitkImageVtkMapper2DColorTest.cpp mitkImageVtkMapper2DLevelWindowTest.cpp + mitkImageVtkMapper2DLookupTableTest.cpp mitkImageVtkMapper2DOpacityTest.cpp mitkImageVtkMapper2DResliceInterpolationPropertyTest.cpp - mitkImageVtkMapper2DColorTest.cpp mitkImageVtkMapper2DSwivelTest.cpp + mitkImageVtkMapper2DTest.cpp mitkImageVtkMapper2DTransferFunctionTest.cpp - mitkImageVtkMapper2DLookupTableTest.cpp - mitkIOUtilTest.cpp - mitkSurfaceVtkMapper3DTest - mitkSurfaceVtkMapper3DTexturedSphereTest.cpp - mitkSurfaceGLMapper2DColorTest.cpp - mitkSurfaceGLMapper2DOpacityTest.cpp - mitkVolumeCalculatorTest.cpp + mitkImageWriterTest.cpp + #mitkLabeledImageToSurfaceFilterTest.cpp + mitkLabelOverlay3DRendering2DTest.cpp + mitkLabelOverlay3DRendering3DTest.cpp mitkLevelWindowManagerTest.cpp - mitkPointSetVtkMapper2DTest.cpp - mitkPointSetVtkMapper2DImageTest.cpp + mitkNodeDependentPointSetInteractorTest.cpp + mitkPointSetLocaleTest.cpp mitkPointSetVtkMapper2DGlyphTypeTest.cpp + mitkPointSetVtkMapper2DImageTest.cpp + mitkPointSetVtkMapper2DTest.cpp mitkPointSetVtkMapper2DTransformedPointsTest.cpp - mitkLabelOverlay3DRendering2DTest.cpp - mitkLabelOverlay3DRendering3DTest.cpp - mitkTextOverlay2DRenderingTest.cpp + mitkStateMachineFactoryTest.cpp + mitkSurfaceGLMapper2DColorTest.cpp + mitkSurfaceGLMapper2DOpacityTest.cpp + mitkSurfaceVtkMapper3DTest + mitkSurfaceVtkMapper3DTexturedSphereTest.cpp mitkTextOverlay2DLayouterRenderingTest.cpp + mitkTextOverlay2DRenderingTest.cpp + mitkTextOverlay3DColorRenderingTest.cpp mitkTextOverlay3DRendering2DTest.cpp mitkTextOverlay3DRendering3DTest.cpp - mitkTextOverlay3DColorRenderingTest.cpp + mitkVolumeCalculatorTest.cpp mitkVTKRenderWindowSizeTest.cpp ) if (${VTK_MAJOR_VERSION} VERSION_LESS 6) # test can be removed with VTK 6 set(MODULE_TESTS ${MODULE_TESTS} mitkVTKRenderWindowSizeTest.cpp) endif() set(MODULE_RESOURCE_FILES Interactions/AddAndRemovePoints.xml Interactions/globalConfig.xml Interactions/StatemachineTest.xml Interactions/StatemachineConfigTest.xml ) # Create an artificial module initializing class for # the usServiceListenerTest.cpp usFunctionGenerateExecutableInit(testdriver_init_file IDENTIFIER ${MODULE_NAME}TestDriver ) # Embed the resources set(testdriver_resources ) usFunctionEmbedResources(testdriver_resources EXECUTABLE_NAME ${MODULE_NAME}TestDriver ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Resources FILES ${MODULE_RESOURCE_FILES} ) set(TEST_CPP_FILES ${testdriver_init_file} ${testdriver_resources}) diff --git a/Core/Code/Testing/mitkIOUtilTest.cpp b/Core/Code/Testing/mitkIOUtilTest.cpp index 7bb4b40927..7aad920958 100644 --- a/Core/Code/Testing/mitkIOUtilTest.cpp +++ b/Core/Code/Testing/mitkIOUtilTest.cpp @@ -1,151 +1,171 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkTestingMacros.h" #include #include #include #include #include class mitkIOUtilTestSuite : public mitk::ParameterizedTestFixture { CPPUNIT_TEST_SUITE(mitkIOUtilTestSuite); CPPUNIT_TEST(TestTempMethods); - MITK_PARAMETERIZED_TEST(TestLoadAndSaveMethods); + MITK_PARAMETERIZED_TEST_1(TestLoadAndSaveImage, "Pic3D.nrrd"); + MITK_PARAMETERIZED_TEST_1(TestLoadAndSavePointSet, "pointSet.mps"); + MITK_PARAMETERIZED_TEST_1(TestLoadAndSaveSurface, "binary.stl"); CPPUNIT_TEST_SUITE_END(); private: - std::string pathToImage; - std::string pathToPointSet; - std::string pathToSurface; + std::string testData; public: - static CppUnit::Test* suite(int argc, char* argv[]) - { - CppUnit::TestSuite* testSuite = new CppUnit::TestSuite("mitkIOUtilTest"); - testSuite->addTest(new mitk::ParameterizedTestCaller( - "bla", &mitkIOUtilTestSuite::TestTempMethods)); - return testSuite; - } - void setUpParameter(const std::vector& parameter) { - CPPUNIT_ASSERT(parameter.size() == 3); - pathToImage = parameter[0]; - pathToPointSet = parameter[1]; - pathToSurface = parameter[2]; + CPPUNIT_ASSERT(parameter.size() == 1); + testData = getTestDataFilePath(parameter[0]); } void TestTempMethods() { std::string tmpPath = mitk::IOUtil::GetTempPath(); CPPUNIT_ASSERT(!tmpPath.empty()); std::ofstream tmpFile; std::string tmpFilePath = mitk::IOUtil::CreateTemporaryFile(tmpFile); CPPUNIT_ASSERT(tmpFile && tmpFile.is_open()); CPPUNIT_ASSERT(tmpFilePath.size() > tmpPath.size()); CPPUNIT_ASSERT(tmpFilePath.substr(0, tmpPath.size()) == tmpPath); tmpFile.close(); CPPUNIT_ASSERT(std::remove(tmpFilePath.c_str()) == 0); std::string programPath = mitk::IOUtil::GetProgramPath(); CPPUNIT_ASSERT(!programPath.empty()); std::ofstream tmpFile2; std::string tmpFilePath2 = mitk::IOUtil::CreateTemporaryFile(tmpFile2, "my-XXXXXX", programPath); CPPUNIT_ASSERT(tmpFile2 && tmpFile2.is_open()); CPPUNIT_ASSERT(tmpFilePath2.size() > programPath.size()); CPPUNIT_ASSERT(tmpFilePath2.substr(0, programPath.size()) == programPath); tmpFile2.close(); CPPUNIT_ASSERT(std::remove(tmpFilePath2.c_str()) == 0); std::ofstream tmpFile3; std::string tmpFilePath3 = mitk::IOUtil::CreateTemporaryFile(tmpFile3, std::ios_base::binary, "my-XXXXXX.TXT", programPath); CPPUNIT_ASSERT(tmpFile3 && tmpFile3.is_open()); CPPUNIT_ASSERT(tmpFilePath3.size() > programPath.size()); CPPUNIT_ASSERT(tmpFilePath3.substr(0, programPath.size()) == programPath); CPPUNIT_ASSERT(tmpFilePath3.substr(tmpFilePath3.size() - 13, 3) == "my-"); CPPUNIT_ASSERT(tmpFilePath3.substr(tmpFilePath3.size() - 4) == ".TXT"); tmpFile3.close(); //CPPUNIT_ASSERT(std::remove(tmpFilePath3.c_str()) == 0) CPPUNIT_ASSERT_THROW(mitk::IOUtil::CreateTemporaryFile(tmpFile2, "XX"), mitk::Exception); std::string tmpDir = mitk::IOUtil::CreateTemporaryDirectory(); CPPUNIT_ASSERT(tmpDir.size() > tmpPath.size()); CPPUNIT_ASSERT(tmpDir.substr(0, tmpPath.size()) == tmpPath); CPPUNIT_ASSERT(itksys::SystemTools::RemoveADirectory(tmpDir.c_str())); std::string tmpDir2 = mitk::IOUtil::CreateTemporaryDirectory("my-XXXXXX", programPath); CPPUNIT_ASSERT(tmpDir2.size() > programPath.size()); CPPUNIT_ASSERT(tmpDir2.substr(0, programPath.size()) == programPath); CPPUNIT_ASSERT(itksys::SystemTools::RemoveADirectory(tmpDir2.c_str())); } - void TestLoadAndSaveMethods() + void TestLoadAndSaveImage() { - mitk::Image::Pointer img1 = mitk::IOUtil::LoadImage(pathToImage); + mitk::Image::Pointer img1 = mitk::IOUtil::LoadImage(testData); CPPUNIT_ASSERT( img1.IsNotNull()); - mitk::PointSet::Pointer pointset = mitk::IOUtil::LoadPointSet(pathToPointSet); - CPPUNIT_ASSERT( pointset.IsNotNull()); - mitk::Surface::Pointer surface = mitk::IOUtil::LoadSurface(pathToSurface); - CPPUNIT_ASSERT( surface.IsNotNull()); - std::string outDir = MITK_TEST_OUTPUT_DIR; - std::string imagePath = outDir+"/diffpic3d.nrrd"; - std::string imagePath2 = outDir+"/diffpic3d.nii.gz"; - std::string pointSetPath = outDir + "/diffpointset.mps"; - std::string surfacePath = outDir + "/diffsurface.stl"; - std::string pointSetPathWithDefaultExtension = outDir + "/diffpointset2.mps"; - std::string pointSetPathWithoutDefaultExtension = outDir + "/diffpointset2.xXx"; + std::ofstream tmpStream; + std::string imagePath = mitk::IOUtil::CreateTemporaryFile(tmpStream, "diffpic3d-XXXXXX.nrrd"); + tmpStream.close(); + std::string imagePath2 = mitk::IOUtil::CreateTemporaryFile(tmpStream, "diffpic3d-XXXXXX.nii.gz"); + tmpStream.close(); // the cases where no exception should be thrown CPPUNIT_ASSERT(mitk::IOUtil::SaveImage(img1, imagePath)); CPPUNIT_ASSERT(mitk::IOUtil::SaveBaseData(img1.GetPointer(), imagePath2)); - CPPUNIT_ASSERT(mitk::IOUtil::SavePointSet(pointset, pointSetPath)); - CPPUNIT_ASSERT(mitk::IOUtil::SaveSurface(surface, surfacePath)); + + //load data which does not exist + CPPUNIT_ASSERT_THROW(mitk::IOUtil::LoadImage("fileWhichDoesNotExist.nrrd"), mitk::Exception); + + //delete the files after the test is done + std::remove(imagePath.c_str()); + std::remove(imagePath2.c_str()); + + mitk::Image::Pointer relativImage = mitk::ImageGenerator::GenerateGradientImage(4,4,4,1); + std::string imagePath3 = mitk::IOUtil::CreateTemporaryFile(tmpStream, "XXXXXX.nrrd"); + tmpStream.close(); + mitk::IOUtil::SaveImage(relativImage, imagePath3); + CPPUNIT_ASSERT_NO_THROW(mitk::IOUtil::LoadImage(imagePath3)); + std::remove(imagePath3.c_str()); + } + + void TestLoadAndSavePointSet() + { + mitk::PointSet::Pointer pointset = mitk::IOUtil::LoadPointSet(testData); + CPPUNIT_ASSERT( pointset.IsNotNull()); + + std::ofstream tmpStream; + std::string pointSetPath = mitk::IOUtil::CreateTemporaryFile(tmpStream, "XXXXXX.mps"); + tmpStream.close(); + std::string pointSetPathWithDefaultExtension = mitk::IOUtil::CreateTemporaryFile(tmpStream, "XXXXXX.mps"); + tmpStream.close(); + std::string pointSetPathWithoutDefaultExtension = mitk::IOUtil::CreateTemporaryFile(tmpStream, "XXXXXX.xXx"); + tmpStream.close(); + + // the cases where no exception should be thrown + CPPUNIT_ASSERT(mitk::IOUtil::SavePointSet(pointset, pointSetPathWithDefaultExtension)); // test if defaultextension is inserted if no extension is present CPPUNIT_ASSERT(mitk::IOUtil::SavePointSet(pointset, pointSetPathWithoutDefaultExtension.c_str())); + //delete the files after the test is done + std::remove(pointSetPath.c_str()); + std::remove(pointSetPathWithDefaultExtension.c_str()); + std::remove(pointSetPathWithoutDefaultExtension.c_str()); + } + + void TestLoadAndSaveSurface() + { + mitk::Surface::Pointer surface = mitk::IOUtil::LoadSurface(testData); + CPPUNIT_ASSERT( surface.IsNotNull()); + + std::ofstream tmpStream; + std::string surfacePath = mitk::IOUtil::CreateTemporaryFile(tmpStream, "diffsurface-XXXXXX.stl"); + + // the cases where no exception should be thrown + CPPUNIT_ASSERT(mitk::IOUtil::SaveSurface(surface, surfacePath)); + // test if exception is thrown as expected on unknown extsension CPPUNIT_ASSERT_THROW(mitk::IOUtil::SaveSurface(surface,"testSurface.xXx"), mitk::Exception); - //load data which does not exist - CPPUNIT_ASSERT_THROW(mitk::IOUtil::LoadImage("fileWhichDoesNotExist.nrrd"), mitk::Exception); //delete the files after the test is done - remove(imagePath.c_str()); - remove(pointSetPath.c_str()); - remove(surfacePath.c_str()); - //remove the pointset with default extension and not the one without - remove(pointSetPathWithDefaultExtension.c_str()); - - mitk::Image::Pointer relativImage = mitk::ImageGenerator::GenerateGradientImage(4,4,4,1); - mitk::IOUtil::SaveImage(relativImage, "tempfile.nrrd"); - CPPUNIT_ASSERT_NO_THROW(mitk::IOUtil::LoadImage("tempfile.nrrd")); - remove("tempfile.nrrd"); + std::remove(surfacePath.c_str()); } + }; MITK_TEST_SUITE_REGISTRATION(mitkIOUtil) diff --git a/mitkTestingConfig.h.in b/mitkTestingConfig.h.in index 3a908f70f0..8e1c8ae108 100644 --- a/mitkTestingConfig.h.in +++ b/mitkTestingConfig.h.in @@ -1,18 +1,20 @@ /* mitkTestingConfig.h this file is generated. Do not change! */ #ifndef MITKTESTINGCONFIG_H #define MITKTESTINGCONFIG_H #cmakedefine BUILD_TESTING #cmakedefine MITK_FAST_TESTING #define MITK_TEST_OUTPUT_DIR "@MITK_TEST_OUTPUT_DIR@" #ifdef CMAKE_INTDIR #define MITK_RUNTIME_OUTPUT_DIR "@CMAKE_RUNTIME_OUTPUT_DIRECTORY@/" CMAKE_INTDIR #else #define MITK_RUNTIME_OUTPUT_DIR "@CMAKE_RUNTIME_OUTPUT_DIRECTORY@" #endif +#define MITK_DATA_DIR "@MITK_DATA_DIR@" + #endif // MITKTESTINGCONFIG_H