Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkPointSetReaderTest.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 "mitkFileReaderRegistry.h"
18 #include "mitkMimeType.h"
19 #include "mitkPointSet.h"
20 #include "mitkTestingMacros.h"
21 
30 int mitkPointSetReaderTest(int argc, char *argv[])
31 {
32  // always start with this!
33  MITK_TEST_BEGIN("PointSetReader")
34  MITK_TEST_CONDITION_REQUIRED(argc == 2, "Testing invocation")
35 
36  mitk::FileReaderRegistry readerRegistry;
37 
38  // Get PointSet reader(s)
39  std::vector<mitk::IFileReader *> readers =
41  MITK_TEST_CONDITION_REQUIRED(!readers.empty(), "Testing for registered readers")
42 
43  for (std::vector<mitk::IFileReader *>::const_iterator iter = readers.begin(), end = readers.end(); iter != end;
44  ++iter)
45  {
46  std::string testName = "test1";
47  mitk::IFileReader *reader = *iter;
48  reader->SetInput(testName);
49  // testing file reading with invalid data
51  "Testing confidence level with invalid input file name!");
52  CPPUNIT_ASSERT_THROW(reader->Read(), mitk::Exception);
53 
54  // testing file reading with valid data
55  std::string filePath = argv[1];
56  reader->SetInput(filePath);
58  "Testing confidence level with valid input file name!");
59  std::vector<mitk::BaseData::Pointer> data = reader->Read();
60  MITK_TEST_CONDITION_REQUIRED(!data.empty(), "Testing non-empty data with valid input file name!");
61 
62  // evaluate if the read point set is correct
63  mitk::PointSet::Pointer resultPS = dynamic_cast<mitk::PointSet *>(data.front().GetPointer());
64  MITK_TEST_CONDITION_REQUIRED(resultPS.IsNotNull(), "Testing correct BaseData type");
66  resultPS->GetTimeSteps() == 14,
67  "Testing output time step generation!"); // CAVE: Only valid with the specified test data!
69  resultPS->GetPointSet(resultPS->GetTimeSteps() - 1)->GetNumberOfPoints() == 0,
70  "Testing output time step generation with empty time step!"); // CAVE: Only valid with the specified test data!
71  }
72 
73  // always end with this!
75 }
virtual ConfidenceLevel GetConfidenceLevel() const =0
The confidence level of the reader or writer implementation.
std::vector< mitk::IFileReader * > GetReaders(const MimeType &mimeType, us::ModuleContext *context=us::GetModuleContext())
static MimeType GetMimeTypeForFile(const std::string &path, us::ModuleContext *context=us::GetModuleContext())
Get the highest ranked mime-type for the given file name.
#define MITK_TEST_CONDITION_REQUIRED(COND, MSG)
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
virtual std::vector< itk::SmartPointer< BaseData > > Read()=0
Reads the specified file or input stream and returns its contents.
virtual void SetInput(const std::string &location)=0
Set the input location.
Data structure which stores a set of points. Superclass of mitk::Mesh.
Definition: mitkPointSet.h:79
An object of this class represents an exception of MITK. Please don't instantiate exceptions manually...
Definition: mitkException.h:49
int mitkPointSetReaderTest(int argc, char *argv[])
The common interface for all MITK file readers.
and MITK_TEST_END()