Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
mitkSceneIOTest2.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 "mitkException.h"
18 #include "mitkTestFixture.h"
19 #include "mitkTestingMacros.h"
20 
21 #include "mitkDataStorageCompare.h"
22 #include "mitkIOUtil.h"
23 #include "mitkSceneIO.h"
25 
80 class mitkSceneIOTest2Suite : public mitk::TestFixture
81 {
82  CPPUNIT_TEST_SUITE(mitkSceneIOTest2Suite);
83  MITK_TEST(Test_SceneIOInterfaces);
84  MITK_TEST(Test_ReconstructionOfScenes);
85  CPPUNIT_TEST_SUITE_END();
86 
87  mitk::SceneIOTestScenarioProvider m_TestCaseProvider;
88 
89 public:
90  void Test_SceneIOInterfaces() { CPPUNIT_ASSERT_MESSAGE("Not urgent", true); }
91  void Test_ReconstructionOfScenes()
92  {
93  std::string tempDir = mitk::IOUtil::CreateTemporaryDirectory("SceneIOTest_XXXXXX");
94 
96  MITK_TEST_OUTPUT(<< "Executing " << scenarios.size() << " test scenarios");
97  for (auto scenario : scenarios)
98  {
99  MITK_TEST_OUTPUT(<< "\n===== Test_ReconstructionOfScenes, scenario '" << scenario.key << "' =====");
100 
101  std::string archiveFilename = mitk::IOUtil::CreateTemporaryFile("scene_XXXXXX.mitk", tempDir);
103  mitk::DataStorage::Pointer originalStorage = scenario.BuildDataStorage();
104  CPPUNIT_ASSERT_MESSAGE(
105  std::string("Save test scenario '") + scenario.key + "' to '" + archiveFilename + "'",
106  scenario.serializable == writer->SaveScene(originalStorage->GetAll(), originalStorage, archiveFilename));
107 
108  if (scenario.serializable)
109  {
111  mitk::DataStorage::Pointer restoredStorage;
112  CPPUNIT_ASSERT_NO_THROW(restoredStorage = reader->LoadScene(archiveFilename));
113  CPPUNIT_ASSERT_MESSAGE(
114  std::string("Comparing restored test scenario '") + scenario.key + "'",
115  mitk::DataStorageCompare(originalStorage,
116  restoredStorage,
117  // TODO make those flags part of the scenario object
118  // TODO make known/expected failures also part of the
119  // scenario object (but this needs a way to describe them, first)
122  // mappers tested although SceneIO leaves default mappers
124  // mitk::DataStorageCompare::CMP_Interactors
125  // interactors skipped for now
126  scenario.comparisonPrecision)
127  .CompareVerbose());
128  }
129  }
130  }
131 
132 }; // class
133 
134 int mitkSceneIOTest2(int /*argc*/, char * /*argv*/ [])
135 {
136  CppUnit::TextUi::TestRunner runner;
137  runner.addTest(mitkSceneIOTest2Suite::suite());
138  return runner.run() ? 0 : 1;
139 }
itk::SmartPointer< Self > Pointer
bool CompareVerbose()
Shorthand for Compare(true).
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
static Pointer New()
#define MITK_TEST_OUTPUT(x)
Output some text.
int mitkSceneIOTest2(int, char *[])
Test fixture for parameterized tests.
static std::string CreateTemporaryDirectory(const std::string &templateName="XXXXXX", std::string path=std::string())
Definition: mitkIOUtil.cpp:452
static std::string CreateTemporaryFile(std::ofstream &tmpStream, const std::string &templateName="XXXXXX", std::string path=std::string())
Definition: mitkIOUtil.cpp:407
Provides DataStorages that serve as test scenarios.
std::vector< Scenario > ScenarioList
List of Scenarios.
ScenarioList GetAllScenarios() const
Returns all registered scenarios.