Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkExampleDataStructureReaderWriterTest.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 // Testing
18 #include "mitkTestFixture.h"
19 #include "mitkTestingMacros.h"
20 
21 // std includes
22 #include <string>
23 
24 // MITK includes
26 #include "mitkIOUtil.h"
27 
28 // VTK includes
29 #include <vtkDebugLeaks.h>
30 
31 class mitkExampleDataStructureReaderWriterTestSuite : public mitk::TestFixture
32 {
33  CPPUNIT_TEST_SUITE(mitkExampleDataStructureReaderWriterTestSuite);
34 
35  // Test saving/loading
36  MITK_TEST(ReadWrite_ExampleData_SavedAndLoadedDataEqualToExample);
37  CPPUNIT_TEST_SUITE_END();
38 
39 private:
41  std::string m_DefaultDataString;
42 
43 public:
48  void setUp() override
49  {
50  m_DefaultDataString = "This is the example data content\nAnd a second line\n";
52  m_Data->SetData(m_DefaultDataString);
53  }
54 
55  void tearDown() override
56  {
57  m_DefaultDataString = "";
58  m_Data = nullptr;
59  }
60 
61  void ReadWrite_ExampleData_SavedAndLoadedDataEqualToExample()
62  {
63  std::string path = mitk::IOUtil::GetTempPath() + "ExampleDataOutput.txt";
64  mitk::IOUtil::SaveBaseData(m_Data, path);
66  dynamic_cast<mitk::ExampleDataStructure *>(mitk::IOUtil::LoadBaseData(path).GetPointer());
67 
68  itksys::SystemTools::RemoveFile(path);
69 
70  CPPUNIT_ASSERT_MESSAGE("Comparing created and loaded example data.",
71  mitk::Equal(m_Data, loadedData, mitk::eps, true));
72  }
73 };
74 
75 MITK_TEST_SUITE_REGISTRATION(mitkExampleDataStructureReaderWriter)
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
static std::string GetTempPath()
Definition: mitkIOUtil.cpp:372
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
static mitk::BaseData::Pointer LoadBaseData(const std::string &path)
Create a BaseData object from the given file.
Definition: mitkIOUtil.cpp:576
static bool SaveBaseData(mitk::BaseData *data, const std::string &path)
SaveBaseData Convenience method to save arbitrary baseData.
Definition: mitkIOUtil.cpp:888
Test fixture for parameterized tests.
MITKNEWMODULE_EXPORT bool Equal(mitk::ExampleDataStructure *leftHandSide, mitk::ExampleDataStructure *rightHandSide, mitk::ScalarType eps, bool verbose)
Returns true if the example data structures are considered equal.
MITKCORE_EXPORT const ScalarType eps