Medical Imaging Interaction Toolkit  2016.11.0
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #include "mitkPointSet.h"
18 
19 #include "mitkFileWriterSelector.h"
20 #include "mitkTestingMacros.h"
21 
22 #include <iostream>
23 #include <time.h>
24 
33 int mitkPointSetWriterTest(int /* argc */, char * /*argv*/ [])
34 {
35  // always start with this!
36  MITK_TEST_BEGIN("PointSetWriter")
37 
38  // create pointSet
39  srand(time(NULL));
41  int numberOfPoints = rand() % 100;
42  for (int i = 0; i <= numberOfPoints + 1; i++)
43  {
44  mitk::Point3D point;
45  point[0] = rand() % 1000;
46  point[1] = rand() % 1000;
47  point[2] = rand() % 1000;
48  pointSet->SetPoint(i, point);
49  }
50 
51  MITK_TEST_CONDITION_REQUIRED(pointSet.IsNotNull(), "PointSet creation")
52 
53  // Get PointSet writer(s)
54  mitk::FileWriterSelector writerSelector(pointSet.GetPointer());
55  std::vector<mitk::FileWriterSelector::Item> writers = writerSelector.Get();
56  MITK_TEST_CONDITION_REQUIRED(!writers.empty(), "Testing for registered writers")
57 
58  for (std::vector<mitk::FileWriterSelector::Item>::const_iterator iter = writers.begin(), end = writers.end();
59  iter != end;
60  ++iter)
61  {
62  // test for exception handling
63  try
64  {
65  mitk::IFileWriter *writer = iter->GetWriter();
66  writer->SetInput(pointSet);
67  writer->SetOutputLocation("/usr/bin");
68  iter->GetWriter()->Write();
69  MITK_TEST_FAILED_MSG(<< "itk::ExceptionObject expected")
70  }
71  catch (const itk::ExceptionObject &)
72  { /* this is expected */
73  }
74  catch (...)
75  {
76  // this means that a wrong exception (i.e. no itk:Exception) has been thrown
77  MITK_TEST_FAILED_MSG(<< "Wrong exception (i.e. no itk:Exception) caught during write [FAILED]")
78  }
79  }
80 
81  // always end with this!
83 }
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.
std::vector< Item > Get(const std::string &mimeType) const
Get a sorted list of file writer info objects.
#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 *[])