diff --git a/Core/Code/Testing/mitkImageTimeSelectorTest.cpp b/Core/Code/Testing/mitkImageTimeSelectorTest.cpp index 55bbdefde8..249c9a3514 100644 --- a/Core/Code/Testing/mitkImageTimeSelectorTest.cpp +++ b/Core/Code/Testing/mitkImageTimeSelectorTest.cpp @@ -1,90 +1,120 @@ /*=================================================================== 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 "mitkTesting.h" +#include "mitkTestingMacros.h" + +#include "mitkIOUtil.h" #include #include -int mitkImageTimeSelectorTest(int argc, char* argv[]) + + +/** Global members common for all subtests */ +namespace { + std::string m_Filename; + mitk::Image::Pointer m_Image; +} // end of anonymous namespace - std::cout << "Loading file: "; - if(argc==0) - { - std::cout<<"no file specified [FAILED]"<SetFileName( argv[1] ); - factory->Update(); - - if(factory->GetNumberOfOutputs()<1) - { - std::cout<<"file could not be loaded [FAILED]"<GetOutput( 0 ); - image = dynamic_cast(node->GetData()); - if(image.IsNull()) - { - std::cout<<"file not an image - test will not be applied [PASSED]"<SetInput(image); - timeSelector->SetTimeNr( 0 ); - timeSelector->UpdateLargestPossibleRegion(); - mitk::Image::Pointer result = timeSelector->GetOutput(); + timeSelector->SetInput(m_Image); - std::cout << "Testing IsInitialized(): "; - if(result->IsInitialized()==false) + // 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() ); } - std::cout<<"[PASSED]"<DisconnectPipeline(); - //timeSelector = NULL; - if( result->IsVolumeSet(0) == false) +} + +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() ); } - std::cout<<"[PASSED]"<