diff --git a/Core/Code/Testing/mitkImageTimeSelectorTest.cpp b/Core/Code/Testing/mitkImageTimeSelectorTest.cpp index e6e1464c66..265dc9a82d 100644 --- a/Core/Code/Testing/mitkImageTimeSelectorTest.cpp +++ b/Core/Code/Testing/mitkImageTimeSelectorTest.cpp @@ -1,119 +1,119 @@ /*=================================================================== 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 "mitkImage.h" #include "mitkDataNodeFactory.h" #include "mitkImageTimeSelector.h" #include "mitkImageGenerator.h" #include "mitkTestingMacros.h" #include "mitkIOUtil.h" #include #include /** Global members common for all subtests */ namespace { std::string m_Filename; mitk::Image::Pointer m_Image; } // end of anonymous namespace /** @brief Global test setup */ static void Setup( ) { try { m_Image = mitk::IOUtil::LoadImage( m_Filename ); } catch( const itk::ExceptionObject &e) { MITK_TEST_FAILED_MSG(<< "(Setup) Caught exception from IOUtil while loading input : " << m_Filename <<"\n" << e.what()) } } static void Valid_AllInputTimesteps_ReturnsTrue() { Setup(); mitk::ImageTimeSelector::Pointer timeSelector = mitk::ImageTimeSelector::New(); timeSelector->SetInput(m_Image); // test all timesteps const unsigned int maxTimeStep = m_Image->GetTimeSteps(); for( unsigned int t=0; tSetTimeNr(t); timeSelector->Update(); mitk::Image::Pointer currentTimestepImage = timeSelector->GetOutput(); std::stringstream ss; ss << " : Valid image in timestep " << t ; MITK_TEST_CONDITION_REQUIRED( currentTimestepImage.IsNotNull() , ss.str().c_str() ); } } static void Valid_ImageExpandedByTimestep_ReturnsTrue() { Setup(); mitk::ImageTimeSelector::Pointer timeSelector = mitk::ImageTimeSelector::New(); const unsigned int maxTimeStep = m_Image->GetTimeSteps(); mitk::TimeGeometry* tsg = m_Image->GetTimeGeometry(); mitk::ProportionalTimeGeometry* ptg = dynamic_cast(tsg); ptg->Expand(maxTimeStep+1); ptg->SetTimeStepGeometry( ptg->GetGeometryForTimeStep(0), maxTimeStep ); mitk::Image::Pointer expandedImage = mitk::Image::New(); expandedImage->Initialize( m_Image->GetPixelType(0), *tsg ); timeSelector->SetInput(expandedImage); for( unsigned int t=0; tSetTimeNr(t); timeSelector->Update(); mitk::Image::Pointer currentTimestepImage = timeSelector->GetOutput(); std::stringstream ss; ss << " : Valid image in timestep " << t ; MITK_TEST_CONDITION_REQUIRED( currentTimestepImage.IsNotNull() , ss.str().c_str() ); } } -int mitkImageTimeSelectorTest(int, char* []) +int mitkImageTimeSelectorTest(int argc, char* argv[]) { MITK_TEST_BEGIN(mitkImageTimeSelectorTest); m_Filename = std::string( argv[1] ); Valid_AllInputTimesteps_ReturnsTrue(); Valid_ImageExpandedByTimestep_ReturnsTrue(); MITK_TEST_END(); } diff --git a/Core/Code/Testing/mitkMultiComponentImageDataComparisonFilterTest.cpp b/Core/Code/Testing/mitkMultiComponentImageDataComparisonFilterTest.cpp index c64e14467e..77a3033270 100644 --- a/Core/Code/Testing/mitkMultiComponentImageDataComparisonFilterTest.cpp +++ b/Core/Code/Testing/mitkMultiComponentImageDataComparisonFilterTest.cpp @@ -1,81 +1,81 @@ /*=================================================================== 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. ===================================================================*/ // mitk includes #include "mitkTestingMacros.h" #include "mitkMultiComponentImageDataComparisonFilter.h" #include "mitkItkImageFileReader.h" #include "mitkImageReadAccessor.h" #include "itkNumericTraits.h" -int mitkMultiComponentImageDataComparisonFilterTest(int, char* []) +int mitkMultiComponentImageDataComparisonFilterTest(int argc, char* argv[]) { MITK_TEST_BEGIN("MultiComponentImageDataComparisonFilter"); // instantiation mitk::MultiComponentImageDataComparisonFilter::Pointer testObject = mitk::MultiComponentImageDataComparisonFilter::New(); MITK_TEST_CONDITION_REQUIRED(testObject.IsNotNull(), "Testing instantiation of test class!"); MITK_TEST_CONDITION_REQUIRED(testObject->GetCompareFilterResult() == NULL, "Testing initialization of result struct" ); MITK_TEST_CONDITION_REQUIRED(testObject->GetTolerance() == 0.0f, "Testing initialization of tolerance member"); MITK_TEST_CONDITION_REQUIRED(testObject->GetResult() == false, "Testing initialization of CompareResult member"); // initialize compare result struct and pass it to the filter mitk::CompareFilterResults compareResult; compareResult.m_MaximumDifference = 0.0f; compareResult.m_MinimumDifference = itk::NumericTraits::max(); compareResult.m_MeanDifference = 0.0f; compareResult.m_FilterCompleted = false; compareResult.m_TotalDifference = 0.0f; compareResult.m_PixelsWithDifference = 0; testObject->SetCompareFilterResult(&compareResult); MITK_TEST_CONDITION_REQUIRED(testObject->GetCompareFilterResult() != NULL, "Testing set/get of compare result struct" ); MITK_TEST_CONDITION_REQUIRED(testObject->GetResult() == false, "CompareResult still false" ); //now load an image with several components and present it to the filter mitk::ItkImageFileReader::Pointer imgReader = mitk::ItkImageFileReader::New(); imgReader->SetFileName(argv[1]); imgReader->Update(); mitk::Image::Pointer testImg = imgReader->GetOutput(); mitk::Image::Pointer testImg2 = testImg->Clone(); testObject->SetValidImage(testImg); testObject->SetTestImage(testImg2); MITK_TEST_CONDITION_REQUIRED(testObject->GetNumberOfIndexedInputs() == 2, "Testing correct handling of input images"); testObject->Update(); MITK_TEST_CONDITION_REQUIRED(testObject->GetResult(), "Testing filter processing with equal image data"); // now change some of the data and check if the response is correct mitk::ImageReadAccessor imgAcc(testImg2); unsigned char* imgData = (unsigned char*) imgAcc.GetData(); imgData[10] += 1; imgData[20] += 2; imgData[30] += 3; testObject->Update(); MITK_TEST_CONDITION_REQUIRED(testObject->GetResult() == false, "Testing filter processing with unequal image data"); MITK_TEST_CONDITION_REQUIRED(mitk::Equal((int)testObject->GetCompareFilterResult()->m_PixelsWithDifference, (int) 3) && mitk::Equal((double)testObject->GetCompareFilterResult()->m_MaximumDifference, (double) 3.0) && mitk::Equal((double)testObject->GetCompareFilterResult()->m_MeanDifference, (double) 2.0), "Assessing calculated image differences"); MITK_TEST_END(); } diff --git a/Core/Code/Testing/vtkMitkThickSlicesFilterTest.cpp b/Core/Code/Testing/vtkMitkThickSlicesFilterTest.cpp index 887b83592b..2f8b17e6c4 100644 --- a/Core/Code/Testing/vtkMitkThickSlicesFilterTest.cpp +++ b/Core/Code/Testing/vtkMitkThickSlicesFilterTest.cpp @@ -1,174 +1,174 @@ /*=================================================================== 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 "mitkImageWriteAccessor.h" #include "mitkImage.h" #include #include #include class vtkMitkThickSlicesFilterTestHelper { public: static mitk::Image::Pointer CreateTestImage( int min, int max ) { mitk::PixelType pixelType( mitk::MakeScalarPixelType() ); mitk::Image::Pointer testImage = mitk::Image::New(); unsigned int* dim = new unsigned int[3]; dim[0] = 10; dim[1] = 10; dim[2] = max+1-min; testImage->Initialize( pixelType, 3, dim ); size_t buffer_size = dim[0] * dim[1] * sizeof(unsigned char); for( int i=min; i<=max; ++i ) { mitk::ImageWriteAccessor writeAccess( testImage, testImage->GetSliceData( i-min ) ); memset( writeAccess.GetData(), i, buffer_size ); } return testImage; } static void EvaluateResult( unsigned char expectedValue, vtkImageData* image, const char* projection ) { MITK_TEST_CONDITION_REQUIRED( image->GetDimensions()[0] == 10 && image->GetDimensions()[1] == 10 && image->GetDimensions()[2] == 1, "Resulting image has correct size" ); unsigned char* value = static_cast( image->GetScalarPointer(0,0,0) ); MITK_INFO << "Evaluating projection mode: " << projection; MITK_INFO << "expected value: " << static_cast( expectedValue ); MITK_INFO << "actual value: " << static_cast( value[0] ); MITK_TEST_CONDITION_REQUIRED( value[0] == expectedValue, "Resulting image has correct pixel-value" ); } }; /** * Test for vtkMitkThickSlicesFilter. * */ -int vtkMitkThickSlicesFilterTest(int, char** ) +int vtkMitkThickSlicesFilterTest(int, char* []) { // always start with this! MITK_TEST_BEGIN("vtkMitkThickSlicesFilterTest") vtkMitkThickSlicesFilter* thickSliceFilter = vtkMitkThickSlicesFilter::New(); ////////////////////////////////////////////////////////////////////////// // Image looks like: // 000000000 // 111111111 // 222222222 mitk::Image::Pointer testImage1 = vtkMitkThickSlicesFilterTestHelper::CreateTestImage( 0, 2 ); thickSliceFilter->SetInputData( testImage1->GetVtkImageData() ); // MaxIP thickSliceFilter->SetThickSliceMode( 0 ); thickSliceFilter->Modified(); thickSliceFilter->Update(); vtkMitkThickSlicesFilterTestHelper::EvaluateResult( 2, thickSliceFilter->GetOutput(), "MaxIP" ); // Sum thickSliceFilter->SetThickSliceMode( 1 ); thickSliceFilter->Modified(); thickSliceFilter->Update(); vtkMitkThickSlicesFilterTestHelper::EvaluateResult( 1, thickSliceFilter->GetOutput(), "Sum" ); // Weighted thickSliceFilter->SetThickSliceMode( 2 ); thickSliceFilter->Modified(); thickSliceFilter->Update(); vtkMitkThickSlicesFilterTestHelper::EvaluateResult( 1, thickSliceFilter->GetOutput(), "Weighted" ); // MinIP thickSliceFilter->SetThickSliceMode( 3 ); thickSliceFilter->Modified(); thickSliceFilter->Update(); vtkMitkThickSlicesFilterTestHelper::EvaluateResult( 0, thickSliceFilter->GetOutput(), "MinIP" ); // Mean thickSliceFilter->SetThickSliceMode( 4 ); thickSliceFilter->Modified(); thickSliceFilter->Update(); vtkMitkThickSlicesFilterTestHelper::EvaluateResult( 1, thickSliceFilter->GetOutput(), "Mean" ); ////////////////////////////////////////////////////////////////////////// // Image looks like: // 333333333 // 444444444 // 555555555 // 666666666 // 777777777 // 888888888 mitk::Image::Pointer testImage2 = vtkMitkThickSlicesFilterTestHelper::CreateTestImage( 3, 8 ); thickSliceFilter->SetInputData( testImage2->GetVtkImageData() ); // MaxIP thickSliceFilter->SetThickSliceMode( 0 ); thickSliceFilter->Modified(); thickSliceFilter->Update(); vtkMitkThickSlicesFilterTestHelper::EvaluateResult( 8, thickSliceFilter->GetOutput(), "MaxIP" ); // Sum thickSliceFilter->SetThickSliceMode( 1 ); thickSliceFilter->Modified(); thickSliceFilter->Update(); vtkMitkThickSlicesFilterTestHelper::EvaluateResult( 5, thickSliceFilter->GetOutput(), "Sum" ); // Weighted thickSliceFilter->SetThickSliceMode( 2 ); thickSliceFilter->Modified(); thickSliceFilter->Update(); vtkMitkThickSlicesFilterTestHelper::EvaluateResult( 4, thickSliceFilter->GetOutput(), "Weighted" ); // MinIP thickSliceFilter->SetThickSliceMode( 3 ); thickSliceFilter->Modified(); thickSliceFilter->Update(); vtkMitkThickSlicesFilterTestHelper::EvaluateResult( 3, thickSliceFilter->GetOutput(), "MinIP" ); // Mean thickSliceFilter->SetThickSliceMode( 4 ); thickSliceFilter->Modified(); thickSliceFilter->Update(); vtkMitkThickSlicesFilterTestHelper::EvaluateResult( 6, thickSliceFilter->GetOutput(), "Mean" ); thickSliceFilter->Delete(); MITK_TEST_END() } diff --git a/Core/Code/TestingHelper/mitkTestingMacros.h b/Core/Code/TestingHelper/mitkTestingMacros.h index 855d3787d0..02edc5fe47 100644 --- a/Core/Code/TestingHelper/mitkTestingMacros.h +++ b/Core/Code/TestingHelper/mitkTestingMacros.h @@ -1,386 +1,386 @@ /*=================================================================== 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 mitkTestingMacros_h #define mitkTestingMacros_h #include #include #include #include #include #include #include #include #include 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 instead. * @ingroup MITKTestingAPI */ #define MITK_TEST_END() \ - } catch (const mitk::TestFailedException& ex) { \ + } catch (const mitk::TestFailedException&) { \ MITK_TEST_OUTPUT(<< "Further test execution skipped.") \ mitk::TestManager::GetInstance()->TestFailed(); \ } catch (const 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. * @throw Throws mitkException if a NULL pointer is given as input. */ #define MITK_ASSERT_EQUAL(EXPECTED, ACTUAL, MSG) \ if(((EXPECTED).IsNull()) || ((ACTUAL).IsNull())) { \ mitkThrow() << "mitk::Equal does not work with NULL pointer input."; \ } \ 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) \ CPPUNIT_ASSERT_MESSAGE(MSG, !mitk::Equal(*(OBJ1), *(OBJ2), 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. * * @param OBJ1 First object. * @param OBJ2 Second object. * @param MSG Message to appear with the test. * @throw Throws mitkException if a NULL pointer is given as input. * * \sa MITK_ASSERT_EQUAL */ #define MITK_ASSERT_NOT_EQUAL(OBJ1, OBJ2, MSG) \ if(((OBJ1).IsNull()) || ((OBJ2).IsNull())) { \ mitkThrow() << "mitk::Equal does not work with NULL pointer input."; \ } \ 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()); \ return runner.run() ? 0 : 1; \ } /** * @brief Adds a test to the current test suite. * * @ingroup MITKTestingAPI * * Use this macro after the CPPUNIT_TEST_SUITE() macro to add test cases. * The macro internally just calls the CPPUNIT_TEST macro. * * @param TESTMETHOD The name of the member funtion test. */ #define MITK_TEST(TESTMETHOD) CPPUNIT_TEST(TESTMETHOD) /** * @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 custom parameters. * * @param TESTMETHOD The name of the member function test. * @param ARGS A std::vector object containing test parameter. * * @note Use the macro MITK_PARAMETERIZED_TEST only if you know what * you are doing. If you are not sure, use MITK_TEST instead. */ #define MITK_PARAMETERIZED_TEST(TESTMETHOD, ARGS) \ { \ std::string testName = #TESTMETHOD; \ for (std::size_t i = 0; i < ARGS.size(); ++i) \ { \ testName += "_" + ARGS[i]; \ } \ CPPUNIT_TEST_SUITE_ADD_TEST( \ ( new mitk::TestCaller( \ context.getTestNameFor(testName), \ &TestFixtureType::TESTMETHOD, \ context.makeFixture(), args ) ) ); \ } /** * @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 from the command line. * * @warning Use the macro MITK_PARAMETERIZED_CMD_LINE_TEST only * if you know what you are doing. If you are not sure, use * MITK_TEST instead. MITK_PARAMETERIZED_CMD_LINE_TEST is meant * for migrating from ctest to CppUnit. If you implement new * tests, the MITK_TEST macro will be sufficient. * * @param TESTMETHOD The name of the member function test. */ #define MITK_PARAMETERIZED_CMD_LINE_TEST(TESTMETHOD) \ CPPUNIT_TEST_SUITE_ADD_TEST( \ ( new mitk::TestCaller( \ context.getTestNameFor( #TESTMETHOD), \ &TestFixtureType::TESTMETHOD, \ 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. * * @note Use the macro MITK_PARAMETERIZED_TEST_1 only if you know what * you are doing. If you are not sure, use MITK_TEST instead. * * @see MITK_PARAMETERIZED_TEST */ #define MITK_PARAMETERIZED_TEST_1(TESTMETHOD, arg1) \ { \ std::vector args; \ args.push_back(arg1); \ MITK_PARAMETERIZED_TEST(TESTMETHOD, args) \ } /** * @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 two custom parameter. * * @param TESTMETHOD The name of the member function test. * @param arg1 A custom string parameter being passed to the fixture. * * @note Use the macro MITK_PARAMETERIZED_TEST_2 only if you know what * you are doing. If you are not sure, use MITK_TEST instead. * * @see MITK_PARAMETERIZED_TEST */ #define MITK_PARAMETERIZED_TEST_2(TESTMETHOD, arg1, arg2) \ { \ std::vector args; \ args.push_back(arg1); \ args.push_back(arg2); \ MITK_PARAMETERIZED_TEST(TESTMETHOD, args) \ } #endif