Medical Imaging Interaction Toolkit  2018.4.99-389bf124
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 (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 "mitkFileReaderRegistry.h"
14 #include "mitkMimeType.h"
15 #include "mitkPointSet.h"
16 #include "mitkTestingMacros.h"
17 
26 int mitkPointSetReaderTest(int argc, char *argv[])
27 {
28  // always start with this!
29  MITK_TEST_BEGIN("PointSetReader")
30  MITK_TEST_CONDITION_REQUIRED(argc == 2, "Testing invocation")
31 
32  mitk::FileReaderRegistry readerRegistry;
33 
34  // Get PointSet reader(s)
35  std::vector<mitk::IFileReader *> readers =
37  MITK_TEST_CONDITION_REQUIRED(!readers.empty(), "Testing for registered readers")
38 
39  for (std::vector<mitk::IFileReader *>::const_iterator iter = readers.begin(), end = readers.end(); iter != end;
40  ++iter)
41  {
42  std::string testName = "test1";
43  mitk::IFileReader *reader = *iter;
44  reader->SetInput(testName);
45  // testing file reading with invalid data
47  "Testing confidence level with invalid input file name!");
48  CPPUNIT_ASSERT_THROW(reader->Read(), mitk::Exception);
49 
50  // testing file reading with valid data
51  std::string filePath = argv[1];
52  reader->SetInput(filePath);
54  "Testing confidence level with valid input file name!");
55  std::vector<mitk::BaseData::Pointer> data = reader->Read();
56  MITK_TEST_CONDITION_REQUIRED(!data.empty(), "Testing non-empty data with valid input file name!");
57 
58  // evaluate if the read point set is correct
59  mitk::PointSet::Pointer resultPS = dynamic_cast<mitk::PointSet *>(data.front().GetPointer());
60  MITK_TEST_CONDITION_REQUIRED(resultPS.IsNotNull(), "Testing correct BaseData type");
62  resultPS->GetTimeSteps() == 14,
63  "Testing output time step generation!"); // CAVE: Only valid with the specified test data!
65  resultPS->GetPointSet(resultPS->GetTimeSteps() - 1)->GetNumberOfPoints() == 0,
66  "Testing output time step generation with empty time step!"); // CAVE: Only valid with the specified test data!
67  }
68 
69  // always end with this!
71 }
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:75
An object of this class represents an exception of MITK. Please don&#39;t instantiate exceptions manually...
Definition: mitkException.h:45
int mitkPointSetReaderTest(int argc, char *argv[])
The common interface for all MITK file readers.
and MITK_TEST_END()