Functions

mitkSurfaceVtkWriterTest.cpp File Reference

#include "mitkSurfaceVtkWriter.h"
#include "mitkTestingMacros.h"
#include <vtkPolyDataReader.h>
#include <vtkPolyDataWriter.h>
#include <iostream>

Go to the source code of this file.

Functions

int mitkSurfaceVtkWriterTest (int, char *argv[])

Function Documentation

int mitkSurfaceVtkWriterTest ( int  ,
char *  argv[] 
)

Simple example for a test for the (non-existent) class "ClassName".

argc and argv are the command line parameters which were passed to the ADD_TEST command in the CMakeLists.txt file. For the automatic tests, argv is either empty for the simple tests or contains the filename of a test image for the image tests (see CMakeLists.txt).

Definition at line 35 of file mitkSurfaceVtkWriterTest.cpp.

References EXIT_FAILURE, MITK_TEST_BEGIN, MITK_TEST_CONDITION_REQUIRED, MITK_TEST_END, MITK_TEST_FOR_EXCEPTION_BEGIN, MITK_TEST_FOR_EXCEPTION_END, mitk::Surface::New(), mitk::SurfaceVtkWriter< VTKWRITER >::New(), mitk::SurfaceVtkWriter< VTKWRITER >::SetFileName(), mitk::SurfaceVtkWriter< VTKWRITER >::SetInput(), and mitk::SurfaceVtkWriter< VTKWRITER >::Update().

{
  // always start with this!
  MITK_TEST_BEGIN("SurfaceVtkWriter")

  // let's create an object of our class  
  mitk::SurfaceVtkWriter<vtkPolyDataWriter>::Pointer mySurfaceVtkWriter = mitk::SurfaceVtkWriter<vtkPolyDataWriter>::New();

  // first test: did this work?
  // using MITK_TEST_CONDITION_REQUIRED makes the test stop after failure, since
  // it makes no sense to continue without an object.
  MITK_TEST_CONDITION_REQUIRED(mySurfaceVtkWriter.IsNotNull(),"Testing instantiation") 

  // create contour
  vtkPolyDataReader* reader = vtkPolyDataReader::New();
  reader->SetFileName(argv[1]);
  reader->Update();
  if (reader->GetOutput())
  {
    mitk::Surface::Pointer surface = mitk::Surface::New();
    surface->SetVtkPolyData(reader->GetOutput());
    surface->Update();

    MITK_TEST_CONDITION_REQUIRED(surface.IsNotNull(),"Surface creation")

      try{  
        // test for exception handling
        MITK_TEST_FOR_EXCEPTION_BEGIN(itk::ExceptionObject)
        mySurfaceVtkWriter->SetInput(surface);
        mySurfaceVtkWriter->SetFileName("/usr/bin");
        mySurfaceVtkWriter->Update(); 
        MITK_TEST_FOR_EXCEPTION_END(itk::ExceptionObject)
    }
    catch(...) {
      //this means that a wrong exception (i.e. no itk:Exception) has been thrown 
      std::cout << "Wrong exception (i.e. no itk:Exception) caught during write [FAILED]" << std::endl;
      return EXIT_FAILURE;
    }

    // write your own tests here and use the macros from mitkTestingMacros.h !!!
    // do not write to std::cout and do not return from this function yourself!

    // always end with this!
  }

  //Delete reader correctly
  reader->Delete();

  MITK_TEST_END()

}
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines