00001 /*========================================================================= 00002 00003 Program: Medical Imaging & Interaction Toolkit 00004 Language: C++ 00005 Date: $Date$ 00006 Version: $Revision: 7837 $ 00007 00008 Copyright (c) German Cancer Research Center, Division of Medical and 00009 Biological Informatics. All rights reserved. 00010 See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. 00011 00012 This software is distributed WITHOUT ANY WARRANTY; without even 00013 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00014 PURPOSE. See the above copyright notices for more information. 00015 00016 =========================================================================*/ 00017 00018 #include "mitkSurfaceVtkWriter.h" 00019 00020 #include "mitkTestingMacros.h" 00021 00022 #include <vtkPolyDataReader.h> 00023 #include <vtkPolyDataWriter.h> 00024 00025 #include <iostream> 00026 00035 int mitkSurfaceVtkWriterTest(int /*argc*/ , char* argv[]) 00036 { 00037 // always start with this! 00038 MITK_TEST_BEGIN("SurfaceVtkWriter") 00039 00040 // let's create an object of our class 00041 mitk::SurfaceVtkWriter<vtkPolyDataWriter>::Pointer mySurfaceVtkWriter = mitk::SurfaceVtkWriter<vtkPolyDataWriter>::New(); 00042 00043 // first test: did this work? 00044 // using MITK_TEST_CONDITION_REQUIRED makes the test stop after failure, since 00045 // it makes no sense to continue without an object. 00046 MITK_TEST_CONDITION_REQUIRED(mySurfaceVtkWriter.IsNotNull(),"Testing instantiation") 00047 00048 // create contour 00049 vtkPolyDataReader* reader = vtkPolyDataReader::New(); 00050 reader->SetFileName(argv[1]); 00051 reader->Update(); 00052 if (reader->GetOutput()) 00053 { 00054 mitk::Surface::Pointer surface = mitk::Surface::New(); 00055 surface->SetVtkPolyData(reader->GetOutput()); 00056 surface->Update(); 00057 00058 MITK_TEST_CONDITION_REQUIRED(surface.IsNotNull(),"Surface creation") 00059 00060 try{ 00061 // test for exception handling 00062 MITK_TEST_FOR_EXCEPTION_BEGIN(itk::ExceptionObject) 00063 mySurfaceVtkWriter->SetInput(surface); 00064 mySurfaceVtkWriter->SetFileName("/usr/bin"); 00065 mySurfaceVtkWriter->Update(); 00066 MITK_TEST_FOR_EXCEPTION_END(itk::ExceptionObject) 00067 } 00068 catch(...) { 00069 //this means that a wrong exception (i.e. no itk:Exception) has been thrown 00070 std::cout << "Wrong exception (i.e. no itk:Exception) caught during write [FAILED]" << std::endl; 00071 return EXIT_FAILURE; 00072 } 00073 00074 // write your own tests here and use the macros from mitkTestingMacros.h !!! 00075 // do not write to std::cout and do not return from this function yourself! 00076 00077 // always end with this! 00078 } 00079 00080 //Delete reader correctly 00081 reader->Delete(); 00082 00083 MITK_TEST_END() 00084 00085 } 00086