diff --git a/Modules/IGT/Testing/files.cmake b/Modules/IGT/Testing/files.cmake index 93510729b4..274b641bde 100644 --- a/Modules/IGT/Testing/files.cmake +++ b/Modules/IGT/Testing/files.cmake @@ -1,46 +1,47 @@ set(MODULE_TESTS mitkCameraVisualizationTest.cpp mitkClaronInterfaceTest.cpp mitkClaronToolTest.cpp mitkClaronTrackingDeviceTest.cpp mitkInternalTrackingToolTest.cpp mitkNavigationDataDisplacementFilterTest.cpp mitkNavigationDataLandmarkTransformFilterTest.cpp mitkNavigationDataObjectVisualizationFilterTest.cpp mitkNavigationDataSetTest.cpp mitkNavigationDataTest.cpp mitkNavigationDataRecorderTest.cpp mitkNavigationDataReferenceTransformFilterTest.cpp mitkNavigationDataSequentialPlayerTest.cpp + mitkNavigationDataSetReaderWriterTest.cpp mitkNavigationDataSourceTest.cpp mitkNavigationDataToMessageFilterTest.cpp mitkNavigationDataToNavigationDataFilterTest.cpp mitkNavigationDataToPointSetFilterTest.cpp mitkNavigationDataTransformFilterTest.cpp mitkNDIPassiveToolTest.cpp mitkNDIProtocolTest.cpp mitkNDITrackingDeviceTest.cpp mitkTimeStampTest.cpp mitkTrackingVolumeGeneratorTest.cpp mitkTrackingDeviceTest.cpp mitkTrackingToolTest.cpp mitkVirtualTrackingDeviceTest.cpp mitkNavigationDataPlayerTest.cpp # see bug 11636 (extend this test by microservices) mitkTrackingDeviceSourceTest.cpp mitkTrackingDeviceSourceConfiguratorTest.cpp mitkNavigationDataEvaluationFilterTest.cpp mitkTrackingTypesTest.cpp # ------------------ Navigation Tool Management Tests ------------------- mitkNavigationToolStorageTest.cpp mitkNavigationToolTest.cpp mitkNavigationToolReaderAndWriterTest.cpp mitkNavigationToolStorageSerializerAndDeserializerTest.cpp # ----------------------------------------------------------------------- ) set(MODULE_CUSTOM_TESTS mitkNDIAuroraHardwareTest.cpp mitkNDIPolarisHardwareTest.cpp mitkClaronTrackingDeviceHardwareTest.cpp ) diff --git a/Modules/IGT/Testing/mitkNavigationDataSetReaderWriterTest.cpp b/Modules/IGT/Testing/mitkNavigationDataSetReaderWriterTest.cpp new file mode 100644 index 0000000000..a0265968cf --- /dev/null +++ b/Modules/IGT/Testing/mitkNavigationDataSetReaderWriterTest.cpp @@ -0,0 +1,98 @@ +/*=================================================================== + +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. + +===================================================================*/ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include + +//for exceptions +#include "mitkIGTException.h" +#include "mitkIGTIOException.h" + +class mitkNavigationDataSetReaderWriterTestClass +{ +public: + + static void TestReadWrite() + { + // Aim is to read an xml into a pointset, write that xml again, and compare the output + + mitk::NavigationDataSetWriterXML writer; + mitk::NavigationDataReaderXML::Pointer reader = mitk::NavigationDataReaderXML::New(); + + std::string path = "F://Build//MITK-Data//IGT-Data//NavigationDataSet.xml"; + mitk::NavigationDataSet::Pointer set = reader->Read(path); + writer.Write("F://Build//MITK-Data//IGT-Data//NavigationDataSet2.xml", set); + } + + static bool CompareFiles(std::string file1, std::string file2) + { + FILE* f1 = fopen (file1.c_str() , "r"); + FILE* f2 = fopen (file2.c_str() , "r"); + char buf1[10000]; + char buf2[10000]; + + do { + size_t r1 = fread(buf1, 1, 10000, f1); + size_t r2 = fread(buf2, 1, 10000, f2); + + if (r1 != r2 || + memcmp(buf1, buf2, r1)) { + return false; // Files are not equal + } + } while (!feof(f1) && !feof(f2)); + + return feof(f1) && feof(f2); + } +}; + +/**Documentation +* test for the class "NavigationDataRecorder". +*/ +int mitkNavigationDataSetReaderWriterTest(int /* argc */, char* /*argv*/[]) +{ + MITK_TEST_BEGIN("NavigationDataRecorder"); + + MITK_TEST_CONDITION_REQUIRED(mitkNavigationDataSetReaderWriterTestClass::CompareFiles("F://Build//MITK-Data//IGT-Data//NavigationDataSet.xml", + "F://Build//MITK-Data//IGT-Data//NavigationDataSet.xml"), "Asserting that compare function for files works correctly - Positive Test"); + MITK_TEST_CONDITION_REQUIRED(! mitkNavigationDataSetReaderWriterTestClass::CompareFiles("F://Build//MITK-Data//IGT-Data//NavigationDataSet.xml", + "F://Build//MITK-Data//IGT-Data//SROMFile.rom"), "Asserting that compare function for files works correctly - Negative Test"); + mitkNavigationDataSetReaderWriterTestClass::TestReadWrite(); + //mitkNavigationDataSetReaderWriterTestClass::TestRecordingWithGivenStream(); + //mitkNavigationDataSetReaderWriterTestClass::TestRecordingOnHarddiscXML(); + //mitkNavigationDataSetReaderWriterTestClass::TestRecordingOnHarddiscXMLZIP(); + //mitkNavigationDataSetReaderWriterTestClass::TestRecordingOnHarddiscCSV(); + //mitkNavigationDataSetReaderWriterTestClass::TestRecordingInvalidData(); + //mitkNavigationDataSetReaderWriterTestClass::TestStartRecordingExceptions(); + + ////Test fails under linux, perhaps reading permission problems, deactivated it temporary + ////mitkNavigationDataSetReaderWriterTestClass::TestLoadingRecordedXMLFile(); + + //mitkNavigationDataSetReaderWriterTestClass::CleanUp(); + + MITK_TEST_END(); +};