Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkSurfaceVtkWriterTest.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #include "mitkIOUtil.h"
14 #include "mitkSurface.h"
15 #include "mitkTestingMacros.h"
16 
17 #include <vtkPolyDataReader.h>
18 #include <vtkPolyDataWriter.h>
19 
20 #include <iostream>
21 
30 int mitkSurfaceVtkWriterTest(int /*argc*/, char *argv[])
31 {
32  // always start with this!
33  MITK_TEST_BEGIN("SurfaceVtkWriter")
34 
35  // create contour
36  vtkPolyDataReader *reader = vtkPolyDataReader::New();
37  reader->SetFileName(argv[1]);
38  reader->Update();
39  if (reader->GetOutput())
40  {
42  surface->SetVtkPolyData(reader->GetOutput());
43  surface->Update();
44 
45  MITK_TEST_CONDITION_REQUIRED(surface.IsNotNull(), "Surface creation")
46 
47  try
48  {
49  // test for exception handling
50  mitk::IOUtil::Save(surface, "/usr/bin");
51  MITK_TEST_FAILED_MSG(<< "itk::ExceptionObject expected")
52  }
53  catch (const mitk::Exception &)
54  { /* this is expected */
55  }
56  catch (...)
57  {
58  // this means that a wrong exception (i.e. no itk:Exception) has been thrown
59  MITK_TEST_FAILED_MSG(<< "Wrong exception (i.e. no itk:Exception) caught during write [FAILED]")
60  }
61 
62  // write your own tests here and use the macros from mitkTestingMacros.h !!!
63  // do not write to std::cout and do not return from this function yourself!
64  }
65 
66  // Delete reader correctly
67  reader->Delete();
68 
69  // always end with this!
71 }
#define MITK_TEST_CONDITION_REQUIRED(COND, MSG)
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
An object of this class represents an exception of MITK. Please don&#39;t instantiate exceptions manually...
Definition: mitkException.h:45
#define MITK_TEST_FAILED_MSG(MSG)
Fail and finish test with message MSG.
int mitkSurfaceVtkWriterTest(int, char *argv[])
static void Save(const mitk::BaseData *data, const std::string &path, bool setPathProperty=false)
Save a mitk::BaseData instance.
Definition: mitkIOUtil.cpp:774
and MITK_TEST_END()
static Pointer New()