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 https://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 "mitkUnstructuredGridVtkWriter.h" 00019 00020 #include "mitkTestingMacros.h" 00021 #include "mitkUnstructuredGrid.h" 00022 00023 #include <mitkVtkUnstructuredGridReader.h> 00024 #include <vtkUnstructuredGridWriter.h> 00025 00026 #include <iostream> 00027 00036 int mitkUnstructuredGridVtkWriterTest(int argc , char* argv[]) 00037 { 00038 // always start with this! 00039 MITK_TEST_BEGIN("UnstructuredGridVtkWriter") 00040 00041 //let's create an object of our class 00042 mitk::UnstructuredGridVtkWriter<vtkUnstructuredGridWriter>::Pointer myUnstructuredGridVtkWriter = mitk::UnstructuredGridVtkWriter<vtkUnstructuredGridWriter>::New(); 00043 00044 // first test: did this work? 00045 // using MITK_TEST_CONDITION_REQUIRED makes the test stop after failure, since 00046 // it makes no sense to continue without an object. 00047 MITK_TEST_CONDITION_REQUIRED(myUnstructuredGridVtkWriter.IsNotNull(),"Testing instantiation") 00048 00049 if (argc<1) 00050 { 00051 MITK_INFO<<"Command line argument missing"; 00052 return 0; 00053 } 00054 // create contour by reading the file given in argv[1] 00055 mitk::UnstructuredGrid::Pointer unstructuredGrid; 00056 mitk::VtkUnstructuredGridReader::Pointer reader = mitk::VtkUnstructuredGridReader::New(); 00057 00058 try { 00059 reader->SetFileName(argv[1]); 00060 reader->Update(); 00061 unstructuredGrid = reader->GetOutput(); 00062 } 00063 catch (itk::ExceptionObject e) 00064 { 00065 MITK_INFO<<e.GetDescription(); 00066 return 0; 00067 } 00068 00069 try{ 00070 // test if exception is thrown when unstructured grid is tried to be saved in an non-existing/non-writable folder/file 00071 MITK_TEST_FOR_EXCEPTION_BEGIN(itk::ExceptionObject) 00072 myUnstructuredGridVtkWriter->SetInput(unstructuredGrid); 00073 // set non-existing (windows), non-writable (linux) file name 00074 myUnstructuredGridVtkWriter->SetFileName("/usr/bin"); 00075 myUnstructuredGridVtkWriter->Update(); 00076 MITK_TEST_FOR_EXCEPTION_END(itk::ExceptionObject) 00077 } 00078 catch(...) { 00079 //this means that a wrong exception (i.e. no itk:Exception) has been thrown 00080 MITK_INFO << "Wrong exception (i.e. no itk:Exception) caught during write [FAILED]" << std::endl; 00081 return EXIT_FAILURE; 00082 } 00083 00084 //write your own tests here and use the macros from mitkTestingMacros.h !!! 00085 //do not write to std::cout and do not return from this function yourself! 00086 00087 //always end with this! 00088 MITK_TEST_END() 00089 } 00090