diff --git a/Modules/IGT/Testing/mitkNavigationToolStorageSerializerAndDeserializerIntegrationTest.cpp b/Modules/IGT/Testing/mitkNavigationToolStorageSerializerAndDeserializerIntegrationTest.cpp index ff4300806b..3139c5cdfe 100644 --- a/Modules/IGT/Testing/mitkNavigationToolStorageSerializerAndDeserializerIntegrationTest.cpp +++ b/Modules/IGT/Testing/mitkNavigationToolStorageSerializerAndDeserializerIntegrationTest.cpp @@ -1,496 +1,396 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ //testing headers #include #include #include //some general mitk headers #include #include #include //headers of IGT classes releated to the tested class #include #include #include #include #include #include //POCO headers for file handling #include #include #include class mitkNavigationToolStorageSerializerAndDeserializerIntegrationTestSuite : public mitk::TestFixture { CPPUNIT_TEST_SUITE(mitkNavigationToolStorageSerializerAndDeserializerIntegrationTestSuite); MITK_TEST(TestInstantiationSerializer); MITK_TEST(TestInstantiationDeserializer); CPPUNIT_TEST_SUITE_END(); private: /** Members used inside the different test methods. All members are initialized via setUp().*/ public: /**@brief Setup Always call this method before each Test-case to ensure correct and new intialization of the used members for a new test case. (If the members are not used in a test, the method does not need to be called).*/ void setUp() { } void tearDown() { } void TestInstantiationSerializer() { // let's create objects of our classes mitk::NavigationToolStorageSerializer::Pointer testSerializer = mitk::NavigationToolStorageSerializer::New(); CPPUNIT_ASSERT_MESSAGE("Testing instantiation of NavigationToolStorageSerializer",testSerializer.IsNotNull()); } void TestInstantiationDeserializer() { mitk::DataStorage::Pointer tempStorage = dynamic_cast(mitk::StandaloneDataStorage::New().GetPointer()); //needed for deserializer! mitk::NavigationToolStorageDeserializer::Pointer testDeserializer = mitk::NavigationToolStorageDeserializer::New(tempStorage); CPPUNIT_ASSERT_MESSAGE("Testing instantiation of NavigationToolStorageDeserializer",testDeserializer.IsNotNull()); } }; MITK_TEST_SUITE_REGISTRATION(mitkNavigationToolStorageSerializerAndDeserializerIntegration) - - -//static void TestWriteSimpleToolStorage() -//{ -// //create Tool Storage -// mitk::NavigationToolStorage::Pointer myStorage = mitk::NavigationToolStorage::New(); -// //first tool -// mitk::NavigationTool::Pointer myTool1 = mitk::NavigationTool::New(); -// myTool1->SetIdentifier("001"); -// myStorage->AddTool(myTool1); -// //second tool -// mitk::NavigationTool::Pointer myTool2 = mitk::NavigationTool::New(); -// myTool2->SetIdentifier("002"); -// myStorage->AddTool(myTool2); -// //third tool -// mitk::NavigationTool::Pointer myTool3 = mitk::NavigationTool::New(); -// myTool3->SetIdentifier("003"); -// myStorage->AddTool(myTool3); -// -// //create Serializer -// mitk::NavigationToolStorageSerializer::Pointer mySerializer = mitk::NavigationToolStorageSerializer::New(); -// -// //create filename -// std::string filename = std::string( MITK_TEST_OUTPUT_DIR )+Poco::Path::separator()+"TestStorage.storage"; -// -// //test serialization -// bool success = mySerializer->Serialize(filename,myStorage); -// MITK_TEST_CONDITION_REQUIRED(success,"Testing serialization of simple tool storage"); -//} // //static void TestWriteAndReadSimpleToolStorageWithToolLandmarks() //{ // //create Tool Storage // mitk::NavigationToolStorage::Pointer myStorage = mitk::NavigationToolStorage::New(); // // //first tool // mitk::NavigationTool::Pointer myTool1 = mitk::NavigationTool::New(); // myTool1->SetIdentifier("001"); // mitk::PointSet::Pointer CalLandmarks1 = mitk::PointSet::New(); // mitk::Point3D testPt1; // mitk::FillVector3D(testPt1,1,2,3); // CalLandmarks1->SetPoint(0,testPt1); // mitk::PointSet::Pointer RegLandmarks1 = mitk::PointSet::New(); // mitk::Point3D testPt2; // mitk::FillVector3D(testPt2,4,5,6); // RegLandmarks1->SetPoint(5,testPt2); // myTool1->SetToolCalibrationLandmarks(CalLandmarks1); // myTool1->SetToolRegistrationLandmarks(RegLandmarks1); // mitk::Point3D toolTipPos; // mitk::FillVector3D(toolTipPos,1.3423,2.323,4.332); // mitk::Quaternion toolTipRot = mitk::Quaternion(0.1,0.2,0.3,0.4); // myTool1->SetToolTipPosition(toolTipPos); // myTool1->SetToolTipOrientation(toolTipRot); // myStorage->AddTool(myTool1); // // //create Serializer // mitk::NavigationToolStorageSerializer::Pointer mySerializer = mitk::NavigationToolStorageSerializer::New(); // // //create filename // std::string filename = std::string( MITK_TEST_OUTPUT_DIR )+Poco::Path::separator()+"TestStorageToolReg.storage"; // // //test serialization // bool success = mySerializer->Serialize(filename,myStorage); // MITK_TEST_CONDITION_REQUIRED(success,"Testing serialization of tool storage with tool registrations"); // // mitk::DataStorage::Pointer tempStorage = dynamic_cast(mitk::StandaloneDataStorage::New().GetPointer()); //needed for deserializer! // mitk::NavigationToolStorageDeserializer::Pointer myDeserializer = mitk::NavigationToolStorageDeserializer::New(tempStorage); // mitk::NavigationToolStorage::Pointer readStorage = myDeserializer->Deserialize(std::string( MITK_TEST_OUTPUT_DIR )+Poco::Path::separator()+"TestStorageToolReg.storage"); // MITK_TEST_CONDITION_REQUIRED(readStorage.IsNotNull(),"Testing deserialization of tool storage with tool registrations"); // MITK_TEST_CONDITION_REQUIRED(readStorage->GetToolCount()==1," ..Testing number of tools in storage"); // // mitk::PointSet::Pointer readRegLandmarks = readStorage->GetTool(0)->GetToolRegistrationLandmarks(); // mitk::PointSet::Pointer readCalLandmarks = readStorage->GetTool(0)->GetToolCalibrationLandmarks(); // // MITK_TEST_CONDITION_REQUIRED(((readRegLandmarks->GetPoint(5)[0] == 4)&&(readRegLandmarks->GetPoint(5)[1] == 5)&&(readRegLandmarks->GetPoint(5)[2] == 6)),"..Testing if tool registration landmarks have been stored and loaded correctly."); // MITK_TEST_CONDITION_REQUIRED(((readCalLandmarks->GetPoint(0)[0] == 1)&&(readCalLandmarks->GetPoint(0)[1] == 2)&&(readCalLandmarks->GetPoint(0)[2] == 3)),"..Testing if tool calibration landmarks have been stored and loaded correctly."); // // mitk::Point3D readToolTipPos = readStorage->GetTool(0)->GetToolTipPosition(); // mitk::Quaternion readToolTipRot = readStorage->GetTool(0)->GetToolTipOrientation(); // // MITK_TEST_CONDITION_REQUIRED(((float(readToolTipPos[0]) == float(1.3423))&& // (float(readToolTipPos[1]) == float(2.323))&& // (float(readToolTipPos[2]) == float(4.332))), // "..Testing if tool tip position has been stored and loaded correctly."); // // MITK_TEST_CONDITION_REQUIRED(((float(readToolTipRot.x()) == float(0.1))&& // (float(readToolTipRot.y()) == float(0.2))&& // (float(readToolTipRot.z()) == float(0.3))&& // (float(readToolTipRot.r()) == float(0.4))), // "..Testing if tool tip orientation has been stored and loaded correctly."); //} -// +//Datei in MITK-Data: SimpleIGTStorage.storage //static void TestReadSimpleToolStorage() //{ // mitk::DataStorage::Pointer tempStorage = dynamic_cast(mitk::StandaloneDataStorage::New().GetPointer()); //needed for deserializer! // mitk::NavigationToolStorageDeserializer::Pointer myDeserializer = mitk::NavigationToolStorageDeserializer::New(tempStorage); // mitk::NavigationToolStorage::Pointer readStorage = myDeserializer->Deserialize(std::string( MITK_TEST_OUTPUT_DIR )+Poco::Path::separator()+"TestStorage.storage"); // MITK_TEST_CONDITION_REQUIRED(readStorage.IsNotNull(),"Testing deserialization of simple tool storage"); // MITK_TEST_CONDITION_REQUIRED(readStorage->GetToolCount()==3," ..Testing number of tools in storage"); // //TODO: why is the order of tools changed is save/load process?? // bool foundtool1 = false; // bool foundtool2 = false; // bool foundtool3 = false; // for(int i=0; i<3; i++) // { // if ((readStorage->GetTool(i)->GetIdentifier()=="001")) foundtool1 = true; // else if ((readStorage->GetTool(i)->GetIdentifier()=="002")) foundtool2 = true; // else if ((readStorage->GetTool(i)->GetIdentifier()=="003")) foundtool3 = true; // } // MITK_TEST_CONDITION_REQUIRED(foundtool1&&foundtool2&&foundtool3," ..Testing if identifiers of tools where saved / loaded successfully"); //} // -//static void CleanUp() -//{ -// try -// { -// std::remove((std::string( MITK_TEST_OUTPUT_DIR )+Poco::Path::separator()+"TestStorage.storage").c_str()); -// std::remove((std::string( MITK_TEST_OUTPUT_DIR )+Poco::Path::separator()+"TestStorageToolReg.storage").c_str()); -// std::remove((std::string( MITK_TEST_OUTPUT_DIR )+Poco::Path::separator()+"TestStorage2.storage").c_str()); -// } -// catch(...) -// { -// MITK_INFO << "Warning: Error occured when deleting test file!"; -// } -//} -// -//static void TestWriteComplexToolStorage() -//{ -// //create first tool -// mitk::Surface::Pointer testSurface; -// std::string toolFileName(MITK_IGT_DATA_DIR); -// toolFileName.append("/ClaronTool"); -// mitk::NavigationTool::Pointer myNavigationTool = mitk::NavigationTool::New(); -// myNavigationTool->SetCalibrationFile(toolFileName); -// -// mitk::DataNode::Pointer myNode = mitk::DataNode::New(); -// myNode->SetName("ClaronTool"); -// -// //load an stl File -// std::string pathToClaronTool(MITK_IGT_DATA_DIR); -// pathToClaronTool.append("/ClaronTool.stl"); -// testSurface = mitk::IOUtil::LoadSurface(pathToClaronTool); -// myNode->SetData(testSurface); -// -// myNavigationTool->SetDataNode(myNode); -// myNavigationTool->SetIdentifier("ClaronTool#1"); -// myNavigationTool->SetSerialNumber("0815"); -// myNavigationTool->SetTrackingDeviceType(mitk::ClaronMicron); -// myNavigationTool->SetType(mitk::NavigationTool::Fiducial); -// -// //create second tool -// mitk::NavigationTool::Pointer myNavigationTool2 = mitk::NavigationTool::New(); -// mitk::Surface::Pointer testSurface2; -// -// mitk::DataNode::Pointer myNode2 = mitk::DataNode::New(); -// myNode2->SetName("AuroraTool"); -// -// //load an stl File -// std::string pathToEMTool(MITK_IGT_DATA_DIR); -// pathToEMTool.append("/EMTool.stl"); -// testSurface2 = mitk::IOUtil::LoadSurface(pathToEMTool); -// myNode2->SetData(testSurface2); -// -// myNavigationTool2->SetDataNode(myNode2); -// myNavigationTool2->SetIdentifier("AuroraTool#1"); -// myNavigationTool2->SetSerialNumber("0816"); -// myNavigationTool2->SetTrackingDeviceType(mitk::NDIAurora); -// myNavigationTool2->SetType(mitk::NavigationTool::Instrument); -// -// //create navigation tool storage -// mitk::NavigationToolStorage::Pointer myStorage = mitk::NavigationToolStorage::New(); -// myStorage->AddTool(myNavigationTool); -// myStorage->AddTool(myNavigationTool2); -// -// //create Serializer -// mitk::NavigationToolStorageSerializer::Pointer mySerializer = mitk::NavigationToolStorageSerializer::New(); -// -// //create filename -// std::string filename = std::string( MITK_TEST_OUTPUT_DIR )+Poco::Path::separator()+"TestStorage2.storage"; -// -// //test serialization -// bool success = mySerializer->Serialize(filename,myStorage); -// MITK_TEST_CONDITION_REQUIRED(success,"Testing serialization of complex tool storage"); -//} // +//Datei in MITK-Data: ComplexIGTStorage.storage //static void TestReadComplexToolStorage() //{ // mitk::DataStorage::Pointer tempStorage = dynamic_cast(mitk::StandaloneDataStorage::New().GetPointer()); //needed for deserializer! // mitk::NavigationToolStorageDeserializer::Pointer myDeserializer = mitk::NavigationToolStorageDeserializer::New(tempStorage); // mitk::NavigationToolStorage::Pointer readStorage = myDeserializer->Deserialize(std::string( MITK_TEST_OUTPUT_DIR )+Poco::Path::separator()+"TestStorage2.storage"); // MITK_TEST_CONDITION_REQUIRED(readStorage.IsNotNull(),"Testing deserialization of complex tool storage"); // MITK_TEST_CONDITION_REQUIRED(readStorage->GetToolCount()==2," ..Testing number of tools in storage"); //} // //static void TestReadNotExistingStorage() //{ // mitk::DataStorage::Pointer tempStorage = dynamic_cast(mitk::StandaloneDataStorage::New().GetPointer()); //needed for deserializer! // mitk::NavigationToolStorageDeserializer::Pointer myDeserializer = mitk::NavigationToolStorageDeserializer::New(tempStorage); // // bool exceptionThrown = false; // try // { // mitk::NavigationToolStorage::Pointer readStorage = myDeserializer->Deserialize("noStorage.tfl"); // } // catch (mitk::IGTException e) // { // exceptionThrown = true; // } // MITK_TEST_CONDITION_REQUIRED(exceptionThrown,"Testing if exception is thrown if a non existing storage is given for deserialization."); //} // //static void TestReadStorageWithUnknownFiletype() //{ // mitk::DataStorage::Pointer tempStorage = dynamic_cast(mitk::StandaloneDataStorage::New().GetPointer()); //needed for deserializer! // // std::string toolFileName(MITK_IGT_DATA_DIR); // toolFileName.append("/ClaronTool.stl"); // mitk::NavigationToolStorageDeserializer::Pointer myDeserializer = mitk::NavigationToolStorageDeserializer::New(tempStorage); // // bool exceptionThrown = false; // try // { // mitk::NavigationToolStorage::Pointer readStorage = myDeserializer->Deserialize(toolFileName); // } // catch (mitk::IGTException e) // { // exceptionThrown = true; // } // MITK_TEST_CONDITION_REQUIRED(exceptionThrown,"Testing if exception is thrown if a wrong file type is given for deserialization."); //} // // //static void TestReadZipFileWithNoToolstorage() //{ // mitk::DataStorage::Pointer tempStorage = dynamic_cast(mitk::StandaloneDataStorage::New().GetPointer()); //needed for deserializer! // // std::string toolFileName(MITK_IGT_DATA_DIR); // toolFileName.append("/Empty.zip"); // MITK_TEST_CONDITION(toolFileName.empty() == false, "Check if tool calibration of claron tool file exists"); // mitk::NavigationToolStorageDeserializer::Pointer myDeserializer = mitk::NavigationToolStorageDeserializer::New(tempStorage); // // bool exceptionThrown = false; // try // { // mitk::NavigationToolStorage::Pointer readStorage = myDeserializer->Deserialize(toolFileName); // } // catch (mitk::IGTException e) // { // exceptionThrown = true; // } // catch (std::exception& e) // { // MITK_ERROR << "Unexpected exception catched: " << e.what() << " / filename: " << toolFileName; // } // MITK_TEST_CONDITION_REQUIRED(exceptionThrown,"Testing if exception is thrown if a empty zip file is given for deserialization."); //} // // //static void TestWriteStorageToInvalidFile() //{ // //create Tool Storage // mitk::NavigationToolStorage::Pointer myStorage = mitk::NavigationToolStorage::New(); // //first tool // mitk::NavigationTool::Pointer myTool1 = mitk::NavigationTool::New(); // myTool1->SetIdentifier("001"); // myStorage->AddTool(myTool1); // //second tool // mitk::NavigationTool::Pointer myTool2 = mitk::NavigationTool::New(); // myTool2->SetIdentifier("002"); // myStorage->AddTool(myTool2); // //third tool // mitk::NavigationTool::Pointer myTool3 = mitk::NavigationTool::New(); // myTool3->SetIdentifier("003"); // myStorage->AddTool(myTool3); // // //create Serializer // mitk::NavigationToolStorageSerializer::Pointer mySerializer = mitk::NavigationToolStorageSerializer::New(); // // //create filename //#ifdef WIN32 // std::string filename = "C:\342INVALIDFILE<>.storage"; //invalid filename for windows //#else // std::string filename = "/dsfdsf:$�$342INVALIDFILE.storage"; //invalid filename for linux //#endif // // // //test serialization // bool exceptionThrown = false; // try // { // mySerializer->Serialize(filename,myStorage); // } // catch(mitk::IGTException e) // { // exceptionThrown = true; // } // MITK_TEST_CONDITION_REQUIRED(exceptionThrown,"Testing if an exception is thrown if an invalid file is used."); //} // //static void TestWriteEmptyToolStorage() //{ // //create Tool Storage // mitk::NavigationToolStorage::Pointer myStorage = mitk::NavigationToolStorage::New(); // // //create Serializer // mitk::NavigationToolStorageSerializer::Pointer mySerializer = mitk::NavigationToolStorageSerializer::New(); // // std::string filename; // try // { // //create filename // filename = mitk::IOUtil::CreateTemporaryFile(); // } // catch (std::exception& e) { // MITK_ERROR << "File access Exception: " << e.what(); // MITK_TEST_FAILED_MSG(<<"Could not create filename for Exceptiontest"); // } // // //test serialization // bool success = mySerializer->Serialize(filename,myStorage); // MITK_TEST_CONDITION_REQUIRED(success,"Testing serialization of simple tool storage"); // // //clean up // Poco::File file = Poco::File(filename); // file.remove(); // //} // ////new tests for exception throwing of NavigationToolStorageSerializer //static void TestSerializerForExceptions() //{ // mitk::NavigationToolStorageSerializer::Pointer testSerializer = mitk::NavigationToolStorageSerializer::New(); // mitk::NavigationToolStorage::Pointer myStorage = mitk::NavigationToolStorage::New(); // // //create an invalid filename // std::string filename = std::string( MITK_TEST_OUTPUT_DIR )+Poco::Path::separator()+""; // // //now try to serialize an check if an exception is thrown // bool ExceptionThrown = false; // try // { // testSerializer->Serialize(filename,myStorage); // } // catch(mitk::IGTException) // { // ExceptionThrown = true; // } // MITK_TEST_CONDITION_REQUIRED(ExceptionThrown, "Testing serializer with invalid filename."); //} // ////new tests for exception throwing of NavigationToolStorageDeserializer //static void TestDeserializerForExceptions() //{ // // Desearializing file with invalid name // mitk::DataStorage::Pointer tempStorage = dynamic_cast(mitk::StandaloneDataStorage::New().GetPointer()); // mitk::NavigationToolStorageDeserializer::Pointer testDeseralizer= mitk::NavigationToolStorageDeserializer::New(tempStorage); // bool ExceptionThrown1 = false; // try // { // mitk::NavigationToolStorage::Pointer readStorage = testDeseralizer->Deserialize("InvalidName"); // } // catch(mitk::IGTException) // { // ExceptionThrown1 = true; // } // MITK_TEST_CONDITION_REQUIRED(ExceptionThrown1, "Testing deserializer with invalid filename."); // // bool ExceptionThrown2 = false; // // // Deserializing of empty zip file // mitk::NavigationToolStorageDeserializer::Pointer testDeseralizer2= mitk::NavigationToolStorageDeserializer::New(tempStorage); // try // { // std::string filename(MITK_IGT_DATA_DIR); // filename.append("/Empty2.zip"); // mitk::NavigationToolStorage::Pointer readStorage = testDeseralizer2->Deserialize(filename); // } // catch(mitk::IGTException) // { // ExceptionThrown2 = true; // } // MITK_TEST_CONDITION_REQUIRED(ExceptionThrown2, "Testing deserializer method with empty zip file."); //} // ///** This function is testing the TrackingVolume class. */ //int mitkNavigationToolStorageSerializerAndDeserializerTest(int /* argc */, char* /*argv*/[]) //{ // MITK_TEST_BEGIN("NavigationToolStorageSerializerAndDeserializer"); // try{ // TestInstantiationSerializer(); // TestInstantiationDeserializer(); // TestWriteSimpleToolStorage(); // TestWriteAndReadSimpleToolStorageWithToolLandmarks(); // TestReadSimpleToolStorage(); // TestWriteComplexToolStorage(); // TestReadComplexToolStorage(); // TestReadNotExistingStorage(); // TestReadStorageWithUnknownFiletype(); // TestReadZipFileWithNoToolstorage(); // TestWriteStorageToInvalidFile(); // TestWriteEmptyToolStorage(); // TestSerializerForExceptions(); // TestDeserializerForExceptions(); // } // catch (std::exception& e) { // MITK_ERROR << "exception:" << e.what(); // MITK_TEST_FAILED_MSG(<<"Exception occured, test failed!"); // } // catch (...) { // MITK_ERROR << "Unknown Exception?"; // MITK_TEST_FAILED_MSG(<<"Exception occured, test failed!"); // } // // CleanUp(); // // MITK_TEST_END(); //} diff --git a/Modules/IGT/Testing/mitkNavigationToolStorageSerializerTest.cpp b/Modules/IGT/Testing/mitkNavigationToolStorageSerializerTest.cpp index 3fca827f8e..ce04776e23 100644 --- a/Modules/IGT/Testing/mitkNavigationToolStorageSerializerTest.cpp +++ b/Modules/IGT/Testing/mitkNavigationToolStorageSerializerTest.cpp @@ -1,55 +1,135 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ //testing headers #include #include +#include //headers of IGT classes releated to the tested class #include - - - - class mitkNavigationToolStorageSerializerTestSuite : public mitk::TestFixture { CPPUNIT_TEST_SUITE(mitkNavigationToolStorageSerializerTestSuite); MITK_TEST(TestInstantiationSerializer); + MITK_TEST(TestWriteSimpleToolStorage); + MITK_TEST(TestWriteComplexToolStorage); CPPUNIT_TEST_SUITE_END(); private: /** Members used inside the different test methods. All members are initialized via setUp().*/ + std::string m_FileName1; public: + /**@brief Setup Always call this method before each Test-case to ensure correct and new intialization of the used members for a new test case. (If the members are not used in a test, the method does not need to be called).*/ void setUp() { + m_FileName1 = mitk::IOUtil::CreateTemporaryFile(); } void tearDown() { + try + { + std::remove(m_FileName1.c_str()); + } + catch(...) + { + MITK_INFO << "Warning: Error occured when deleting test file!"; + } } void TestInstantiationSerializer() { // let's create objects of our classes mitk::NavigationToolStorageSerializer::Pointer testSerializer = mitk::NavigationToolStorageSerializer::New(); CPPUNIT_ASSERT_MESSAGE("Testing instantiation of NavigationToolStorageSerializer",testSerializer.IsNotNull()); } + void TestWriteSimpleToolStorage() + { + //create Tool Storage + mitk::NavigationToolStorage::Pointer myStorage = mitk::NavigationToolStorage::New(); + //first tool + mitk::NavigationTool::Pointer myTool1 = mitk::NavigationTool::New(); + myTool1->SetIdentifier("001"); + myStorage->AddTool(myTool1); + //second tool + mitk::NavigationTool::Pointer myTool2 = mitk::NavigationTool::New(); + myTool2->SetIdentifier("002"); + myStorage->AddTool(myTool2); + //third tool + mitk::NavigationTool::Pointer myTool3 = mitk::NavigationTool::New(); + myTool3->SetIdentifier("003"); + myStorage->AddTool(myTool3); + + //create Serializer + mitk::NavigationToolStorageSerializer::Pointer mySerializer = mitk::NavigationToolStorageSerializer::New(); + + //test serialization + bool success = mySerializer->Serialize(m_FileName1,myStorage); + CPPUNIT_ASSERT_MESSAGE("Testing serialization of simple tool storage",success); + } + + void TestWriteComplexToolStorage() + { + //create first tool + mitk::NavigationTool::Pointer myNavigationTool = mitk::NavigationTool::New(); + myNavigationTool->SetCalibrationFile(GetTestDataFilePath("ClaronTool")); + mitk::DataNode::Pointer myNode = mitk::DataNode::New(); + myNode->SetName("ClaronTool"); + myNode->SetData(mitk::IOUtil::LoadSurface(GetTestDataFilePath("IGT-Data/ClaronTool.stl"))); //load an stl File + myNavigationTool->SetDataNode(myNode); + myNavigationTool->SetIdentifier("ClaronTool#1"); + myNavigationTool->SetSerialNumber("0815"); + myNavigationTool->SetTrackingDeviceType(mitk::ClaronMicron); + myNavigationTool->SetType(mitk::NavigationTool::Fiducial); + + //create second tool + mitk::NavigationTool::Pointer myNavigationTool2 = mitk::NavigationTool::New(); + mitk::Surface::Pointer testSurface2; + + mitk::DataNode::Pointer myNode2 = mitk::DataNode::New(); + myNode2->SetName("AuroraTool"); + + //load an stl File + testSurface2 = mitk::IOUtil::LoadSurface(GetTestDataFilePath("IGT-Data/EMTool.stl")); + myNode2->SetData(testSurface2); + + myNavigationTool2->SetDataNode(myNode2); + myNavigationTool2->SetIdentifier("AuroraTool#1"); + myNavigationTool2->SetSerialNumber("0816"); + myNavigationTool2->SetTrackingDeviceType(mitk::NDIAurora); + myNavigationTool2->SetType(mitk::NavigationTool::Instrument); + + //create navigation tool storage + mitk::NavigationToolStorage::Pointer myStorage = mitk::NavigationToolStorage::New(); + myStorage->AddTool(myNavigationTool); + myStorage->AddTool(myNavigationTool2); + + //create Serializer + mitk::NavigationToolStorageSerializer::Pointer mySerializer = mitk::NavigationToolStorageSerializer::New(); + + + //test serialization + bool success = mySerializer->Serialize(m_FileName1,myStorage); + CPPUNIT_ASSERT_MESSAGE("Testing serialization of complex tool storage",success); + } + }; MITK_TEST_SUITE_REGISTRATION(mitkNavigationToolStorageSerializer)