Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkDICOMReaderConfiguratorTest.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 
15 
16 #include "mitkTestingMacros.h"
17 
21 int mitkDICOMReaderConfiguratorTest(int /*argc*/, char* /*argv*/[])
22 {
23  MITK_TEST_BEGIN("mitkDICOMReaderConfiguratorTest");
24 
25  mitk::DICOMFileReaderSelector::Pointer readerSource = mitk::DICOMFileReaderSelector::New();
26  readerSource->LoadBuiltIn3DConfigs();
27  readerSource->LoadBuiltIn3DnTConfigs();
28 
29  mitk::DICOMFileReaderSelector::ReaderList allReaders = readerSource->GetAllConfiguredReaders(); // this already parses XML config for this reader
30  for (auto rIter = allReaders.begin();
31  rIter != allReaders.end();
32  ++rIter)
33  {
34  mitk::DICOMFileReader::Pointer originalReader = *rIter;
35 
36  MITK_TEST_OUTPUT(<< "********************************************************************************");
37  MITK_TEST_OUTPUT(<< "Testing reader '" << originalReader->GetConfigurationLabel() << "'" );
38  MITK_TEST_OUTPUT(<< "********************************************************************************");
39  // ask for an XML serialization of this reader, then compare the XML files.
40  mitk::DICOMReaderConfigurator::Pointer serializer = mitk::DICOMReaderConfigurator::New();
41  std::string xmlSerialization = serializer->CreateConfigStringFromReader( originalReader.GetPointer() );
42  MITK_TEST_CONDITION( !xmlSerialization.empty(), "DICOMReaderConfigurator is able to serialize reader");
43  MITK_INFO << "Got serialization:";
44  std::cout << xmlSerialization << std::endl;
45 
46  mitk::DICOMReaderConfigurator::Pointer creator = mitk::DICOMReaderConfigurator::New();
47  try
48  {
49  mitk::DICOMFileReader::Pointer reconstructedReader = creator->CreateFromUTF8ConfigString(xmlSerialization);
50  MITK_TEST_CONDITION( reconstructedReader.IsNotNull(), "DICOMReaderConfigurator is able to create reader from XML");
51 
52  MITK_TEST_CONDITION( *reconstructedReader == *originalReader, "Readers are equal before and after serialization" )
53  }
54  catch(std::exception& e)
55  {
56  MITK_TEST_CONDITION_REQUIRED(false, "Exception from DICOMReaderConfigurator: " << e.what());
57  }
58  }
59 
60  MITK_TEST_END();
61 }
62 
#define MITK_INFO
Definition: mitkLogMacros.h:18
#define MITK_TEST_CONDITION_REQUIRED(COND, MSG)
std::list< DICOMFileReader::Pointer > ReaderList
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
int mitkDICOMReaderConfiguratorTest(int, char *[])
Verify serialization ability of DICOMReaderConfigurator.
#define MITK_TEST_OUTPUT(x)
Output some text.
#define MITK_TEST_CONDITION(COND, MSG)
and MITK_TEST_END()