Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
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 (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 "mitkException.h"
14 #include "mitkTestFixture.h"
15 #include "mitkTestingMacros.h"
16 
17 #include "mitkDataStorageCompare.h"
18 #include "mitkIOUtil.h"
19 #include "mitkSceneIO.h"
21 
76 class mitkSceneIOTest2Suite : public mitk::TestFixture
77 {
78  CPPUNIT_TEST_SUITE(mitkSceneIOTest2Suite);
79  MITK_TEST(Test_SceneIOInterfaces);
80  MITK_TEST(Test_ReconstructionOfScenes);
81  CPPUNIT_TEST_SUITE_END();
82 
83  mitk::SceneIOTestScenarioProvider m_TestCaseProvider;
84 
85 public:
86  void Test_SceneIOInterfaces() { CPPUNIT_ASSERT_MESSAGE("Not urgent", true); }
87  void Test_ReconstructionOfScenes()
88  {
89  std::string tempDir = mitk::IOUtil::CreateTemporaryDirectory("SceneIOTest_XXXXXX");
90 
92  MITK_TEST_OUTPUT(<< "Executing " << scenarios.size() << " test scenarios");
93  for (auto scenario : scenarios)
94  {
95  MITK_TEST_OUTPUT(<< "\n===== Test_ReconstructionOfScenes, scenario '" << scenario.key << "' =====");
96 
97  std::string archiveFilename = mitk::IOUtil::CreateTemporaryFile("scene_XXXXXX.mitk", tempDir);
98  mitk::SceneIO::Pointer writer = mitk::SceneIO::New();
99  mitk::DataStorage::Pointer originalStorage = scenario.BuildDataStorage();
100  CPPUNIT_ASSERT_MESSAGE(
101  std::string("Save test scenario '") + scenario.key + "' to '" + archiveFilename + "'",
102  scenario.serializable == writer->SaveScene(originalStorage->GetAll(), originalStorage, archiveFilename));
103 
104  if (scenario.serializable)
105  {
106  mitk::SceneIO::Pointer reader = mitk::SceneIO::New();
107  mitk::DataStorage::Pointer restoredStorage;
108  CPPUNIT_ASSERT_NO_THROW(restoredStorage = reader->LoadScene(archiveFilename));
109  CPPUNIT_ASSERT_MESSAGE(
110  std::string("Comparing restored test scenario '") + scenario.key + "'",
111  mitk::DataStorageCompare(originalStorage,
112  restoredStorage,
113  // TODO make those flags part of the scenario object
114  // TODO make known/expected failures also part of the
115  // scenario object (but this needs a way to describe them, first)
118  // mappers tested although SceneIO leaves default mappers
120  // mitk::DataStorageCompare::CMP_Interactors
121  // interactors skipped for now
122  scenario.comparisonPrecision)
123  .CompareVerbose());
124  }
125  }
126  }
127 
128 }; // class
129 
130 int mitkSceneIOTest2(int /*argc*/, char * /*argv*/ [])
131 {
132  CppUnit::TextUi::TestRunner runner;
133  runner.addTest(mitkSceneIOTest2Suite::suite());
134  return runner.run() ? 0 : 1;
135 }
bool CompareVerbose()
Shorthand for Compare(true).
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
ScenarioList GetAllScenarios() const
Returns all registered scenarios.
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:458
static std::string CreateTemporaryFile(std::ofstream &tmpStream, const std::string &templateName="XXXXXX", std::string path=std::string())
Definition: mitkIOUtil.cpp:413
Provides DataStorages that serve as test scenarios.
std::vector< Scenario > ScenarioList
List of Scenarios.