Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "mitkPicFileWriter.h"
00019 #include "mitkDataNodeFactory.h"
00020 #include "mitkTestingMacros.h"
00021
00030 int mitkPicFileWriterTest(int argc , char* argv[])
00031 {
00032
00033 MITK_TEST_BEGIN("PicFileWriter")
00034
00035
00036 mitk::PicFileWriter::Pointer myPicFileWriter = mitk::PicFileWriter::New();
00037
00038
00039
00040
00041 MITK_TEST_CONDITION_REQUIRED(myPicFileWriter.IsNotNull(),"Testing instantiation")
00042
00043
00044 std::cout << "Loading file: " << std::flush;
00045 if(argc==0)
00046 {
00047 std::cout<<"no file specified [FAILED]"<<std::endl;
00048 return EXIT_FAILURE;
00049 }
00050 mitk::Image::Pointer image = NULL;
00051
00052 try{
00053
00054 std::cout << "Testing handling of NULL image " << std::flush;
00055 MITK_TEST_FOR_EXCEPTION_BEGIN(itk::ExceptionObject)
00056
00057 myPicFileWriter->SetInput(image);
00058 myPicFileWriter->SetFileName("/usr/bin");
00059 myPicFileWriter->Update();
00060 MITK_TEST_FOR_EXCEPTION_END(itk::ExceptionObject)
00061 }
00062 catch(...) {
00063 std::cout << "Success: Writer warns on NULL image." << std::endl;
00064 }
00065
00066 mitk::DataNodeFactory::Pointer factory = mitk::DataNodeFactory::New();
00067 try
00068 {
00069 std::cout<<argv[1]<<std::endl;
00070 factory->SetFileName( argv[1] );
00071 factory->Update();
00072
00073 if(factory->GetNumberOfOutputs()<1)
00074 {
00075 std::cout<<"file could not be loaded [FAILED]"<<std::endl;
00076 return EXIT_FAILURE;
00077 }
00078 mitk::DataNode::Pointer node = factory->GetOutput( 0 );
00079 image = dynamic_cast<mitk::Image*>(node->GetData());
00080 if(image.IsNull())
00081 {
00082 std::cout<<"file "<< argv[1]<< "is not an image - test will not be applied [PASSED]"<<std::endl;
00083 std::cout<<"[TEST DONE]"<<std::endl;
00084 return EXIT_SUCCESS;
00085 }
00086 }
00087 catch ( itk::ExceptionObject & ex )
00088 {
00089 std::cout << "Exception: " << ex << "[FAILED]" << std::endl;
00090 return EXIT_FAILURE;
00091 }
00092
00093 MITK_TEST_CONDITION_REQUIRED(image.IsNotNull(),"loaded image not NULL")
00094
00095 try{
00096
00097 MITK_TEST_FOR_EXCEPTION_BEGIN(itk::ExceptionObject)
00098
00099 myPicFileWriter->SetInput(image);
00100 myPicFileWriter->SetFileName("/usr/bin");
00101 myPicFileWriter->Update();
00102 MITK_TEST_FOR_EXCEPTION_END(itk::ExceptionObject)
00103 }
00104 catch(...) {
00105
00106 std::cout << "Wrong exception (i.e. no itk:Exception) caught during write [FAILED]" << std::endl;
00107 return EXIT_FAILURE;
00108 }
00109
00110
00111 MITK_TEST_END()
00112 }
00113