MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
mitkNavigationToolStorageDeserializerTest.cpp
Go to the documentation of this file.
1/*============================================================================
2
3The Medical Imaging Interaction Toolkit (MITK)
4
5Copyright (c) German Cancer Research Center (DKFZ)
6All rights reserved.
7
8Use of this source code is governed by a 3-clause BSD license that can be
9found in the LICENSE file.
10
11============================================================================*/
12
13//testing headers
14#include <mitkTestingMacros.h>
15#include <mitkTestFixture.h>
16
17//headers of IGT classes releated to the tested class
19#include <mitkStandaloneDataStorage.h>
20#include <mitkIGTException.h>
21
22class mitkNavigationToolStorageDeserializerTestSuite : public mitk::TestFixture
23{
32 CPPUNIT_TEST_SUITE_END();
33
34private:
36 mitk::NavigationToolStorageDeserializer::Pointer m_Deserializer;
37 mitk::DataStorage::Pointer m_DataStorage;
38
39public:
41 void setUp() override
42 {
43 m_DataStorage = dynamic_cast<mitk::DataStorage*>(mitk::StandaloneDataStorage::New().GetPointer()); //needed for deserializer!
44 m_Deserializer = mitk::NavigationToolStorageDeserializer::New(m_DataStorage);
45 }
46
47 void tearDown() override
48 {
49 m_DataStorage = nullptr;
50 m_Deserializer = nullptr;
51 }
52
54 {
55 mitk::DataStorage::Pointer tempStorage = dynamic_cast<mitk::DataStorage*>(mitk::StandaloneDataStorage::New().GetPointer()); //needed for deserializer!
56 mitk::NavigationToolStorageDeserializer::Pointer testDeserializer = mitk::NavigationToolStorageDeserializer::New(tempStorage);
57 CPPUNIT_ASSERT_MESSAGE("Testing instantiation of NavigationToolStorageDeserializer",testDeserializer.IsNotNull());
58 }
59
61 {
62 std::string testDataPath = GetTestDataFilePath("IGT-Data/SimpleIGTStorage.storage");
63 mitk::NavigationToolStorage::Pointer readStorage = m_Deserializer->Deserialize(testDataPath);
64 CPPUNIT_ASSERT_MESSAGE("Testing deserialization of simple tool storage",readStorage.IsNotNull());
65 CPPUNIT_ASSERT_MESSAGE(" ..Testing number of tools in storage",readStorage->GetToolCount()==3);
66 //TODO: why is the order of tools changed is save/load process??
67 bool foundtool1 = false;
68 bool foundtool2 = false;
69 bool foundtool3 = false;
70 for(int i=0; i<3; i++)
71 {
72 if ((readStorage->GetTool(i)->GetIdentifier()=="001")) foundtool1 = true;
73 else if ((readStorage->GetTool(i)->GetIdentifier()=="002")) foundtool2 = true;
74 else if ((readStorage->GetTool(i)->GetIdentifier()=="003")) foundtool3 = true;
75 }
76 CPPUNIT_ASSERT_MESSAGE(" ..Testing if tool 1 was loaded successfully",foundtool1);
77 CPPUNIT_ASSERT_MESSAGE(" ..Testing if tool 2 was loaded successfully",foundtool2);
78 CPPUNIT_ASSERT_MESSAGE(" ..Testing if tool 3 was loaded successfully",foundtool3);
79 }
80
82 {
83 std::string testDataPath = GetTestDataFilePath("IGT-Data/ComplexIGTStorage.storage");
84 mitk::NavigationToolStorage::Pointer readStorage = m_Deserializer->Deserialize(testDataPath);
85 CPPUNIT_ASSERT_MESSAGE("Testing deserialization of complex tool storage",readStorage.IsNotNull());
86 CPPUNIT_ASSERT_MESSAGE(" ..Testing number of tools in storage",readStorage->GetToolCount()==2);
87 }
88
90 {
91 CPPUNIT_ASSERT_THROW_MESSAGE("Testing if exception is thrown if a non existing storage is given for deserialization.",
92 m_Deserializer->Deserialize("noStorage.tfl"),
94 }
95
97 {
98 std::string testDataPath = GetTestDataFilePath("IGT-Data/ClaronTool.stl");
99
100 CPPUNIT_ASSERT_THROW_MESSAGE("Testing if exception is thrown if a wrong file type is given for deserialization.",
101 m_Deserializer->Deserialize(testDataPath),
103 }
104
106 {
107 std::string testDataPath = GetTestDataFilePath("IGT-Data/Empty.zip");
108
109 CPPUNIT_ASSERT_THROW_MESSAGE("Testing if exception is thrown if a empty zip file is given for deserialization.",
110 m_Deserializer->Deserialize(testDataPath),
112 }
113
114 //new tests for exception throwing of NavigationToolStorageDeserializer
116 {
117 CPPUNIT_ASSERT_THROW_MESSAGE("Testing deserializer with invalid filename.",
118 m_Deserializer->Deserialize("InvalidName"),
120
121 std::string testDataPath = GetTestDataFilePath("IGT-Data/Empty2.zip");
122 CPPUNIT_ASSERT_THROW_MESSAGE("Testing deserializer with invalid filename.",
123 m_Deserializer->Deserialize(testDataPath),
125 }
126
127
128};
129MITK_TEST_SUITE_REGISTRATION(mitkNavigationToolStorageDeserializer)
void setUp() override
Setup Always call this method before each Test-case to ensure correct and new intialization of the us...
An object of this class represents an exception of the MITK-IGT module.