Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkPointSetWriterTest.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 "mitkPointSet.h"
14 
15 #include "mitkFileWriterSelector.h"
16 #include "mitkTestingMacros.h"
17 
18 #include <iostream>
19 #include <ctime>
20 
29 int mitkPointSetWriterTest(int /* argc */, char * /*argv*/ [])
30 {
31  // always start with this!
32  MITK_TEST_BEGIN("PointSetWriter")
33 
34  // create pointSet
35  srand(time(nullptr));
37  int numberOfPoints = rand() % 100;
38  for (int i = 0; i <= numberOfPoints + 1; i++)
39  {
40  mitk::Point3D point;
41  point[0] = rand() % 1000;
42  point[1] = rand() % 1000;
43  point[2] = rand() % 1000;
44  pointSet->SetPoint(i, point);
45  }
46 
47  MITK_TEST_CONDITION_REQUIRED(pointSet.IsNotNull(), "PointSet creation")
48 
49  // Get PointSet writer(s)
50  mitk::FileWriterSelector writerSelector(pointSet.GetPointer());
51  std::vector<mitk::FileWriterSelector::Item> writers = writerSelector.Get();
52  MITK_TEST_CONDITION_REQUIRED(!writers.empty(), "Testing for registered writers")
53 
54  for (std::vector<mitk::FileWriterSelector::Item>::const_iterator iter = writers.begin(), end = writers.end();
55  iter != end;
56  ++iter)
57  {
58  // test for exception handling
59  try
60  {
61  mitk::IFileWriter *writer = iter->GetWriter();
62  writer->SetInput(pointSet);
63  writer->SetOutputLocation("/usr/bin");
64  iter->GetWriter()->Write();
65  MITK_TEST_FAILED_MSG(<< "itk::ExceptionObject expected")
66  }
67  catch (const itk::ExceptionObject &)
68  { /* this is expected */
69  }
70  catch (...)
71  {
72  // this means that a wrong exception (i.e. no itk:Exception) has been thrown
73  MITK_TEST_FAILED_MSG(<< "Wrong exception (i.e. no itk:Exception) caught during write [FAILED]")
74  }
75  }
76 
77  // always end with this!
79 }
std::vector< Item > Get(const std::string &mimeType) const
Get a sorted list of file writer info objects.
static Pointer New()
#define MITK_TEST_CONDITION_REQUIRED(COND, MSG)
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
virtual void SetOutputLocation(const std::string &location)=0
Set the output location.
#define MITK_TEST_FAILED_MSG(MSG)
Fail and finish test with message MSG.
virtual void SetInput(const BaseData *data)=0
Set the input data for writing.
and MITK_TEST_END()
The common interface of all MITK file writers.
int mitkPointSetWriterTest(int, char *[])