#include "mitkUnstructuredGridVtkWriter.h"#include "mitkTestingMacros.h"#include "mitkUnstructuredGrid.h"#include <mitkVtkUnstructuredGridReader.h>#include <vtkUnstructuredGridWriter.h>#include <iostream>Go to the source code of this file.
Functions | |
| int | mitkUnstructuredGridVtkWriterTest (int argc, char *argv[]) |
| int mitkUnstructuredGridVtkWriterTest | ( | int | argc, |
| 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 36 of file mitkUnstructuredGridVtkWriterTest.cpp.
References EXIT_FAILURE, MITK_INFO, MITK_TEST_BEGIN, MITK_TEST_CONDITION_REQUIRED, MITK_TEST_END, MITK_TEST_FOR_EXCEPTION_BEGIN, MITK_TEST_FOR_EXCEPTION_END, mitk::VtkUnstructuredGridReader::New(), mitk::UnstructuredGridVtkWriter< VTKWRITER >::New(), mitk::UnstructuredGridVtkWriter< VTKWRITER >::SetFileName(), mitk::UnstructuredGridVtkWriter< VTKWRITER >::SetInput(), and mitk::UnstructuredGridVtkWriter< VTKWRITER >::Update().
{
// always start with this!
MITK_TEST_BEGIN("UnstructuredGridVtkWriter")
//let's create an object of our class
mitk::UnstructuredGridVtkWriter<vtkUnstructuredGridWriter>::Pointer myUnstructuredGridVtkWriter = mitk::UnstructuredGridVtkWriter<vtkUnstructuredGridWriter>::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(myUnstructuredGridVtkWriter.IsNotNull(),"Testing instantiation")
if (argc<1)
{
MITK_INFO<<"Command line argument missing";
return 0;
}
// create contour by reading the file given in argv[1]
mitk::UnstructuredGrid::Pointer unstructuredGrid;
mitk::VtkUnstructuredGridReader::Pointer reader = mitk::VtkUnstructuredGridReader::New();
try {
reader->SetFileName(argv[1]);
reader->Update();
unstructuredGrid = reader->GetOutput();
}
catch (itk::ExceptionObject e)
{
MITK_INFO<<e.GetDescription();
return 0;
}
try{
// test if exception is thrown when unstructured grid is tried to be saved in an non-existing/non-writable folder/file
MITK_TEST_FOR_EXCEPTION_BEGIN(itk::ExceptionObject)
myUnstructuredGridVtkWriter->SetInput(unstructuredGrid);
// set non-existing (windows), non-writable (linux) file name
myUnstructuredGridVtkWriter->SetFileName("/usr/bin");
myUnstructuredGridVtkWriter->Update();
MITK_TEST_FOR_EXCEPTION_END(itk::ExceptionObject)
}
catch(...) {
//this means that a wrong exception (i.e. no itk:Exception) has been thrown
MITK_INFO << "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!
MITK_TEST_END()
}
1.7.2