diff --git a/Modules/Core/test/mitkBaseDataTest.cpp b/Modules/Core/test/mitkBaseDataTest.cpp index 0e7be67417..16a242f275 100644 --- a/Modules/Core/test/mitkBaseDataTest.cpp +++ b/Modules/Core/test/mitkBaseDataTest.cpp @@ -1,279 +1,278 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ // Testing #include "mitkTestFixture.h" #include "mitkTestingMacros.h" // std includes #include // MITK includes #include "mitkBaseDataTestImplementation.h" #include "mitkStringProperty.h" #include #include -// itksys #include "itkImage.h" // VTK includes #include class mitkBaseDataTestSuite : public mitk::TestFixture { CPPUNIT_TEST_SUITE(mitkBaseDataTestSuite); MITK_TEST(CreateBaseData_Success); MITK_TEST(InitializationOfBaseData_Success); MITK_TEST(CreateCloneBaseData_Success); MITK_TEST(InitializationOfCloneBaseData_Success); MITK_TEST(GetAndSetTimeGeometry_Success); MITK_TEST(ResetTimeGeometry_Success); MITK_TEST(ReinitOfTimeGeometry_Success); MITK_TEST(GetGeometryForSingleTimeGeometries_Failure); MITK_TEST(TestingExpand_Success); MITK_TEST(TestingGetUpdateGeometry_Success); MITK_TEST(GetOriginOfBaseData_Success); MITK_TEST(GetOriginOfCloneBaseData); MITK_TEST(ClearATimeStep); MITK_TEST(BaseDataSetAndGetProperty_Success); MITK_TEST(CloneBaseDataSetAndGetProperty_Success); MITK_TEST(BasePropertyListIsSet_Success); MITK_TEST(BasePorpertyIsSetInPropertyList_Success); MITK_TEST(UpdateOutputInformationOfBaseData_Failure); MITK_TEST(CopyingInformationOfBaseData_Failure); CPPUNIT_TEST_SUITE_END(); private: mitk::BaseDataTestImplementation::Pointer m_BaseDataImpl; mitk::BaseDataTestImplementation::Pointer m_CloneBaseData; mitk::TimeGeometry *m_Geo; mitk::ProportionalTimeGeometry::Pointer m_Geo2; mitk::Geometry3D::Pointer m_Geometry3D; mitk::BaseGeometry::Pointer m_Geo3; mitk::ScalarType m_X[3]; mitk::PropertyList::Pointer m_PropertyList; public: void setUp() override { m_BaseDataImpl = mitk::BaseDataTestImplementation::New(); m_CloneBaseData = m_BaseDataImpl->Clone(); m_Geo = nullptr; m_Geo2 = mitk::ProportionalTimeGeometry::New(); m_Geometry3D = mitk::Geometry3D::New(); m_Geo3 = dynamic_cast(m_Geometry3D.GetPointer()); m_X[0] = 2; m_X[1] = 4; m_X[2] = 6; m_PropertyList = mitk::PropertyList::New(); } void tearDown() override { m_BaseDataImpl = nullptr; m_CloneBaseData = nullptr; m_Geo = nullptr; m_Geo2 = nullptr; m_Geometry3D = nullptr; m_Geo3 = nullptr; m_X[0] = 0; m_X[1] = 0; m_X[2] = 0; m_PropertyList = nullptr; } void CreateBaseData_Success() { // Create a BaseData implementation MITK_INFO << "Creating a base data instance..."; CPPUNIT_ASSERT_MESSAGE("Testing instantiation", m_BaseDataImpl.IsNotNull()); } void InitializationOfBaseData_Success() { CPPUNIT_ASSERT_MESSAGE("BaseDataTestImplementation is initialized", m_BaseDataImpl->IsInitialized()); CPPUNIT_ASSERT_MESSAGE("BaseDataTestImplementation is initialized and empty", m_BaseDataImpl->IsEmpty()); } void CreateCloneBaseData_Success() { // Create CloneBaseData implementation MITK_INFO << "Creating a clone base data instance..."; CPPUNIT_ASSERT_MESSAGE("Testing instantiation of base data clone", m_CloneBaseData.IsNotNull()); } void InitializationOfCloneBaseData_Success() { CPPUNIT_ASSERT_MESSAGE("Clone of BaseDataTestImplementation is initialized", m_CloneBaseData->IsInitialized()); CPPUNIT_ASSERT_MESSAGE("Clone of BaseDataTestImplementation is initialized and empty", m_CloneBaseData->IsEmpty()); } void GetAndSetTimeGeometry_Success() { // test method GetTimeGeometry() MITK_INFO << "Testing setter and getter for geometries..."; CPPUNIT_ASSERT_MESSAGE("Testing creation of TimeGeometry", m_BaseDataImpl->GetTimeGeometry()); } void ResetTimeGeometry_Success() { m_BaseDataImpl->SetTimeGeometry(m_Geo); CPPUNIT_ASSERT_MESSAGE("Reset Geometry", m_BaseDataImpl->GetTimeGeometry() == nullptr); } void ReinitOfTimeGeometry_Success() { m_BaseDataImpl->SetTimeGeometry(m_Geo2); m_Geo2->Initialize(2); CPPUNIT_ASSERT_MESSAGE("Correct Reinit of TimeGeometry", m_BaseDataImpl->GetTimeGeometry() == m_Geo2.GetPointer()); } void GetGeometryForSingleTimeGeometries_Failure() { // test method GetGeometry(int timeStep) CPPUNIT_ASSERT_MESSAGE("Testing Creation of single TimeGeometries", m_BaseDataImpl->GetGeometry(1) == nullptr); } void TestingExpand_Success() { // test method Expand(unsigned int timeSteps) m_BaseDataImpl->Expand(5); CPPUNIT_ASSERT_MESSAGE("Expand the geometry to further time slices!", m_BaseDataImpl->GetTimeSteps() == 5); } void TestingGetUpdateGeometry_Success() { // test method GetUpdatedGeometry(int timeStep); m_BaseDataImpl->Expand(5); mitk::ProportionalTimeGeometry::Pointer timeGeometry = dynamic_cast(m_BaseDataImpl->GetTimeGeometry()); if (timeGeometry.IsNotNull()) { timeGeometry->SetTimeStepGeometry(m_Geo3, 1); } CPPUNIT_ASSERT_MESSAGE("Set Geometry for time step 1", m_BaseDataImpl->GetUpdatedGeometry(1) == m_Geo3); CPPUNIT_ASSERT_MESSAGE("Check if modified time is set", m_BaseDataImpl->GetMTime() != 0); } void GetOriginOfBaseData_Success() { m_BaseDataImpl->Expand(5); m_BaseDataImpl->SetClonedGeometry(m_Geo3, 1); mitk::Point3D p3d(m_X); m_BaseDataImpl->SetOrigin(p3d); m_Geo3->SetOrigin(p3d); CPPUNIT_ASSERT_MESSAGE("Testing Origin set", m_BaseDataImpl->GetGeometry(1)->GetOrigin() == m_Geo3->GetOrigin()); } void GetOriginOfCloneBaseData() { m_BaseDataImpl->Expand(5); m_BaseDataImpl->SetClonedGeometry(m_Geo3, 1); mitk::Point3D p3d(m_X); m_BaseDataImpl->SetOrigin(p3d); m_Geo3->SetOrigin(p3d); m_CloneBaseData = m_BaseDataImpl->Clone(); CPPUNIT_ASSERT_MESSAGE("Testing origin set in clone!", m_CloneBaseData->GetGeometry(1)->GetOrigin() == m_Geo3->GetOrigin()); } void ClearATimeStep() { CPPUNIT_ASSERT_MESSAGE("Is not empty before clear()!", !m_BaseDataImpl->IsEmptyTimeStep(1)); m_BaseDataImpl->Clear(); CPPUNIT_ASSERT_MESSAGE("...but afterwards!", m_BaseDataImpl->IsEmptyTimeStep(1)); } void BaseDataSetAndGetProperty_Success() { // test method Set-/GetProperty() m_BaseDataImpl->SetProperty("property38", mitk::StringProperty::New("testproperty")); CPPUNIT_ASSERT_MESSAGE("Check if base property is set correctly!", m_BaseDataImpl->GetProperty("property38")->GetValueAsString() == "testproperty"); } void CloneBaseDataSetAndGetProperty_Success() { m_BaseDataImpl->SetProperty("property38", mitk::StringProperty::New("testproperty")); m_CloneBaseData = m_BaseDataImpl->Clone(); CPPUNIT_ASSERT_MESSAGE("Testing origin set in clone!", m_CloneBaseData->GetProperty("property38")->GetValueAsString() == "testproperty"); } void BasePropertyListIsSet_Success() { // test method Set-/GetPropertyList m_PropertyList->SetFloatProperty("floatProperty1", 123.45); m_PropertyList->SetBoolProperty("visibility", true); m_PropertyList->SetStringProperty("nameXY", "propertyName"); m_BaseDataImpl->SetPropertyList(m_PropertyList); CPPUNIT_ASSERT_MESSAGE("Check if base property list is set correctly!", m_BaseDataImpl->GetPropertyList() == m_PropertyList); } void BasePorpertyIsSetInPropertyList_Success() { m_PropertyList->SetFloatProperty("floatProperty1", 123.45); m_PropertyList->SetBoolProperty("visibility", true); m_PropertyList->SetStringProperty("nameXY", "propertyName"); m_BaseDataImpl->SetPropertyList(m_PropertyList); bool value = false; CPPUNIT_ASSERT_MESSAGE("Check if base property is set correctly in the property list!", m_BaseDataImpl->GetPropertyList()->GetBoolProperty("visibility", value) == true); } void UpdateOutputInformationOfBaseData_Failure() { // test method UpdateOutputInformation() m_BaseDataImpl->UpdateOutputInformation(); m_Geo2->Initialize(2); m_Geo2.GetPointer(); CPPUNIT_ASSERT_MESSAGE("TimeGeometry update!", m_BaseDataImpl->GetUpdatedTimeGeometry() != m_Geo2); } void CopyingInformationOfBaseData_Failure() { // Test method CopyInformation() mitk::BaseDataTestImplementation::Pointer newBaseData = mitk::BaseDataTestImplementation::New(); newBaseData->CopyInformation(m_BaseDataImpl); CPPUNIT_ASSERT_MESSAGE("Check copying of Basedata Data Object!", newBaseData->GetTimeGeometry()->CountTimeSteps() != 5); } }; MITK_TEST_SUITE_REGISTRATION(mitkBaseData) diff --git a/Modules/Core/test/mitkDispatcherTest.cpp b/Modules/Core/test/mitkDispatcherTest.cpp index 87169dd319..3b622050d5 100644 --- a/Modules/Core/test/mitkDispatcherTest.cpp +++ b/Modules/Core/test/mitkDispatcherTest.cpp @@ -1,119 +1,203 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ -#include "itkLightObject.h" +// Testing +#include "mitkTestFixture.h" +#include "mitkTestingMacros.h" +// MITK includes +#include #include "mitkBaseRenderer.h" #include "mitkDataInteractor.h" #include "mitkDataNode.h" #include "mitkDispatcher.h" #include "mitkStandaloneDataStorage.h" -#include "mitkTestingMacros.h" #include "mitkVtkPropRenderer.h" +// ITK includes +#include "itkLightObject.h" -int mitkDispatcherTest(int /*argc*/, char * /*argv*/ []) +class mitkDispatcherTestSuite : public mitk::TestFixture { - MITK_TEST_BEGIN("Dispatcher") + CPPUNIT_TEST_SUITE(mitkDispatcherTestSuite); + MITK_TEST(DispatcherExists_Success); + MITK_TEST(AddInteractorConnectedToDataStorage_IncreaseNumberOfInteractors); + MITK_TEST(AddDataNodeToInteractor_NoIncreasedNumberOfInteractors); + MITK_TEST(AddInteractorNotConnectedToDataStorage_NoRegisteredInteractor); + MITK_TEST(ConnectInteractorToDataStorage_ReplaceInteractorEntry); + MITK_TEST(NewDataNodeAndInteractor_IncreasedNumberOfInteractors); + MITK_TEST(InteractorsPointToSameDataNode_DecreasedNumberOfInteractors); + MITK_TEST(SetDataNodeToNullptr_RemoveInteractor); + MITK_TEST(RemoveDataNode_RemoveInteractor); + MITK_TEST(GetReferenceCountDataNode_Success); + MITK_TEST(GetReferenceCountInteractors_Success); + CPPUNIT_TEST_SUITE_END(); + +private: + + vtkRenderWindow *m_RenWin; + mitk::VtkPropRenderer::Pointer m_Renderer; + + mitk::StandaloneDataStorage::Pointer m_Ds; + mitk::DataNode::Pointer m_Dn; + + mitk::DataNode::Pointer m_Dn2; + mitk::DataInteractor::Pointer m_Ei; + mitk::DataInteractor::Pointer m_Ei2; +public: /* - * Tests the process of creating Interactors and assigning DataNodes to them. - * Test checks if these Interactors are added to the Dispatcher under different conditions, - * and in different call order. - */ - - // Here BindDispatcherInteractor and Dispatcher should be created automatically - vtkRenderWindow *renWin = vtkRenderWindow::New(); - mitk::VtkPropRenderer::Pointer renderer = - mitk::VtkPropRenderer::New("ContourRenderer", renWin); - - mitk::StandaloneDataStorage::Pointer ds = mitk::StandaloneDataStorage::New(); - mitk::DataNode::Pointer dn; - - dn = mitk::DataNode::New(); - mitk::DataNode::Pointer dn2 = mitk::DataNode::New(); - mitk::DataInteractor::Pointer ei = mitk::DataInteractor::New(); - mitk::DataInteractor::Pointer ei2 = mitk::DataInteractor::New(); - - MITK_TEST_CONDITION_REQUIRED(renderer->GetDispatcher()->GetNumberOfInteractors() == 0, - "01 Check Existence of Dispatcher."); - - ei->SetDataNode(dn); - renderer->SetDataStorage(ds); - ds->Add(dn); - - int num = renderer->GetDispatcher()->GetNumberOfInteractors(); - MITK_TEST_CONDITION_REQUIRED(num == 1, "02 Number of registered Interactors " << num << " , expected 1"); - - // This _must not_ result in additionally registered interactors. - ei->SetDataNode(dn); - ei->SetDataNode(dn); - - num = renderer->GetDispatcher()->GetNumberOfInteractors(); - MITK_TEST_CONDITION_REQUIRED(num == 1, "03 Number of registered Interactors " << num << " , expected 1"); - - // Switching the DataNode of an Interactor also must not result in extra registered Interactors in Dispatcher - // since dn2 is not connected to DataStorage - // ei will be dropped from dispatcher - ei->SetDataNode(dn2); - - num = renderer->GetDispatcher()->GetNumberOfInteractors(); - MITK_TEST_CONDITION_REQUIRED(num == 0, "04 Number of registered Interactors " << num << " , expected 0"); - - // DataNode Added to DataStorage, now Interactor entry in Dispatcher should be replaced, - // hence we restore Interactor in the Dispatcher - ds->Add(dn2); - - num = renderer->GetDispatcher()->GetNumberOfInteractors(); - MITK_TEST_CONDITION_REQUIRED(num == 1, "05 Number of registered Interactors " << num << " , expected 1"); - - // New DataNode and new interactor, this should result in additional Interactor in the Dispatcher. - - ei2->SetDataNode(dn); - - num = renderer->GetDispatcher()->GetNumberOfInteractors(); - MITK_TEST_CONDITION_REQUIRED(num == 2, "06 Number of registered Interactors " << num << " , expected 2"); - - // Here ei and ei2 point to the same dn2; dn2 now only points to ei2, so ei is abandoned, - // therefore ei1 is expected to be removed - - ei2->SetDataNode(dn2); - num = renderer->GetDispatcher()->GetNumberOfInteractors(); - MITK_TEST_CONDITION_REQUIRED(num == 1, "07 Number of registered Interactors " << num << " , expected 1"); - - // Setting DataNode in Interactor to nullptr, should remove Interactor from Dispatcher - ei2->SetDataNode(nullptr); - num = renderer->GetDispatcher()->GetNumberOfInteractors(); - MITK_TEST_CONDITION_REQUIRED(num == 0, "08 Number of registered Interactors " << num << " , expected 0"); - - // Add DN again check if it is registered - - ei2->SetDataNode(dn); - - num = renderer->GetDispatcher()->GetNumberOfInteractors(); - MITK_TEST_CONDITION_REQUIRED(num == 1, "09 Number of registered Interactors " << num << " , expected 1"); - - // If DN is removed Interactors should be too - ds->Remove(dn); - num = renderer->GetDispatcher()->GetNumberOfInteractors(); - MITK_TEST_CONDITION_REQUIRED(num == 0, "10 Number of registered Interactors " << num << " , expected 0"); - - // after DN is removed from DS its reference count must be back to one - - MITK_TEST_CONDITION_REQUIRED(dn->GetReferenceCount() == 1, - "10 Number of references of DataNode " << num << " , expected 1"); - - MITK_TEST_CONDITION_REQUIRED(ei->GetReferenceCount() == 1, - "11 Number of references of Interactors " << num << " , expected 1"); - - renWin->Delete(); - // always end with this! - MITK_TEST_END() -} + * Tests the process of creating Interactors and assigning DataNodes to them. + * Test checks if these Interactors are added to the Dispatcher under different conditions, + * and in different call order. + */ + + void setUp() + { + // Here BindDispatcherInteractor and Dispatcher should be created automatically + m_RenWin = vtkRenderWindow::New(); + m_Renderer = mitk::VtkPropRenderer::New("ContourRenderer", m_RenWin); + m_Ds = mitk::StandaloneDataStorage::New(); + m_Dn = mitk::DataNode::New(); + m_Dn2 = mitk::DataNode::New(); + m_Ei = mitk::DataInteractor::New(); + m_Ei2 = mitk::DataInteractor::New(); + m_Renderer->SetDataStorage(m_Ds); + } + + void tearDown() + { + m_RenWin->Delete(); + m_Renderer = nullptr; + m_Ds = nullptr; + m_Dn = nullptr; + m_Dn2 = nullptr; + m_Ei = nullptr; + m_Ei2 = nullptr; + } + + void DispatcherExists_Success() + { + CPPUNIT_ASSERT_MESSAGE("01 Check Existence of Dispatcher.", + m_Renderer->GetDispatcher()->GetNumberOfInteractors() == 0); + } + + void AddInteractorConnectedToDataStorage_IncreaseNumberOfInteractors() + { + m_Ei->SetDataNode(m_Dn); + m_Ds->Add(m_Dn); + + CPPUNIT_ASSERT_MESSAGE("02 Expected number of registered Interactors is 1", + m_Renderer->GetDispatcher()->GetNumberOfInteractors() == 1); + } + + void AddDataNodeToInteractor_NoIncreasedNumberOfInteractors() + { + m_Ei->SetDataNode(m_Dn); + m_Renderer->SetDataStorage(m_Ds); + m_Ds->Add(m_Dn); + // This _must not_ result in additionally registered interactors. + m_Ei->SetDataNode(m_Dn); + CPPUNIT_ASSERT_MESSAGE("03 Expected number of registered Interactors is 1", + m_Renderer->GetDispatcher()->GetNumberOfInteractors() == 1); + } + + void AddInteractorNotConnectedToDataStorage_NoRegisteredInteractor() + { + // Switching the DataNode of an Interactor also must not result in extra registered Interactors in Dispatcher + // since dn2 is not connected to DataStorage + m_Ei->SetDataNode(m_Dn2); + + CPPUNIT_ASSERT_MESSAGE("04 Expected number of registered Interactors is 0", + m_Renderer->GetDispatcher()->GetNumberOfInteractors() == 0); + } + + void ConnectInteractorToDataStorage_ReplaceInteractorEntry() + { + m_Ei->SetDataNode(m_Dn2); + // DataNode Added to DataStorage, now Interactor entry in Dispatcher should be replaced, + // hence we restore Interactor in the Dispatcher + m_Ds->Add(m_Dn2); + + CPPUNIT_ASSERT_MESSAGE("05 Expected number of registered Interactors is 1", + m_Renderer->GetDispatcher()->GetNumberOfInteractors() == 1); + } + + void NewDataNodeAndInteractor_IncreasedNumberOfInteractors() + { + m_Ei->SetDataNode(m_Dn2); + m_Ds->Add(m_Dn2); + m_Ds->Add(m_Dn); + // New DataNode and new interactor, this should result in additional Interactor in the Dispatcher. + m_Ei2->SetDataNode(m_Dn); + + CPPUNIT_ASSERT_MESSAGE("06 Exprected number of registered Interactors is 2", + m_Renderer->GetDispatcher()->GetNumberOfInteractors() == 2); + } + + void InteractorsPointToSameDataNode_DecreasedNumberOfInteractors() + { + m_Ds->Add(m_Dn2); + m_Ds->Add(m_Dn); + m_Ei->SetDataNode(m_Dn2); + m_Ei2->SetDataNode(m_Dn); + // Here ei and ei2 point to the same dn2; dn2 now only points to ei2, so ei is abandoned, + // therefore ei1 is expected to be removed + + m_Ei2->SetDataNode(m_Dn2); + CPPUNIT_ASSERT_MESSAGE("07 Expected number of registered Interactors is 1", + m_Renderer->GetDispatcher()->GetNumberOfInteractors() == 1); + } + + void SetDataNodeToNullptr_RemoveInteractor() + { + m_Ds->Add(m_Dn2); + m_Ei2->SetDataNode(m_Dn2); + // Setting DataNode in Interactor to nullptr, should remove Interactor from Dispatcher + m_Ei2->SetDataNode(nullptr); + CPPUNIT_ASSERT_MESSAGE("08 Expected number of registered Interactors is 0", + m_Renderer->GetDispatcher()->GetNumberOfInteractors() == 0); + } + + void RemoveDataNode_RemoveInteractor() + { + // Add DN again check if it is registered + m_Ds->Add(m_Dn); + m_Ei2->SetDataNode(m_Dn); + + CPPUNIT_ASSERT_MESSAGE("09 Expected number of registered Interactors is 1", + m_Renderer->GetDispatcher()->GetNumberOfInteractors() == 1); + + // If DN is removed Interactors should be too + m_Ds->Remove(m_Dn); + CPPUNIT_ASSERT_MESSAGE("10 ExpectedNumber of registered Interactors is 0", + m_Renderer->GetDispatcher()->GetNumberOfInteractors() == 0); + } + + void GetReferenceCountDataNode_Success() + { + m_Ds->Add(m_Dn); + m_Ei2->SetDataNode(m_Dn); + m_Ds->Remove(m_Dn); + // after DN is removed from DS its reference count must be back to one + CPPUNIT_ASSERT_MESSAGE("11 Expected number of references of DataNode is 1", + m_Dn->GetReferenceCount() == 1); + } + + void GetReferenceCountInteractors_Success() + { + m_Ei->SetDataNode(m_Dn2); + m_Ds->Add(m_Dn2); + m_Ei2->SetDataNode(m_Dn2); + CPPUNIT_ASSERT_MESSAGE("12 Expected number of references of Interactors is 1", + m_Ei->GetReferenceCount() == 1); + } +}; +MITK_TEST_SUITE_REGISTRATION(mitkDispatcher) diff --git a/Modules/Core/test/mitkImageGeneratorTest.cpp b/Modules/Core/test/mitkImageGeneratorTest.cpp index aeaed85d9a..8dfd22dea4 100644 --- a/Modules/Core/test/mitkImageGeneratorTest.cpp +++ b/Modules/Core/test/mitkImageGeneratorTest.cpp @@ -1,126 +1,327 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ +// Testing +#include "mitkTestFixture.h" +#include +// MITK includes +#include #include "mitkImage.h" #include "mitkImageGenerator.h" #include "mitkImageReadAccessor.h" #include "mitkImageStatisticsHolder.h" -#include -int mitkImageGeneratorTest(int /*argc*/, char * /*argv*/ []) +class mitkImageGeneratorTestSuite : public mitk::TestFixture { - MITK_TEST_BEGIN("ImageGeneratorTest"); + CPPUNIT_TEST_SUITE(mitkImageGeneratorTestSuite); + MITK_TEST(SetSpacingX2D_Success); + MITK_TEST(SetDefaultSpacingX2D_Success); + MITK_TEST(SetSpacingX3D_Success); + MITK_TEST(SetSpacingY2D_Success); + MITK_TEST(SetDefaultSpacingY2D_Success); + MITK_TEST(SetSpacingY3D_Success); + MITK_TEST(SetSpacingZ2D_Success); + MITK_TEST(SetDefaultSpacingZ2D_Success); + MITK_TEST(SetSpacingZ3D_Success); + MITK_TEST(SetDimension2D_Success); + MITK_TEST(SetDimension3D_Success); + MITK_TEST(SetDimension4D_Success); + MITK_TEST(SetDimensionX2D_Success); + MITK_TEST(SetDimensionY2D_Success); + MITK_TEST(SetDimensionZ3D_Success); + MITK_TEST(SetDimensionT4D_Success); + MITK_TEST(SetDimensions3Dc_Success); + MITK_TEST(SetDataTypeFloat2D_Success); + MITK_TEST(SetDataTypeUChar2D_Success); + MITK_TEST(SetDataTypeInt3D_Success); + MITK_TEST(SetDataTypeDouble3D_Success); + MITK_TEST(SetDataTypeFloat4D_Success); + MITK_TEST(SetDataTypeUChar4D_Success); + MITK_TEST(SetDataTypeUInt3D_Success); + MITK_TEST(SetPixelTypeFloat2D_Success); + MITK_TEST(SetPixelTypeUChar2D_Success); + MITK_TEST(SetPixelTypeInt3D_Success); + MITK_TEST(SetPixelTypeDouble3D_Success); + MITK_TEST(SetPixelTypeFloat4D_Success); + MITK_TEST(SetPixelTypeUChar4D_Success); + MITK_TEST(SetPixelTypeUInt3D_Success); + MITK_TEST(MaxValueHolds_Success); + MITK_TEST(MinValueHolds_Success); + MITK_TEST(DefaultMaxValueHolds_Success); + MITK_TEST(DefaultMinValueHolds_Success); + MITK_TEST(SetGradientImageValues_Success); + CPPUNIT_TEST_SUITE_END(); +private: // create some images with arbitrary parameters (corner cases) - mitk::Image::Pointer image2Da = - mitk::ImageGenerator::GenerateRandomImage(120, 205, 0, 0, 0.1, 0.2, 0.3, 577, 23); - mitk::Image::Pointer image2Db = mitk::ImageGenerator::GenerateRandomImage(1, 1, 0, 0); - mitk::Image::Pointer image3Da = mitk::ImageGenerator::GenerateRandomImage(512, 205, 1, 0); - mitk::Image::Pointer image3Db = mitk::ImageGenerator::GenerateRandomImage(512, 532, 112, 0); - mitk::Image::Pointer image4Da = mitk::ImageGenerator::GenerateRandomImage(120, 205, 78, 1); - mitk::Image::Pointer image4Db = mitk::ImageGenerator::GenerateRandomImage(550, 33, 78, 150); - - mitk::Image::Pointer image3Dc = mitk::ImageGenerator::GenerateGradientImage(1, 2, 3, 4, 5, 6); - - MITK_TEST_CONDITION_REQUIRED(fabs(image2Da->GetGeometry()->GetSpacing()[0] - 0.1) < 0.0001, - "Testing if spacing x is set correctly."); - MITK_TEST_CONDITION_REQUIRED(fabs(image2Da->GetGeometry()->GetSpacing()[1] - 0.2) < 0.0001, - "Testing if spacing y is set correctly."); - MITK_TEST_CONDITION_REQUIRED(fabs(image2Da->GetGeometry()->GetSpacing()[2] - 0.3) < 0.0001, - "Testing if spacing z is set correctly."); - - MITK_TEST_CONDITION_REQUIRED(fabs(image2Db->GetGeometry()->GetSpacing()[0] - 1.0) < 0.0001, - "Testing if default spacing x is set correctly."); - MITK_TEST_CONDITION_REQUIRED(fabs(image2Db->GetGeometry()->GetSpacing()[1] - 1.0) < 0.0001, - "Testing if default spacing y is set correctly."); - MITK_TEST_CONDITION_REQUIRED(fabs(image2Db->GetGeometry()->GetSpacing()[2] - 1.0) < 0.0001, - "Testing if default spacing z is set correctly."); - - MITK_TEST_CONDITION_REQUIRED(fabs(image3Dc->GetGeometry()->GetSpacing()[0] - 4) < 0.0001, - "Testing if spacing x is set correctly."); - MITK_TEST_CONDITION_REQUIRED(fabs(image3Dc->GetGeometry()->GetSpacing()[1] - 5) < 0.0001, - "Testing if spacing y is set correctly."); - MITK_TEST_CONDITION_REQUIRED(fabs(image3Dc->GetGeometry()->GetSpacing()[2] - 6) < 0.0001, - "Testing if spacing z is set correctly."); - - MITK_TEST_CONDITION_REQUIRED(image2Da->GetDimension() == 2, "Testing if the dimension is set correctly."); - MITK_TEST_CONDITION_REQUIRED(image2Db->GetDimension() == 2, "Testing if the dimension is set correctly."); - MITK_TEST_CONDITION_REQUIRED(image3Da->GetDimension() == 2, "Testing if the dimension is set correctly."); - MITK_TEST_CONDITION_REQUIRED(image3Db->GetDimension() == 3, "Testing if the dimension is set correctly."); - MITK_TEST_CONDITION_REQUIRED(image4Da->GetDimension() == 3, "Testing if the dimension is set correctly."); - MITK_TEST_CONDITION_REQUIRED(image4Db->GetDimension() == 4, "Testing if the dimension is set correctly."); - - MITK_TEST_CONDITION_REQUIRED(image2Da->GetDimension(0) == 120, "Testing if the dimensions are set correctly."); - MITK_TEST_CONDITION_REQUIRED(image2Db->GetDimension(1) == 1, "Testing if the dimensions are set correctly."); - MITK_TEST_CONDITION_REQUIRED(image3Da->GetDimension(2) == 1, "Testing if the dimensions are set correctly."); - MITK_TEST_CONDITION_REQUIRED(image3Db->GetDimension(2) == 112, "Testing if the dimensions are set correctly."); - MITK_TEST_CONDITION_REQUIRED(image4Da->GetDimension(3) == 1, "Testing if the dimensions are set correctly."); - MITK_TEST_CONDITION_REQUIRED(image4Db->GetDimension(3) == 150, "Testing if the dimensions are set correctly."); - - MITK_TEST_CONDITION_REQUIRED(image3Dc->GetDimension(0) == 1, "Testing if image3Dc dimension x is set correctly."); - MITK_TEST_CONDITION_REQUIRED(image3Dc->GetDimension(1) == 2, "Testing if image3Dc dimension y is set correctly."); - MITK_TEST_CONDITION_REQUIRED(image3Dc->GetDimension(2) == 3, "Testing if image3Dc dimension z is set correctly."); - - itk::ImageIOBase::IOPixelType scalarType = itk::ImageIOBase::SCALAR; - - MITK_TEST_CONDITION_REQUIRED(image2Da->GetPixelType().GetComponentType() == itk::ImageIOBase::FLOAT, - "Testing if the data type is set correctly."); - MITK_TEST_CONDITION_REQUIRED(image2Da->GetPixelType().GetPixelType() == scalarType, - "Testing if the pixel type is set correctly."); - MITK_TEST_CONDITION_REQUIRED(image2Db->GetPixelType().GetComponentType() == itk::ImageIOBase::UCHAR, - "Testing if the data type is set correctly."); - MITK_TEST_CONDITION_REQUIRED(image2Db->GetPixelType().GetPixelType() == scalarType, - "Testing if the data type is set correctly."); - MITK_TEST_CONDITION_REQUIRED(image3Da->GetPixelType().GetComponentType() == itk::ImageIOBase::INT, - "Testing if the data type is set correctly."); - MITK_TEST_CONDITION_REQUIRED(image3Da->GetPixelType().GetPixelType() == scalarType, - "Testing if the pixel type is set correctly."); - MITK_TEST_CONDITION_REQUIRED(image3Db->GetPixelType().GetComponentType() == itk::ImageIOBase::DOUBLE, - "Testing if the data type is set correctly."); - MITK_TEST_CONDITION_REQUIRED(image3Db->GetPixelType().GetPixelType() == scalarType, - "Testing if the pixel type is set correctly."); - MITK_TEST_CONDITION_REQUIRED(image4Da->GetPixelType().GetComponentType() == itk::ImageIOBase::FLOAT, - "Testing if the data type is set correctly."); - MITK_TEST_CONDITION_REQUIRED(image4Da->GetPixelType().GetPixelType() == scalarType, - "Testing if the pixel type is set correctly."); - MITK_TEST_CONDITION_REQUIRED(image4Db->GetPixelType().GetComponentType() == itk::ImageIOBase::UCHAR, - "Testing if the data type is set correctly."); - MITK_TEST_CONDITION_REQUIRED(image4Db->GetPixelType().GetPixelType() == scalarType, - "Testing if the pixel type is set correctly."); - MITK_TEST_CONDITION_REQUIRED(image3Dc->GetPixelType().GetComponentType() == itk::ImageIOBase::UINT, - "Testing if the data type is set correctly."); - MITK_TEST_CONDITION_REQUIRED(image3Dc->GetPixelType().GetPixelType() == scalarType, - "Testing if the pixel type is set correctly."); - - MITK_TEST_CONDITION_REQUIRED(image2Da->GetStatistics()->GetScalarValueMax() <= 577, "Testing if max value holds"); - MITK_TEST_CONDITION_REQUIRED(image2Da->GetStatistics()->GetScalarValueMin() >= 23, "Testing if min value holds"); - - MITK_TEST_CONDITION_REQUIRED(image3Da->GetStatistics()->GetScalarValueMax() <= 1000, "Testing if max value holds"); - MITK_TEST_CONDITION_REQUIRED(image3Da->GetStatistics()->GetScalarValueMin() >= 0, "Testing if min value holds"); - - const unsigned int *image3DcBuffer = nullptr; - try - { - mitk::ImageReadAccessor readAccess(image3Dc); - image3DcBuffer = static_cast(readAccess.GetData()); - } - catch (...) - { - MITK_ERROR << "Read access not granted on mitk::Image."; - } - for (unsigned int i = 0; i < 2 * 3; i++) - { - MITK_TEST_CONDITION_REQUIRED(image3DcBuffer[i] == i, "Testing if gradient image values are set correctly"); - } - - MITK_TEST_END(); -} + mitk::Image::Pointer m_Image2Da; + mitk::Image::Pointer m_Image2Db; + mitk::Image::Pointer m_Image3Da; + mitk::Image::Pointer m_Image3Db; + mitk::Image::Pointer m_Image4Da; + mitk::Image::Pointer m_Image4Db; + mitk::Image::Pointer m_Image3Dc; + +public: + void setUp() + { + m_Image2Da = mitk::ImageGenerator::GenerateRandomImage(120, 205, 0, 0, 0.1, 0.2, 0.3, 577, 23); + m_Image2Db = mitk::ImageGenerator::GenerateRandomImage(1, 1, 0, 0); + m_Image3Da = mitk::ImageGenerator::GenerateRandomImage(512, 205, 1, 0); + m_Image3Db = mitk::ImageGenerator::GenerateRandomImage(512, 532, 112, 0); + m_Image4Da = mitk::ImageGenerator::GenerateRandomImage(120, 205, 78, 1); + m_Image4Db = mitk::ImageGenerator::GenerateRandomImage(550, 33, 78, 150); + m_Image3Dc = mitk::ImageGenerator::GenerateGradientImage(1, 2, 3, 4, 5, 6); + } + void tearDown() + { + m_Image2Da = nullptr; + m_Image2Db = nullptr; + m_Image3Da = nullptr; + m_Image3Db = nullptr; + m_Image4Da = nullptr; + m_Image4Db = nullptr; + m_Image3Dc = nullptr; + } + + void SetSpacingX2D_Success() + { + CPPUNIT_ASSERT_MESSAGE("Testing if spacing 2D x is set correctly.", + fabs(m_Image2Da->GetGeometry()->GetSpacing()[0] - 0.1) < 0.0001); + } + + void SetDefaultSpacingX2D_Success() + { + CPPUNIT_ASSERT_MESSAGE("Testing if default spacing 2D x is set correctly.", + fabs(m_Image2Db->GetGeometry()->GetSpacing()[0] - 1.0) < 0.0001); + } + + void SetSpacingX3D_Success() + { + CPPUNIT_ASSERT_MESSAGE("Testing if spacing 3D x is set correctly.", + fabs(m_Image3Dc->GetGeometry()->GetSpacing()[0] - 4) < 0.0001); + } + + void SetSpacingY2D_Success() + { + CPPUNIT_ASSERT_MESSAGE("Testing if spacing 2D y is set correctly.", + fabs(m_Image2Da->GetGeometry()->GetSpacing()[1] - 0.2) < 0.0001); + } + + void SetDefaultSpacingY2D_Success() + { + CPPUNIT_ASSERT_MESSAGE("Testing if default spacing 2D y is set correctly.", + fabs(m_Image2Db->GetGeometry()->GetSpacing()[1] - 1.0) < 0.0001); + } + + void SetSpacingY3D_Success() + { + CPPUNIT_ASSERT_MESSAGE("Testing if spacing 3D y is set correctly.", + fabs(m_Image3Dc->GetGeometry()->GetSpacing()[1] - 5) < 0.0001); + } + + void SetSpacingZ2D_Success() + { + CPPUNIT_ASSERT_MESSAGE("Testing if spacing 2D z is set correctly.", + fabs(m_Image2Da->GetGeometry()->GetSpacing()[2] - 0.3) < 0.0001); + } + + void SetDefaultSpacingZ2D_Success() + { + CPPUNIT_ASSERT_MESSAGE("Testing if default spacing 2D z is set correctly.", + fabs(m_Image2Db->GetGeometry()->GetSpacing()[2] - 1.0) < 0.0001); + } + + void SetSpacingZ3D_Success() + { + CPPUNIT_ASSERT_MESSAGE("Testing if spacing z is set correctly.", + fabs(m_Image3Dc->GetGeometry()->GetSpacing()[2] - 6) < 0.0001); + } + + void SetDimension2D_Success() + { + CPPUNIT_ASSERT_MESSAGE("Testing if the dimension 2D is set correctly.", m_Image2Da->GetDimension() == 2); + CPPUNIT_ASSERT_MESSAGE("Testing if the dimension 2D is set correctly.", m_Image2Db->GetDimension() == 2); + } + + void SetDimension3D_Success() + { + CPPUNIT_ASSERT_MESSAGE("Testing if the dimension 3D is set correctly.",m_Image3Da->GetDimension() == 2); + CPPUNIT_ASSERT_MESSAGE("Testing if the dimension 3D is set correctly.", m_Image3Db->GetDimension() == 3); + } + + void SetDimension4D_Success() + { + CPPUNIT_ASSERT_MESSAGE("Testing if the dimension 4D is set correctly.", m_Image4Da->GetDimension() == 3); + CPPUNIT_ASSERT_MESSAGE("Testing if the dimension 4D is set correctly.", m_Image4Db->GetDimension() == 4); + } + + void SetDimensionX2D_Success() + { + CPPUNIT_ASSERT_MESSAGE("Testing if the X dimension of the 2D image is set correctly.", m_Image2Da->GetDimension(0) == 120); + } + + void SetDimensionY2D_Success() + { + CPPUNIT_ASSERT_MESSAGE("Testing if the Y dimension of the 2D image is set correctly.", m_Image2Db->GetDimension(1) == 1); + } + + void SetDimensionZ3D_Success() + { + CPPUNIT_ASSERT_MESSAGE("Testing if the Z dimension of the 3D image is set correctly.", m_Image3Da->GetDimension(2) == 1); + CPPUNIT_ASSERT_MESSAGE("Testing if the Z dimension of the 3D image is set correctly.", m_Image3Db->GetDimension(2) == 112); + } + + void SetDimensionT4D_Success() + { + CPPUNIT_ASSERT_MESSAGE("Testing if the T dimension of the 4D image is set correctly.", m_Image4Da->GetDimension(3) == 1); + CPPUNIT_ASSERT_MESSAGE("Testing if the T dimension of the 4D image is set correctly.", m_Image4Db->GetDimension(3) == 150); + } + + void SetDimensions3Dc_Success() + { + CPPUNIT_ASSERT_MESSAGE("Testing if image3Dc dimension x is set correctly.", m_Image3Dc->GetDimension(0) == 1); + CPPUNIT_ASSERT_MESSAGE("Testing if image3Dc dimension y is set correctly.", m_Image3Dc->GetDimension(1) == 2); + CPPUNIT_ASSERT_MESSAGE("Testing if image3Dc dimension z is set correctly.", m_Image3Dc->GetDimension(2) == 3); + } + + void SetDataTypeFloat2D_Success() + { + CPPUNIT_ASSERT_MESSAGE("Testing if the data type for a float 3D image is set correctly.", + m_Image2Da->GetPixelType().GetComponentType() == itk::ImageIOBase::FLOAT); + } + + void SetDataTypeUChar2D_Success() + { + CPPUNIT_ASSERT_MESSAGE("Testing if the data type for a UChar 2D image is set correctly.", + m_Image2Db->GetPixelType().GetComponentType() == itk::ImageIOBase::UCHAR); + } + + void SetDataTypeInt3D_Success() + { + CPPUNIT_ASSERT_MESSAGE("Testing if the data type for a Int 3D image is set correctly.", + m_Image3Da->GetPixelType().GetComponentType() == itk::ImageIOBase::INT); + } + + void SetDataTypeDouble3D_Success() + { + CPPUNIT_ASSERT_MESSAGE("Testing if the data type for a Double 3D image is set correctly.", + m_Image3Db->GetPixelType().GetComponentType() == itk::ImageIOBase::DOUBLE); + } + + void SetDataTypeFloat4D_Success() + { + CPPUNIT_ASSERT_MESSAGE("Testing if the data type for a Float 4D image is set correctly.", + m_Image4Da->GetPixelType().GetComponentType() == itk::ImageIOBase::FLOAT); + } + + void SetDataTypeUChar4D_Success() + { + CPPUNIT_ASSERT_MESSAGE("Testing if the data type for a UChar 4D image is set correctly.", + m_Image4Db->GetPixelType().GetComponentType() == itk::ImageIOBase::UCHAR); + } + + void SetDataTypeUInt3D_Success() + { + CPPUNIT_ASSERT_MESSAGE("Testing if the data type for a UInt 3D image is set correctly.", + m_Image3Dc->GetPixelType().GetComponentType() == itk::ImageIOBase::UINT); + } + + void SetPixelTypeFloat2D_Success() + { + itk::ImageIOBase::IOPixelType scalarType = itk::ImageIOBase::SCALAR; + CPPUNIT_ASSERT_MESSAGE("Testing if the pixel type for a Float 2D image is set correctly.", + m_Image2Da->GetPixelType().GetPixelType() == scalarType); + } + + void SetPixelTypeUChar2D_Success() + { + itk::ImageIOBase::IOPixelType scalarType = itk::ImageIOBase::SCALAR; + CPPUNIT_ASSERT_MESSAGE("Testing if the pixel type for a UChar 2D image is set correctly.", + m_Image2Db->GetPixelType().GetPixelType() == scalarType); + } + + void SetPixelTypeInt3D_Success() + { + itk::ImageIOBase::IOPixelType scalarType = itk::ImageIOBase::SCALAR; + CPPUNIT_ASSERT_MESSAGE("Testing if the pixel type for a Int 3D image is set correctly.", + m_Image3Da->GetPixelType().GetPixelType() == scalarType); + } + + void SetPixelTypeDouble3D_Success() + { + itk::ImageIOBase::IOPixelType scalarType = itk::ImageIOBase::SCALAR; + CPPUNIT_ASSERT_MESSAGE("Testing if the pixel type for a Double 3D image is set correctly.", + m_Image3Db->GetPixelType().GetPixelType() == scalarType); + } + + void SetPixelTypeFloat4D_Success() + { + itk::ImageIOBase::IOPixelType scalarType = itk::ImageIOBase::SCALAR; + CPPUNIT_ASSERT_MESSAGE("Testing if the pixel type for a Float 4D image is set correctly.", + m_Image4Da->GetPixelType().GetPixelType() == scalarType); + } + + void SetPixelTypeUChar4D_Success() + { + itk::ImageIOBase::IOPixelType scalarType = itk::ImageIOBase::SCALAR; + CPPUNIT_ASSERT_MESSAGE("Testing if the pixel type for a UChar 4D image is set correctly.", + m_Image4Db->GetPixelType().GetPixelType() == scalarType); + } + + void SetPixelTypeUInt3D_Success() + { + itk::ImageIOBase::IOPixelType scalarType = itk::ImageIOBase::SCALAR; + CPPUNIT_ASSERT_MESSAGE("Testing if the pixel type for a UInt 3D image is set correctly.", + m_Image3Dc->GetPixelType().GetPixelType() == scalarType); + } + + void MaxValueHolds_Success() + { + CPPUNIT_ASSERT_MESSAGE("Testing if max value holds", m_Image2Da->GetStatistics()->GetScalarValueMax() <= 577); + } + + void MinValueHolds_Success() + { + CPPUNIT_ASSERT_MESSAGE("Testing if min value holds", m_Image2Da->GetStatistics()->GetScalarValueMin() >= 23); + } + + void DefaultMaxValueHolds_Success() + { + CPPUNIT_ASSERT_MESSAGE("Testing if default max value holds", m_Image3Da->GetStatistics()->GetScalarValueMax() <= 1000); + } + + void DefaultMinValueHolds_Success() + { + CPPUNIT_ASSERT_MESSAGE("Testing if default min value holds", m_Image3Da->GetStatistics()->GetScalarValueMin() >= 0); + } + + void SetGradientImageValues_Success() + { + const unsigned int *image3DcBuffer = nullptr; + try + { + mitk::ImageReadAccessor readAccess(m_Image3Dc); + image3DcBuffer = static_cast(readAccess.GetData()); + } + catch (...) + { + MITK_ERROR << "Read access not granted on mitk::Image."; + } + for (unsigned int i = 0; i < 2 * 3; i++) + { + CPPUNIT_ASSERT_MESSAGE("Testing if gradient image values are set correctly", image3DcBuffer[i] == i); + } + } +}; +MITK_TEST_SUITE_REGISTRATION(mitkImageGenerator) + diff --git a/Modules/Core/test/mitkInteractionEventTest.cpp b/Modules/Core/test/mitkInteractionEventTest.cpp index a042082ce0..ce740a3a7e 100644 --- a/Modules/Core/test/mitkInteractionEventTest.cpp +++ b/Modules/Core/test/mitkInteractionEventTest.cpp @@ -1,89 +1,116 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ +// Testing +#include "mitkTestFixture.h" +#include "mitkTestingMacros.h" +// MITK includes +#include #include "mitkInteractionEventConst.h" #include "mitkMouseMoveEvent.h" #include "mitkMousePressEvent.h" #include "mitkMouseReleaseEvent.h" -#include "mitkTestingMacros.h" +// VTK includes #include "mitkVtkPropRenderer.h" -int mitkInteractionEventTest(int /*argc*/, char * /*argv*/ []) +class mitkInteractionEventTestSuite : public mitk::TestFixture { - /* - * Create different Events, fill them with data. - * And check if isEqual method is implemented properly. - */ - MITK_TEST_BEGIN("InteractionEvent") - - mitk::VtkPropRenderer::Pointer renderer = nullptr; - - mitk::InteractionEvent::MouseButtons buttonStates = - mitk::InteractionEvent::LeftMouseButton | mitk::InteractionEvent::RightMouseButton; - mitk::InteractionEvent::MouseButtons eventButton = mitk::InteractionEvent::LeftMouseButton; - mitk::InteractionEvent::ModifierKeys modifiers = mitk::InteractionEvent::ControlKey | mitk::InteractionEvent::AltKey; - - mitk::Point2D point; - point[0] = 17; - point[1] = 170; - - mitk::Point3D worldPos; - worldPos[0] = 0.5; - worldPos[1] = 10.609; - worldPos[2] = 5.0; - - // MousePress Events - mitk::MousePressEvent::Pointer me1 = - mitk::MousePressEvent::New(renderer, point, buttonStates, modifiers, eventButton); - mitk::MousePressEvent::Pointer me2 = - mitk::MousePressEvent::New(renderer, point, buttonStates, modifiers, eventButton); - point[0] = 178; - point[1] = 170; - mitk::MousePressEvent::Pointer me3 = - mitk::MousePressEvent::New(renderer, point, buttonStates, modifiers, eventButton); - modifiers = mitk::InteractionEvent::ControlKey; - mitk::MousePressEvent::Pointer me4 = - mitk::MousePressEvent::New(renderer, point, buttonStates, modifiers, eventButton); - - MITK_TEST_CONDITION_REQUIRED(*me1 == *me2 && *me1 == *me3 && *me2 == *me3 && *me3 != *me4, - "Checking isEqual and Constructors of mitk::InteractionEvent, mitk::MousePressEvent"); - - // MouseReleaseEvents - mitk::MouseReleaseEvent::Pointer mr1 = - mitk::MouseReleaseEvent::New(renderer, point, buttonStates, modifiers, eventButton); - mitk::MouseReleaseEvent::Pointer mr2 = - mitk::MouseReleaseEvent::New(renderer, point, buttonStates, modifiers, eventButton); - point[0] = 178; - point[1] = 170; - mitk::MouseReleaseEvent::Pointer mr3 = - mitk::MouseReleaseEvent::New(renderer, point, buttonStates, modifiers, eventButton); - eventButton = mitk::InteractionEvent::RightMouseButton; - mitk::MouseReleaseEvent::Pointer mr4 = - mitk::MouseReleaseEvent::New(renderer, point, buttonStates, modifiers, eventButton); - - MITK_TEST_CONDITION_REQUIRED(*mr1 == *mr2 && *mr1 == *mr3 && *mr2 == *mr3 && *mr3 != *mr4, - "Checking isEqual and Constructors of mitk::InteractionEvent, mitk::MouseReleaseEvent"); - - // MouseMoveEvents - mitk::MouseMoveEvent::Pointer mm1 = mitk::MouseMoveEvent::New(renderer, point, buttonStates, modifiers); - point[0] = 178; - point[1] = 170; - mitk::MouseMoveEvent::Pointer mm3 = mitk::MouseMoveEvent::New(renderer, point, buttonStates, modifiers); - modifiers = mitk::InteractionEvent::AltKey; - mitk::MouseMoveEvent::Pointer mm4 = mitk::MouseMoveEvent::New(renderer, point, buttonStates, modifiers); - - MITK_TEST_CONDITION_REQUIRED(*mm1 == *mm3 && *mm3 != *mm4, - "Checking isEqual and Constructors of mitk::InteractionEvent, mitk::MouseMoveEvent"); - - // always end with this! - MITK_TEST_END() -} + CPPUNIT_TEST_SUITE(mitkInteractionEventTestSuite); + MITK_TEST(MousePressEvent_Success); + MITK_TEST(MouseReleaseEvent_Success); + MITK_TEST(MouseMoveEvent_Success); + CPPUNIT_TEST_SUITE_END(); + +private: + mitk::VtkPropRenderer::Pointer m_Renderer; + + mitk::InteractionEvent::MouseButtons m_ButtonStates; + mitk::InteractionEvent::MouseButtons m_EventButton; + mitk::InteractionEvent::ModifierKeys m_Modifiers; + + mitk::Point2D m_Point; + + mitk::Point3D m_WorldPos; + +public: + void setUp() + { + m_Renderer = nullptr; + m_ButtonStates = mitk::InteractionEvent::LeftMouseButton | mitk::InteractionEvent::RightMouseButton; + m_EventButton = mitk::InteractionEvent::LeftMouseButton; + m_Modifiers = mitk::InteractionEvent::ControlKey | mitk::InteractionEvent::AltKey; + + m_Point[0] = 17; + m_Point[1] = 170; + + m_WorldPos[0] = 0.5; + m_WorldPos[1] = 10.609; + m_WorldPos[2] = 5.0; + } + void tearDown() + { + } + + void MousePressEvent_Success() + { + // MousePress Events + mitk::MousePressEvent::Pointer me1 = + mitk::MousePressEvent::New(m_Renderer, m_Point, m_ButtonStates, m_Modifiers, m_EventButton); + mitk::MousePressEvent::Pointer me2 = + mitk::MousePressEvent::New(m_Renderer, m_Point, m_ButtonStates, m_Modifiers, m_EventButton); + m_Point[0] = 178; + m_Point[1] = 170; + mitk::MousePressEvent::Pointer me3 = + mitk::MousePressEvent::New(m_Renderer, m_Point, m_ButtonStates, m_Modifiers, m_EventButton); + m_Modifiers = mitk::InteractionEvent::ControlKey; + mitk::MousePressEvent::Pointer me4 = + mitk::MousePressEvent::New(m_Renderer, m_Point, m_ButtonStates, m_Modifiers, m_EventButton); + + CPPUNIT_ASSERT_MESSAGE("Checking isEqual and Constructors of mitk::InteractionEvent, mitk::MousePressEvent", + *me1 == *me2 && *me1 == *me3 && *me2 == *me3 && *me3 != *me4); + } + + void MouseReleaseEvent_Success() + { + // MouseReleaseEvents + mitk::MouseReleaseEvent::Pointer mr1 = + mitk::MouseReleaseEvent::New(m_Renderer, m_Point, m_ButtonStates, m_Modifiers, m_EventButton); + mitk::MouseReleaseEvent::Pointer mr2 = + mitk::MouseReleaseEvent::New(m_Renderer, m_Point, m_ButtonStates, m_Modifiers, m_EventButton); + m_Point[0] = 178; + m_Point[1] = 170; + mitk::MouseReleaseEvent::Pointer mr3 = + mitk::MouseReleaseEvent::New(m_Renderer, m_Point, m_ButtonStates, m_Modifiers, m_EventButton); + m_EventButton = mitk::InteractionEvent::RightMouseButton; + mitk::MouseReleaseEvent::Pointer mr4 = + mitk::MouseReleaseEvent::New(m_Renderer, m_Point, m_ButtonStates, m_Modifiers, m_EventButton); + + CPPUNIT_ASSERT_MESSAGE("Checking isEqual and Constructors of mitk::InteractionEvent, mitk::MouseReleaseEvent", + *mr1 == *mr2 && *mr1 == *mr3 && *mr2 == *mr3 && *mr3 != *mr4); + } + + void MouseMoveEvent_Success() + { + // MouseMoveEvents + mitk::MouseMoveEvent::Pointer mm1 = mitk::MouseMoveEvent::New(m_Renderer, m_Point, m_ButtonStates, m_Modifiers); + m_Point[0] = 178; + m_Point[1] = 170; + mitk::MouseMoveEvent::Pointer mm3 = mitk::MouseMoveEvent::New(m_Renderer, m_Point, m_ButtonStates, m_Modifiers); + m_Modifiers = mitk::InteractionEvent::AltKey; + mitk::MouseMoveEvent::Pointer mm4 = mitk::MouseMoveEvent::New(m_Renderer, m_Point, m_ButtonStates, m_Modifiers); + + CPPUNIT_ASSERT_MESSAGE("Checking isEqual and Constructors of mitk::InteractionEvent, mitk::MouseMoveEvent", + *mm1 == *mm3 && *mm3 != *mm4); + } + +}; +MITK_TEST_SUITE_REGISTRATION(mitkInteractionEvent) diff --git a/Modules/Core/test/mitkPixelTypeTest.cpp b/Modules/Core/test/mitkPixelTypeTest.cpp index a5596f9451..0df8ef5104 100644 --- a/Modules/Core/test/mitkPixelTypeTest.cpp +++ b/Modules/Core/test/mitkPixelTypeTest.cpp @@ -1,150 +1,241 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ -#include "mitkPixelType.h" +// Testing +#include "mitkTestFixture.h" #include "mitkTestingMacros.h" -#include +// std includes +#include +// MITK includes +#include "mitkPixelType.h" #include - +// ITK includes +#include "itkImage.h" #include +// VTK includes +#include struct MyObscurePixelType { typedef float ValueType; static const size_t Length = 2; }; //## Documentation //## main testing method -int mitkPixelTypeTest(int /*argc*/, char * /*argv*/ []) +class mitkPixelTypeTestSuite : public mitk::TestFixture { - MITK_TEST_BEGIN("PixelTypeTest"); - - MITK_INFO << "ptype = mitk::MakePixelType();"; - MITK_INFO - << "itkPtype = mitk::MakePixelType();\n with itk::Image, 3> ItkImageType"; - - mitk::PixelType ptype = mitk::MakePixelType(); + CPPUNIT_TEST_SUITE(mitkPixelTypeTestSuite); + + MITK_TEST(GetComponentType_Success); + MITK_TEST(GetPixelTypeAsString_Success); + MITK_TEST(GetBpePtype_Success); + MITK_TEST(GetNumberOfComponentsPtype_Success); + MITK_TEST(GetBitsPerComponentPtype_Success); + MITK_TEST(GetBpeItkPtype_Success); + MITK_TEST(GetNumberOfComponentsItkPtype_Success); + MITK_TEST(GetBitsPerComponentItkPtype_Success); + MITK_TEST(ConstructorWithBrackets_Success); + MITK_TEST(InitializeWithEqualSign_Success); + MITK_TEST(EqualityOperator_Success); + MITK_TEST(NotEqualityOperator_Success); + MITK_TEST(GetPixelTypeUnknown_Success); + MITK_TEST(SetLengthCorrectly_Success); + MITK_TEST(ValueTypeCorresponds_Success); + MITK_TEST(ImageTypeTraitInt3D_Success); + MITK_TEST(ImageTypeTraitShort2D_Success); + MITK_TEST(ImageTypeTraitVectorShort3D_Success); + MITK_TEST(ImageTypeTraitItkInt3D_Success); + MITK_TEST(ImageTypeTraitItkShort2D_Success); + MITK_TEST(ImageTypeTraitItkVectorShort3D_Success); + + CPPUNIT_TEST_SUITE_END(); + +private: typedef itk::Image, 3> ItkImageType; - mitk::PixelType itkPtype = mitk::MakePixelType(); - - MITK_TEST_CONDITION_REQUIRED(ptype.GetComponentType() == itk::ImageIOBase::INT, "GetComponentType()"); - // MITK_TEST_CONDITION( ptype.GetPixelTypeId() == typeid(ItkImageType), "GetPixelTypeId()"); - - MITK_INFO << ptype.GetPixelTypeAsString(); - MITK_INFO << typeid(ItkImageType).name(); - - MITK_TEST_CONDITION_REQUIRED(ptype.GetBpe() == 8 * sizeof(int) * 5, "[ptype] GetBpe()"); - MITK_TEST_CONDITION_REQUIRED(ptype.GetNumberOfComponents() == 5, "[ptype]GetNumberOfComponents()"); - MITK_TEST_CONDITION_REQUIRED(ptype.GetBitsPerComponent() == 8 * sizeof(int), "[ptype]GetBitsPerComponent()"); - - MITK_TEST_CONDITION_REQUIRED(itkPtype.GetBpe() == 8 * sizeof(int) * 5, "[itkPType] GetBpe()"); - MITK_TEST_CONDITION_REQUIRED(itkPtype.GetNumberOfComponents() == 5, "[itkPType] GetNumberOfComponents()"); - MITK_TEST_CONDITION_REQUIRED(itkPtype.GetBitsPerComponent() == 8 * sizeof(int), "[itkPType] GetBitsPerComponent()"); - - // MITK_TEST_CONDITION_REQUIRED( itkPtype == ptype, "[itkPtype = ptype]"); - - // MITK_TEST_CONDITION( ptype.GetPixelTypeAsString().compare("unknown") == 0, "GetPixelTypeAsString()"); - { - { - mitk::PixelType ptype2(ptype); - MITK_TEST_CONDITION_REQUIRED(ptype2.GetComponentType() == itk::ImageIOBase::INT, - "ptype2( ptype)- GetComponentType()"); - MITK_TEST_CONDITION(ptype2.GetPixelType() == ptype.GetPixelType(), "ptype2( ptype)-GetPixelType("); - MITK_TEST_CONDITION(ptype2.GetComponentType() == ptype.GetComponentType(), "ptype2( ptype)-GetComponentType("); - MITK_TEST_CONDITION_REQUIRED(ptype2.GetBpe() == 8 * sizeof(int) * 5, "ptype2( ptype)-GetBpe()"); - MITK_TEST_CONDITION_REQUIRED(ptype2.GetNumberOfComponents() == 5, "ptype2( ptype)-GetNumberOfComponents()"); - MITK_TEST_CONDITION_REQUIRED(ptype2.GetBitsPerComponent() == 8 * sizeof(int), - "ptype2( ptype)-GetBitsPerComponent()"); - // MITK_TEST_CONDITION_REQUIRED( ptype.GetPixelTypeAsString().compare("unknown") == 0, "ptype2( - // ptype)-GetPixelTypeAsString()"); - } - - { - mitk::PixelType ptype2 = ptype; - MITK_TEST_CONDITION_REQUIRED(ptype2.GetComponentType() == itk::ImageIOBase::INT, - "ptype2 = ptype- GetComponentType()"); - MITK_TEST_CONDITION(ptype2.GetPixelType() == ptype.GetPixelType(), "ptype2 = ptype- GetPixelType("); - MITK_TEST_CONDITION(ptype2.GetComponentType() == ptype.GetComponentType(), "ptype2( ptype)-GetComponentType("); - MITK_TEST_CONDITION_REQUIRED(ptype2.GetBpe() == 8 * sizeof(int) * 5, "ptype2 = ptype- GetBpe()"); - MITK_TEST_CONDITION_REQUIRED(ptype2.GetNumberOfComponents() == 5, "ptype2 = ptype- GetNumberOfComponents()"); - MITK_TEST_CONDITION_REQUIRED(ptype2.GetBitsPerComponent() == 8 * sizeof(int), - "ptype2 = ptype- GetBitsPerComponent()"); - // MITK_TEST_CONDITION_REQUIRED( ptype.GetPixelTypeAsString().compare("unknown") == 0, "ptype2 = ptype- - // GetPixelTypeAsString()"); - } - - { - mitk::PixelType ptype2 = ptype; - MITK_TEST_CONDITION_REQUIRED(ptype == ptype2, "operator =="); - // MITK_TEST_CONDITION_REQUIRED( ptype == typeid(int), "operator =="); - // mitk::PixelType ptype3 = mitk::MakePixelType; - // MITK_TEST_CONDITION_REQUIRED( ptype != ptype3, "operator !="); - // MITK_TEST_CONDITION_REQUIRED( *ptype3 != typeid(int), "operator !="); - } - } - - // test instantiation typedef itk::Image MyObscureImageType; - mitk::PixelType obscurePixelType = mitk::MakePixelType(); + typedef itk::VectorImage VectorImageType; + typedef itk::Image> FixedVectorImageType; - MITK_TEST_CONDITION(obscurePixelType.GetPixelType() == itk::ImageIOBase::UNKNOWNPIXELTYPE, - "PixelTypeId is 'UNKNOWN' "); - MITK_TEST_CONDITION(obscurePixelType.GetNumberOfComponents() == MyObscurePixelType::Length, - "Lenght was set correctly"); - MITK_TEST_CONDITION( - obscurePixelType.GetComponentType() == mitk::MapPixelComponentType::value, - "ValueType corresponds."); - typedef itk::VectorImage VectorImageType; - mitk::PixelType vectorPixelType = mitk::MakePixelType(78); - // vectorPixelType.SetVectorLength( 78 ); +public: + void setUp() override + { + } - typedef itk::Image> FixedVectorImageType; - mitk::PixelType fixedVectorPixelType = mitk::MakePixelType(); + void tearDown() override + { + } + + void GetComponentType_Success() + { + mitk::PixelType ptype = mitk::MakePixelType(); + MITK_INFO << "m_Ptype = mitk::MakePixelType();"; + MITK_INFO + << "m_ItkPtype = mitk::MakePixelType();\n with itk::Image, 3> ItkImageType"; + CPPUNIT_ASSERT_MESSAGE("GetComponentType()", ptype.GetComponentType() == itk::ImageIOBase::INT); + } + + void GetPixelTypeAsString_Success() + { + mitk::PixelType ptype = mitk::MakePixelType(); + MITK_INFO << ptype.GetPixelTypeAsString(); + MITK_INFO << typeid(ItkImageType).name(); + } + + void GetBpePtype_Success() + { + mitk::PixelType ptype = mitk::MakePixelType(); + CPPUNIT_ASSERT_MESSAGE("[m_Ptype] GetBpe()", ptype.GetBpe() == 8 * sizeof(int) * 5); + } + + void GetNumberOfComponentsPtype_Success() + { + mitk::PixelType ptype = mitk::MakePixelType(); + CPPUNIT_ASSERT_MESSAGE("[ptype]GetNumberOfComponents()", ptype.GetNumberOfComponents() == 5); + } + + void GetBitsPerComponentPtype_Success() + { + mitk::PixelType ptype = mitk::MakePixelType(); + CPPUNIT_ASSERT_MESSAGE("[ptype]GetBitsPerComponent()", ptype.GetBitsPerComponent() == 8 * sizeof(int)); + } + + void GetBpeItkPtype_Success() + { + mitk::PixelType itkPtype = mitk::MakePixelType(); + CPPUNIT_ASSERT_MESSAGE("[itkPType] GetBpe()", itkPtype.GetBpe() == 8 * sizeof(int) * 5); + } + + void GetNumberOfComponentsItkPtype_Success() + { + mitk::PixelType itkPtype = mitk::MakePixelType(); + CPPUNIT_ASSERT_MESSAGE("[itkPType] GetNumberOfComponents()", itkPtype.GetNumberOfComponents() == 5); + } + + void GetBitsPerComponentItkPtype_Success() + { + mitk::PixelType itkPtype = mitk::MakePixelType(); + CPPUNIT_ASSERT_MESSAGE("[itkPType] GetBitsPerComponent()", itkPtype.GetBitsPerComponent() == 8 * sizeof(int)); + } + + void ConstructorWithBrackets_Success() + { + mitk::PixelType ptype = mitk::MakePixelType(); + mitk::PixelType ptype2(ptype); + CPPUNIT_ASSERT_MESSAGE("ptype2( ptype)- GetComponentType()", ptype2.GetComponentType() == itk::ImageIOBase::INT); + CPPUNIT_ASSERT_MESSAGE("ptype2( ptype)-GetPixelType(", ptype2.GetPixelType() == ptype.GetPixelType()); + CPPUNIT_ASSERT_MESSAGE("ptype2( ptype)-GetComponentType(", ptype2.GetComponentType() == ptype.GetComponentType()); + CPPUNIT_ASSERT_MESSAGE("ptype2( ptype)-GetBpe()", ptype2.GetBpe() == 8 * sizeof(int) * 5); + CPPUNIT_ASSERT_MESSAGE("ptype2( ptype)-GetNumberOfComponents()", ptype2.GetNumberOfComponents() == 5); + CPPUNIT_ASSERT_MESSAGE("ptype2( ptype)-GetBitsPerComponent()", ptype2.GetBitsPerComponent() == 8 * sizeof(int)); + } + + void InitializeWithEqualSign_Success() + { + mitk::PixelType ptype = mitk::MakePixelType(); + mitk::PixelType ptype2 = ptype; + CPPUNIT_ASSERT_MESSAGE("ptype2 = ptype- GetComponentType()", ptype2.GetComponentType() == itk::ImageIOBase::INT); + CPPUNIT_ASSERT_MESSAGE("ptype2 = ptype- GetPixelType(", ptype2.GetPixelType() == ptype.GetPixelType()); + CPPUNIT_ASSERT_MESSAGE("ptype2( ptype)-GetComponentType(", ptype2.GetComponentType() == ptype.GetComponentType()); + CPPUNIT_ASSERT_MESSAGE("ptype2 = ptype- GetBpe()", ptype2.GetBpe() == 8 * sizeof(int) * 5); + CPPUNIT_ASSERT_MESSAGE("ptype2 = ptype- GetNumberOfComponents()", ptype2.GetNumberOfComponents() == 5); + CPPUNIT_ASSERT_MESSAGE("ptype2 = ptype- GetBitsPerComponent()", ptype2.GetBitsPerComponent() == 8 * sizeof(int)); + } + + void EqualityOperator_Success() + { + mitk::PixelType ptype = mitk::MakePixelType(); + mitk::PixelType ptype2 = ptype; + CPPUNIT_ASSERT_MESSAGE("operator ==", ptype == ptype2); + } + + void NotEqualityOperator_Success() + { + mitk::PixelType ptype = mitk::MakePixelType(); + mitk::PixelType ptype3 = mitk::MakePixelType(); + CPPUNIT_ASSERT_MESSAGE("operator !=", ptype != ptype3); + } + + void GetPixelTypeUnknown_Success() + { + // test instantiation + mitk::PixelType obscurePixelType = mitk::MakePixelType(); + CPPUNIT_ASSERT_MESSAGE("PixelTypeId is 'UNKNOWN' ", obscurePixelType.GetPixelType() == itk::ImageIOBase::UNKNOWNPIXELTYPE); + } + + void SetLengthCorrectly_Success() + { + mitk::PixelType obscurePixelType = mitk::MakePixelType(); + CPPUNIT_ASSERT_MESSAGE("Lenght was set correctly", obscurePixelType.GetNumberOfComponents() == MyObscurePixelType::Length); + } - mitk::PixelType scalarPixelType = mitk::MakeScalarPixelType(); + void ValueTypeCorresponds_Success() + { + mitk::PixelType obscurePixelType = mitk::MakePixelType(); + CPPUNIT_ASSERT_MESSAGE("ValueType corresponds.", - // test ImageTypeTrait traits class - MITK_TEST_CONDITION(typeid(mitk::ImageTypeTrait::ImageType) == typeid(itk::Image), "ImageTypeTrait"); - MITK_TEST_CONDITION((mitk::ImageTypeTrait::IsVectorImage == false), "ImageTypeTrait"); + obscurePixelType.GetComponentType() == mitk::MapPixelComponentType::value); + } + + void ImageTypeTraitInt3D_Success() + { + // test ImageTypeTrait traits class + CPPUNIT_ASSERT_MESSAGE("ImageTypeTrait typeid int 3D equals ITK typeid", + + typeid(mitk::ImageTypeTrait::ImageType) == typeid(itk::Image)); + CPPUNIT_ASSERT_MESSAGE("ImageTypeTrait is no vector image", (mitk::ImageTypeTrait::IsVectorImage == false)); + } + + void ImageTypeTraitShort2D_Success() + { + CPPUNIT_ASSERT_MESSAGE("ImageTypeTrait typeid short 2D equals ITK typeid", + typeid(mitk::ImageTypeTrait, 3>::ImageType) == + typeid(itk::Image, 3>)); + CPPUNIT_ASSERT_MESSAGE("ImageTypeTrait is no vector image", (mitk::ImageTypeTrait, 3>::IsVectorImage == false)); + } - MITK_TEST_CONDITION(typeid(mitk::ImageTypeTrait, 3>::ImageType) == - typeid(itk::Image, 3>), - "ImageTypeTrait"); - MITK_TEST_CONDITION((mitk::ImageTypeTrait, 3>::IsVectorImage == false), "ImageTypeTrait"); + void ImageTypeTraitVectorShort3D_Success() + { + CPPUNIT_ASSERT_MESSAGE("ImageTypeTrait typeid short 3D equals ITK typeid", + typeid(mitk::ImageTypeTrait, 3>::ImageType) == typeid(itk::VectorImage)); + CPPUNIT_ASSERT_MESSAGE("ImageTypeTrait is a vector image", (mitk::ImageTypeTrait, 3>::IsVectorImage == true)); + } - MITK_TEST_CONDITION( - typeid(mitk::ImageTypeTrait, 3>::ImageType) == typeid(itk::VectorImage), - "ImageTypeTrait"); - MITK_TEST_CONDITION((mitk::ImageTypeTrait, 3>::IsVectorImage == true), - "ImageTypeTrait"); + void ImageTypeTraitItkInt3D_Success() + { + CPPUNIT_ASSERT_MESSAGE("ImageTypeTrait typeid ITK int 3D equals ITK typeid", + typeid(mitk::ImageTypeTrait>::ImageType) == typeid(itk::Image)); + CPPUNIT_ASSERT_MESSAGE("ImageTypeTrait is no vector image", (mitk::ImageTypeTrait>::IsVectorImage == false)); + } - MITK_TEST_CONDITION(typeid(mitk::ImageTypeTrait>::ImageType) == typeid(itk::Image), - "ImageTypeTrait"); - MITK_TEST_CONDITION((mitk::ImageTypeTrait>::IsVectorImage == false), "ImageTypeTrait"); + void ImageTypeTraitItkShort2D_Success() + { + CPPUNIT_ASSERT_MESSAGE("ImageTypeTrait typeid ITK short 2D equals ITK typeid", + typeid(mitk::ImageTypeTrait, 3>>::ImageType) == + typeid(itk::Image, 3>)); + CPPUNIT_ASSERT_MESSAGE("ImageTypeTrait is no vector image", - MITK_TEST_CONDITION(typeid(mitk::ImageTypeTrait, 3>>::ImageType) == - typeid(itk::Image, 3>), - "ImageTypeTrait"); - MITK_TEST_CONDITION((mitk::ImageTypeTrait, 3>>::IsVectorImage == false), - "ImageTypeTrait"); + (mitk::ImageTypeTrait, 3>>::IsVectorImage == false)); + } - MITK_TEST_CONDITION( - typeid(mitk::ImageTypeTrait>::ImageType) == typeid(itk::VectorImage), - "ImageTypeTrait"); - MITK_TEST_CONDITION((mitk::ImageTypeTrait>::IsVectorImage == true), "ImageTypeTrait"); + void ImageTypeTraitItkVectorShort3D_Success() + { + CPPUNIT_ASSERT_MESSAGE("ImageTypeTrait typeid ITK short 3D equals ITK typeid", + typeid(mitk::ImageTypeTrait>::ImageType) == typeid(itk::VectorImage)); + CPPUNIT_ASSERT_MESSAGE("ImageTypeTrait is a vector image", + (mitk::ImageTypeTrait>::IsVectorImage == true)); + } +}; +MITK_TEST_SUITE_REGISTRATION(mitkPixelType) - // test CastableTo - MITK_TEST_END(); -} diff --git a/Modules/Core/test/mitkPropertyAliasesTest.cpp b/Modules/Core/test/mitkPropertyAliasesTest.cpp index 22dd5d8ec0..3188a48066 100644 --- a/Modules/Core/test/mitkPropertyAliasesTest.cpp +++ b/Modules/Core/test/mitkPropertyAliasesTest.cpp @@ -1,63 +1,106 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ +// Testing +#include "mitkTestFixture.h" +#include "mitkTestingMacros.h" +// std includes +#include #include +// MITK includes #include #include -#include +// VTK includes +#include -int mitkPropertyAliasesTest(int, char *[]) +class mitkPropertyAliasesTestSuite : public mitk::TestFixture { - MITK_TEST_BEGIN("mitkPropertyAliasesTest"); - - mitk::IPropertyAliases *propertyAliases = mitk::CoreServices::GetPropertyAliases(); - MITK_TEST_CONDITION_REQUIRED(propertyAliases != nullptr, "Get property aliases service"); - - propertyAliases->AddAlias("propertyName1", "alias1a"); - propertyAliases->AddAlias("propertyName1", "alias1b"); - propertyAliases->AddAlias("propertyName2", "alias2a"); - propertyAliases->AddAlias("propertyName2", "alias2b", "className"); - + CPPUNIT_TEST_SUITE(mitkPropertyAliasesTestSuite); + MITK_TEST(GetPropertyAliasesService_Success); + MITK_TEST(GetAliases_Success); + MITK_TEST(GetAliasesRestricted_Success); + MITK_TEST(GetPropertyName_Success); + MITK_TEST(GetPropertyNameNonexisting_Empty); + MITK_TEST(GetPropertyNameRestricted_Success); + CPPUNIT_TEST_SUITE_END(); + +private: + mitk::IPropertyAliases *m_PropertyAliases; typedef std::vector Aliases; - - Aliases aliases = propertyAliases->GetAliases("propertyName1"); - auto it1 = std::find(aliases.begin(), aliases.end(), "alias1a"); - auto it2 = std::find(aliases.begin(), aliases.end(), "alias1b"); - - MITK_TEST_CONDITION(aliases.size() == 2 && it1 != aliases.end() && it2 != aliases.end(), - "Get aliases of \"propertyName1\""); - - aliases = propertyAliases->GetAliases("propertyName2"); - it1 = std::find(aliases.begin(), aliases.end(), "alias2a"); - - MITK_TEST_CONDITION(aliases.size() == 1 && it1 != aliases.end(), "Get aliases of \"propertyName2\""); - - aliases = propertyAliases->GetAliases("propertyName2", "className"); - it1 = std::find(aliases.begin(), aliases.end(), "alias2b"); - - MITK_TEST_CONDITION(aliases.size() == 1 && it1 != aliases.end(), - "Get aliases of \"propertyName2\" restricted to \"className\""); - - std::string propertyName = propertyAliases->GetPropertyName("alias1b"); - - MITK_TEST_CONDITION(propertyName == "propertyName1", "Get property name of \"alias1b\""); - - propertyName = propertyAliases->GetPropertyName("alias2b"); - - MITK_TEST_CONDITION(propertyName.empty(), "Get property name of non-existing unrestricted \"alias2b\""); - - propertyName = propertyAliases->GetPropertyName("alias2b", "className"); - - MITK_TEST_CONDITION(propertyName == "propertyName2", "Get property name of restricted \"alias2b\""); - - MITK_TEST_END(); -} + Aliases m_Aliases; + std::string m_PropertyName; + +public: + void setUp() + { + m_PropertyAliases = mitk::CoreServices::GetPropertyAliases(); + m_PropertyAliases->AddAlias("propertyName1", "alias1a"); + m_PropertyAliases->AddAlias("propertyName1", "alias1b"); + m_PropertyAliases->AddAlias("propertyName2", "alias2a"); + m_PropertyAliases->AddAlias("propertyName2", "alias2b", "className"); + } + void tearDown() + { + m_PropertyAliases = nullptr; + } + + + void GetPropertyAliasesService_Success() + { + CPPUNIT_ASSERT_MESSAGE("Get property aliases service", m_PropertyAliases != nullptr); + } + + void GetAliases_Success() + { + m_Aliases = m_PropertyAliases->GetAliases("propertyName1"); + auto it1 = std::find(m_Aliases.begin(), m_Aliases.end(), "alias1a"); + auto it2 = std::find(m_Aliases.begin(), m_Aliases.end(), "alias1b"); + + CPPUNIT_ASSERT_MESSAGE("Get aliases of \"propertyName1\"", m_Aliases.size() == 2 && it1 != m_Aliases.end() && it2 != m_Aliases.end()); + + m_Aliases = m_PropertyAliases->GetAliases("propertyName2"); + it1 = std::find(m_Aliases.begin(), m_Aliases.end(), "alias2a"); + + CPPUNIT_ASSERT_MESSAGE("Get aliases of \"propertyName2\"", m_Aliases.size() == 1 && it1 != m_Aliases.end()); + } + + void GetAliasesRestricted_Success() + { + m_Aliases = m_PropertyAliases->GetAliases("propertyName2", "className"); + auto it1 = std::find(m_Aliases.begin(), m_Aliases.end(), "alias2b"); + + CPPUNIT_ASSERT_MESSAGE("Get aliases of \"propertyName2\" restricted to \"className\"", m_Aliases.size() == 1 && it1 != m_Aliases.end()); + } + + void GetPropertyName_Success() + { + m_PropertyName = m_PropertyAliases->GetPropertyName("alias1b"); + + CPPUNIT_ASSERT_MESSAGE("Get property name of \"alias1b\"", m_PropertyName == "propertyName1"); + } + + void GetPropertyNameNonexisting_Empty() + { + m_PropertyName = m_PropertyAliases->GetPropertyName("alias2b"); + + CPPUNIT_ASSERT_MESSAGE("Get property name of non-existing unrestricted \"alias2b\"", m_PropertyName.empty()); + } + + void GetPropertyNameRestricted_Success() + { + m_PropertyName = m_PropertyAliases->GetPropertyName("alias2b", "className"); + + CPPUNIT_ASSERT_MESSAGE("Get property name of restricted \"alias2b\"", m_PropertyName == "propertyName2"); + } +}; + +MITK_TEST_SUITE_REGISTRATION(mitkPropertyAliases) diff --git a/Modules/Core/test/mitkPropertyDescriptionsTest.cpp b/Modules/Core/test/mitkPropertyDescriptionsTest.cpp index 6b7e98b5f0..4b58119a59 100644 --- a/Modules/Core/test/mitkPropertyDescriptionsTest.cpp +++ b/Modules/Core/test/mitkPropertyDescriptionsTest.cpp @@ -1,43 +1,80 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ +// Testing +#include "mitkTestFixture.h" +#include "mitkTestingMacros.h" +// std includes +#include +#include +// MITK includes #include #include -#include +// VTK includes +#include -int mitkPropertyDescriptionsTest(int, char *[]) +class mitkPropertyDescriptionsTestSuite : public mitk::TestFixture { - MITK_TEST_BEGIN("mitkPropertyDescriptionsTest"); + CPPUNIT_TEST_SUITE(mitkPropertyDescriptionsTestSuite); + MITK_TEST(GetPropertyDescriptionService_Success); + MITK_TEST(GetPropertyDescription_Success); + MITK_TEST(GetOverwrittenDescription_Success); + MITK_TEST(GetPropertyDescriptionRestricted_Success); + CPPUNIT_TEST_SUITE_END(); - mitk::IPropertyDescriptions *propertyDescriptions = mitk::CoreServices::GetPropertyDescriptions(); - MITK_TEST_CONDITION_REQUIRED(propertyDescriptions != nullptr, "Get property descriptions service"); + private: + mitk::IPropertyDescriptions *m_PropertyDescriptions; + std::string m_Description1; - propertyDescriptions->AddDescription("propertyName1", "description1a"); - propertyDescriptions->AddDescription("propertyName1", "description1b"); - std::string description1 = propertyDescriptions->GetDescription("propertyName1"); + public: + void setUp() + { + m_PropertyDescriptions = mitk::CoreServices::GetPropertyDescriptions(); + m_PropertyDescriptions->AddDescription("propertyName1", "description1a"); + m_PropertyDescriptions->AddDescription("propertyName1", "description1b"); + } - MITK_TEST_CONDITION(description1 == "description1a", "Get description of \"propertyName1\""); + void tearDown() + { + m_PropertyDescriptions = nullptr; + } - propertyDescriptions->AddDescription("propertyName1", "description1b", "", true); - description1 = propertyDescriptions->GetDescription("propertyName1"); + void GetPropertyDescriptionService_Success() + { + CPPUNIT_ASSERT_MESSAGE("Get property descriptions service", m_PropertyDescriptions != nullptr); + } - MITK_TEST_CONDITION(description1 == "description1b", "Get overwritten description of \"propertyName1\""); + void GetPropertyDescription_Success() + { + m_Description1 = m_PropertyDescriptions->GetDescription("propertyName1"); + CPPUNIT_ASSERT_MESSAGE("Get description of \"propertyName1\"", m_Description1 == "description1a"); + } - propertyDescriptions->AddDescription("propertyName1", "description1c", "className"); - std::string description2 = propertyDescriptions->GetDescription("propertyName1", "className"); - description1 = propertyDescriptions->GetDescription("propertyName1"); + void GetOverwrittenDescription_Success() + { + m_PropertyDescriptions->AddDescription("propertyName1", "description1b", "", true); + m_Description1 = m_PropertyDescriptions->GetDescription("propertyName1"); + CPPUNIT_ASSERT_MESSAGE("Get overwritten description of \"propertyName1\"", m_Description1 == "description1b"); + } - MITK_TEST_CONDITION(description1 == "description1b" && description2 == "description1c", - "Get description of \"propertyName1\" restricted to \"className\""); + void GetPropertyDescriptionRestricted_Success() + { + m_PropertyDescriptions->AddDescription("propertyName1", "description1c", "className"); + std::string description2 = m_PropertyDescriptions->GetDescription("propertyName1", "className"); + m_Description1 = m_PropertyDescriptions->GetDescription("propertyName1"); + + CPPUNIT_ASSERT_MESSAGE("Get description of \"propertyName1\" restricted to \"className\"", + m_Description1 == "description1b" && description2 == "description1c"); + } +}; - MITK_TEST_END(); -} +MITK_TEST_SUITE_REGISTRATION(mitkPropertyDescriptions) diff --git a/Modules/Core/test/mitkPropertyExtensionsTest.cpp b/Modules/Core/test/mitkPropertyExtensionsTest.cpp index 8404dcc0cb..af38679513 100644 --- a/Modules/Core/test/mitkPropertyExtensionsTest.cpp +++ b/Modules/Core/test/mitkPropertyExtensionsTest.cpp @@ -1,63 +1,100 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ +// Testing +#include "mitkTestFixture.h" +#include "mitkTestingMacros.h" +// std includes +#include +#include +// MITK includes #include #include #include -#include +// VTK includes +#include class TestPropertyExtension : public mitk::PropertyExtension { public: mitkClassMacro(TestPropertyExtension, mitk::PropertyExtension); mitkNewMacro1Param(Self, const std::string &); std::string GetName() const { return m_Name; } private: explicit TestPropertyExtension(const std::string &name) : m_Name(name) {} ~TestPropertyExtension() override {} std::string m_Name; }; -int mitkPropertyExtensionsTest(int, char *[]) +class mitkPropertyExtensionsTestSuite : public mitk::TestFixture { - MITK_TEST_BEGIN("mitkPropertyExtensionsTest"); + CPPUNIT_TEST_SUITE(mitkPropertyExtensionsTestSuite); + MITK_TEST(GetPropertyExtensionService_Success); + MITK_TEST(GetPropertyExtension_Success); + MITK_TEST(GetOverwrittenExtension_Success); + MITK_TEST(GetPropertyExtensionRestricted_Success); + CPPUNIT_TEST_SUITE_END(); - mitk::IPropertyExtensions *propertyExtensions = mitk::CoreServices::GetPropertyExtensions(); - MITK_TEST_CONDITION_REQUIRED(propertyExtensions != nullptr, "Get property extensions service"); - - propertyExtensions->AddExtension("propertyName1", TestPropertyExtension::New("extension1a").GetPointer()); - propertyExtensions->AddExtension("propertyName1", TestPropertyExtension::New("extension1b").GetPointer()); - TestPropertyExtension::Pointer extension1 = - dynamic_cast(propertyExtensions->GetExtension("propertyName1").GetPointer()); - - MITK_TEST_CONDITION(extension1.IsNotNull() && extension1->GetName() == "extension1a", - "Get extension of \"propertyName1\""); - - propertyExtensions->AddExtension("propertyName1", TestPropertyExtension::New("extension1b").GetPointer(), "", true); - extension1 = dynamic_cast(propertyExtensions->GetExtension("propertyName1").GetPointer()); - - MITK_TEST_CONDITION(extension1.IsNotNull() && extension1->GetName() == "extension1b", - "Get overwritten extension of \"propertyName1\""); - - propertyExtensions->AddExtension( - "propertyName1", TestPropertyExtension::New("extension1c").GetPointer(), "className"); - TestPropertyExtension::Pointer extension2 = - dynamic_cast(propertyExtensions->GetExtension("propertyName1", "className").GetPointer()); - extension1 = dynamic_cast(propertyExtensions->GetExtension("propertyName1").GetPointer()); +private: + mitk::IPropertyExtensions *m_PropertyExtensions; + TestPropertyExtension::Pointer m_Extension1; - MITK_TEST_CONDITION(extension1.IsNotNull() && extension1->GetName() == "extension1b" && extension2.IsNotNull() && - extension2->GetName() == "extension1c", - "Get extension of \"propertyName1\" restricted to \"className\""); +public: + void setUp() + { + m_PropertyExtensions = mitk::CoreServices::GetPropertyExtensions(); + m_PropertyExtensions->AddExtension("propertyName1", TestPropertyExtension::New("extension1a").GetPointer()); + m_PropertyExtensions->AddExtension("propertyName1", TestPropertyExtension::New("extension1b").GetPointer()); + } + + void tearDown() + { + m_PropertyExtensions = nullptr; + } + + void GetPropertyExtensionService_Success() + { + CPPUNIT_ASSERT_MESSAGE("Get property extensions service", m_PropertyExtensions != nullptr); + } + + void GetPropertyExtension_Success() + { + TestPropertyExtension::Pointer extension1 = + dynamic_cast(m_PropertyExtensions->GetExtension("propertyName1").GetPointer()); + + CPPUNIT_ASSERT_MESSAGE("Get extension of \"propertyName1\"", + extension1.IsNotNull() && extension1->GetName() == "extension1a"); + } + + void GetOverwrittenExtension_Success() + { + m_PropertyExtensions->AddExtension("propertyName1", TestPropertyExtension::New("extension1b").GetPointer(), "", true); + m_Extension1 = dynamic_cast(m_PropertyExtensions->GetExtension("propertyName1").GetPointer()); + CPPUNIT_ASSERT_MESSAGE("Get overwritten extension of \"propertyName1\"", + m_Extension1.IsNotNull() && m_Extension1->GetName() == "extension1b"); + } + + void GetPropertyExtensionRestricted_Success() + { + m_PropertyExtensions->AddExtension("propertyName1", TestPropertyExtension::New("extension1c").GetPointer(), "className"); + TestPropertyExtension::Pointer extension2 = + dynamic_cast(m_PropertyExtensions->GetExtension("propertyName1", "className").GetPointer()); + m_Extension1 = dynamic_cast(m_PropertyExtensions->GetExtension("propertyName1").GetPointer()); + + CPPUNIT_ASSERT_MESSAGE("Get extension of \"propertyName1\" restricted to \"className\"", + m_Extension1.IsNotNull() && m_Extension1->GetName() == "extension1b" && extension2.IsNotNull() && + extension2->GetName() == "extension1c"); + } + }; + MITK_TEST_SUITE_REGISTRATION(mitkPropertyExtensions) - MITK_TEST_END(); -} diff --git a/Modules/Core/test/mitkPropertyFiltersTest.cpp b/Modules/Core/test/mitkPropertyFiltersTest.cpp index 2eba270d66..f48ff6725f 100644 --- a/Modules/Core/test/mitkPropertyFiltersTest.cpp +++ b/Modules/Core/test/mitkPropertyFiltersTest.cpp @@ -1,65 +1,96 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ -#include +// Testing +#include "mitkTestFixture.h" +#include "mitkTestingMacros.h" +// std includes +#include +#include +// MITK includes #include #include #include #include -#include -#include +// VTK includes +#include -int mitkPropertyFiltersTest(int, char *[]) +class mitkPropertyFiltersTestSuite : public mitk::TestFixture { - MITK_TEST_BEGIN("mitkPropertyFiltersTest"); - - mitk::IPropertyFilters *propertyFilters = mitk::CoreServices::GetPropertyFilters(); - MITK_TEST_CONDITION_REQUIRED(propertyFilters != nullptr, "Get property filters service"); - + CPPUNIT_TEST_SUITE(mitkPropertyFiltersTestSuite); + MITK_TEST(GetPropertyFiltersService_Success); + MITK_TEST(ApplyGlobalPropertyFilter_Success); + MITK_TEST(ApplyRestrictedPropertyFilter_Success); + CPPUNIT_TEST_SUITE_END(); + +private: + mitk::IPropertyFilters *m_PropertyFilters; typedef std::map PropertyMap; typedef PropertyMap::const_iterator PropertyMapConstIterator; - - PropertyMap propertyMap; - propertyMap.insert(std::make_pair("propertyName1", mitk::BoolProperty::New().GetPointer())); - propertyMap.insert(std::make_pair("propertyName2", mitk::BoolProperty::New().GetPointer())); - propertyMap.insert(std::make_pair("propertyName3", mitk::BoolProperty::New().GetPointer())); - - mitk::PropertyFilter filter; - filter.AddEntry("propertyName1", mitk::PropertyFilter::Whitelist); - filter.AddEntry("propertyName2", mitk::PropertyFilter::Whitelist); - - mitk::PropertyFilter restrictedFilter; - restrictedFilter.AddEntry("propertyName2", mitk::PropertyFilter::Blacklist); - - propertyFilters->AddFilter(filter); - propertyFilters->AddFilter(restrictedFilter, "className"); - - PropertyMap filteredPropertyMap = propertyFilters->ApplyFilter(propertyMap); - PropertyMapConstIterator it1 = filteredPropertyMap.find("propertyName1"); - PropertyMapConstIterator it2 = filteredPropertyMap.find("propertyName2"); - PropertyMapConstIterator it3 = filteredPropertyMap.find("propertyName3"); - - MITK_TEST_CONDITION( - it1 != filteredPropertyMap.end() && it2 != filteredPropertyMap.end() && it3 == filteredPropertyMap.end(), - "Apply global property filter"); - - filteredPropertyMap = propertyFilters->ApplyFilter(propertyMap, "className"); - it1 = filteredPropertyMap.find("propertyName1"); - it2 = filteredPropertyMap.find("propertyName2"); - it3 = filteredPropertyMap.find("propertyName3"); - - MITK_TEST_CONDITION( - it1 != filteredPropertyMap.end() && it2 == filteredPropertyMap.end() && it3 == filteredPropertyMap.end(), - "Apply restricted property filter (also respects global filter)"); - - MITK_TEST_END(); -} + PropertyMap m_PropertyMap; + mitk::PropertyFilter m_Filter; + mitk::PropertyFilter m_RestrictedFilter; + PropertyMap m_FilteredPropertyMap; + PropertyMapConstIterator m_It1; + PropertyMapConstIterator m_It2; + PropertyMapConstIterator m_It3; + +public: + void setUp() + { + m_PropertyFilters = mitk::CoreServices::GetPropertyFilters(); + + m_PropertyMap.insert(std::make_pair("propertyName1", mitk::BoolProperty::New().GetPointer())); + m_PropertyMap.insert(std::make_pair("propertyName2", mitk::BoolProperty::New().GetPointer())); + m_PropertyMap.insert(std::make_pair("propertyName3", mitk::BoolProperty::New().GetPointer())); + + m_Filter.AddEntry("propertyName1", mitk::PropertyFilter::Whitelist); + m_Filter.AddEntry("propertyName2", mitk::PropertyFilter::Whitelist); + + m_RestrictedFilter.AddEntry("propertyName2", mitk::PropertyFilter::Blacklist); + + m_PropertyFilters->AddFilter(m_Filter); + m_PropertyFilters->AddFilter(m_RestrictedFilter, "className"); + } + void tearDown() + { + m_PropertyFilters = nullptr; + } + + void GetPropertyFiltersService_Success() + { + CPPUNIT_ASSERT_MESSAGE("Get property filters service", m_PropertyFilters != nullptr); + } + + void ApplyGlobalPropertyFilter_Success() + { + m_FilteredPropertyMap = m_PropertyFilters->ApplyFilter(m_PropertyMap); + m_It1 = m_FilteredPropertyMap.find("propertyName1"); + m_It2 = m_FilteredPropertyMap.find("propertyName2"); + m_It3 = m_FilteredPropertyMap.find("propertyName3"); + + CPPUNIT_ASSERT_MESSAGE("Apply global property filter", + m_It1 != m_FilteredPropertyMap.end() && m_It2 != m_FilteredPropertyMap.end() && m_It3 == m_FilteredPropertyMap.end()); + } + + void ApplyRestrictedPropertyFilter_Success() + { + m_FilteredPropertyMap = m_PropertyFilters->ApplyFilter(m_PropertyMap, "className"); + m_It1 = m_FilteredPropertyMap.find("propertyName1"); + m_It2 = m_FilteredPropertyMap.find("propertyName2"); + m_It3 = m_FilteredPropertyMap.find("propertyName3"); + + CPPUNIT_ASSERT_MESSAGE("Apply restricted property filter (also respects global filter)", + m_It1 != m_FilteredPropertyMap.end() && m_It2 == m_FilteredPropertyMap.end() && m_It3 == m_FilteredPropertyMap.end()); + } +}; +MITK_TEST_SUITE_REGISTRATION(mitkPropertyFilters) diff --git a/Modules/Core/test/mitkPropertyTest.cpp b/Modules/Core/test/mitkPropertyTest.cpp index 01a23ef6ec..3d2fa11b29 100644 --- a/Modules/Core/test/mitkPropertyTest.cpp +++ b/Modules/Core/test/mitkPropertyTest.cpp @@ -1,434 +1,489 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ +// Testing +#include "mitkTestFixture.h" #include "mitkTestingMacros.h" - +// std includes +#include +// MITK includes #include #include #include #include #include #include #include #include #include #include #include - +#include +// ITK includes #include +// VTK includes +#include struct PropertyModifiedListener { typedef itk::SimpleMemberCommand CmdType; PropertyModifiedListener() : m_Modified(false), m_Cmd(CmdType::New()) { m_Cmd->SetCallbackFunction(this, &PropertyModifiedListener::Modified); } void Modified() { m_Modified = true; } bool Pop() { bool b = m_Modified; m_Modified = false; return b; } bool m_Modified; CmdType::Pointer m_Cmd; }; -template -void TestPropInequality(T prop, T prop2) -{ - mitk::BaseProperty::Pointer baseProp2(prop2.GetPointer()); - MITK_TEST_CONDITION_REQUIRED(!(*prop == *prop2), "Test inequality 1"); - MITK_TEST_CONDITION_REQUIRED(!(*prop == *baseProp2), "Test polymorphic inequality 1"); - MITK_TEST_CONDITION_REQUIRED(!(*baseProp2 == *prop), "Test polymorphic inequality 2"); -} - -template -void TestPropAssignment(T prop, T prop2, const std::string &strProp) -{ - PropertyModifiedListener l; - unsigned long tag = prop->AddObserver(itk::ModifiedEvent(), l.m_Cmd.GetPointer()); - - mitk::BaseProperty::Pointer baseProp2(prop2.GetPointer()); - *prop = *baseProp2; - MITK_TEST_CONDITION_REQUIRED(l.Pop(), "Test modified event"); - std::string msg = std::string("Test assignment [") + prop->GetValueAsString() + " == " + strProp + "]"; - MITK_TEST_CONDITION_REQUIRED(prop->GetValueAsString() == strProp, msg); - MITK_TEST_CONDITION_REQUIRED(*prop == *prop2, "Test equality"); - MITK_TEST_CONDITION_REQUIRED(*prop == *baseProp2, "Test equality"); - MITK_TEST_CONDITION_REQUIRED(*baseProp2 == *prop, "Test polymorphic equality"); - - prop->RemoveObserver(tag); -} - -template -void TestPropPolymorphicAssignment(T prop, T prop2, const std::string &strProp) +class mitkPropertyTestSuite : public mitk::TestFixture { - mitk::BaseProperty::Pointer baseProp(prop.GetPointer()); - - PropertyModifiedListener l; - unsigned long tag = baseProp->AddObserver(itk::ModifiedEvent(), l.m_Cmd.GetPointer()); - - *baseProp = *prop2; - MITK_TEST_CONDITION_REQUIRED(l.Pop(), "Test modified event"); - std::string msg = - std::string("Test polymorphic assignment [") + baseProp->GetValueAsString() + " == " + strProp + "]"; - MITK_TEST_CONDITION_REQUIRED(baseProp->GetValueAsString() == strProp, msg); - MITK_TEST_CONDITION_REQUIRED(*prop == *prop2, "Test equality"); - MITK_TEST_CONDITION_REQUIRED(*prop2 == *baseProp, "Test equality"); - MITK_TEST_CONDITION_REQUIRED(*baseProp == *prop2, "Test polymorphic equality"); - - baseProp->RemoveObserver(tag); -} - -template -void TestPropCloning(T prop) -{ - T prop2 = prop->Clone(); - MITK_TEST_CONDITION_REQUIRED(prop.GetPointer() != prop2.GetPointer(), "Test clone pointer") - MITK_TEST_CONDITION_REQUIRED(*prop == *prop2, "Test equality of the clone") -} - -template -void TestProperty(const typename T::ValueType &v1, - const typename T::ValueType &v2, - const std::string &strV1, - const std::string &strV2) -{ - PropertyModifiedListener l; - - typename T::Pointer prop = T::New(v1); - MITK_TEST_OUTPUT(<< "**** Test [" << prop->GetNameOfClass() << "] ****"); + CPPUNIT_TEST_SUITE(mitkPropertyTestSuite); + MITK_TEST(TestBoolProperty_Success); + MITK_TEST(TestIntProperty_Success); + MITK_TEST(TestFloatProperty_Success); + MITK_TEST(TestDoubleProperty_Success); + MITK_TEST(TestVector3DProperty_Success); + MITK_TEST(TestPoint3D_Success); + MITK_TEST(TestPoint4D_Success); + MITK_TEST(TestPoint3I_Success); + MITK_TEST(TestFloatLookupTable_Success); + MITK_TEST(TestBoolLookupTable_Success); + MITK_TEST(TestIntLookupTable_Success); + MITK_TEST(TestStringLookupTable_Success); + MITK_TEST(TestAnnotationProperty_Success); + MITK_TEST(TestClippingProperty_Success); + MITK_TEST(TestColorProperty_Success); + MITK_TEST(TestLevelWindowProperty_Success); + MITK_TEST(TestSmartPointerProperty_Success); + MITK_TEST(TestStringProperty_Success); + MITK_TEST(TestTransferFunctionProperty_Success); + MITK_TEST(TestWeakPointerProperty_Success); + MITK_TEST(TestLookupTablePropertyProperty_Success); + CPPUNIT_TEST_SUITE_END(); + +private: + PropertyModifiedListener m_L; +public: + void setUp() + { + } + void tearDown() + { + } - MITK_TEST_CONDITION_REQUIRED(prop->GetValue() == v1, "Test constructor"); - std::string msg = std::string("Test GetValueAsString() [") + prop->GetValueAsString() + " == " + strV1 + "]"; - MITK_TEST_CONDITION_REQUIRED(prop->GetValueAsString() == strV1, msg); + template + void TestPropInequality(T prop, T prop2) + { + mitk::BaseProperty::Pointer baseProp2(prop2.GetPointer()); + CPPUNIT_ASSERT_MESSAGE("Test inequality 1", !(*prop == *prop2)); + CPPUNIT_ASSERT_MESSAGE("Test polymorphic inequality 1", !(*prop == *baseProp2)); + CPPUNIT_ASSERT_MESSAGE("Test polymorphic inequality 2", !(*baseProp2 == *prop)); + } - TestPropCloning(prop); + template + void TestPropAssignment(T prop, T prop2, const std::string &strProp) + { + unsigned long tag = prop->AddObserver(itk::ModifiedEvent(), m_L.m_Cmd.GetPointer()); + + mitk::BaseProperty::Pointer baseProp2(prop2.GetPointer()); + *prop = *baseProp2; + CPPUNIT_ASSERT_MESSAGE("Test modified event", m_L.Pop()); + std::string msg = std::string("Test assignment [") + prop->GetValueAsString() + " == " + strProp + "]"; + CPPUNIT_ASSERT_MESSAGE(msg, prop->GetValueAsString() == strProp); + CPPUNIT_ASSERT_MESSAGE("Test equality", *prop == *prop2); + CPPUNIT_ASSERT_MESSAGE("Test equality", *prop == *baseProp2); + CPPUNIT_ASSERT_MESSAGE("Test polymorphic equality", *baseProp2 == *prop); + + prop->RemoveObserver(tag); + } - typename T::Pointer prop2 = T::New(); - prop2->AddObserver(itk::ModifiedEvent(), l.m_Cmd.GetPointer()); - MITK_TEST_CONDITION_REQUIRED(!l.m_Modified, "Test modified"); - prop2->SetValue(v2); - MITK_TEST_CONDITION_REQUIRED(l.Pop(), "Test modified"); - MITK_TEST_CONDITION_REQUIRED(prop2->GetValue() == v2, "Test SetValue()"); + template + void TestPropPolymorphicAssignment(T prop, T prop2, const std::string &strProp) + { + mitk::BaseProperty::Pointer baseProp(prop.GetPointer()); + + unsigned long tag = baseProp->AddObserver(itk::ModifiedEvent(), m_L.m_Cmd.GetPointer()); + + *baseProp = *prop2; + CPPUNIT_ASSERT_MESSAGE("Test modified event", m_L.Pop()); + std::string msg = + std::string("Test polymorphic assignment [") + baseProp->GetValueAsString() + " == " + strProp + "]"; + CPPUNIT_ASSERT_MESSAGE(msg, baseProp->GetValueAsString() == strProp); + CPPUNIT_ASSERT_MESSAGE("Test equality", *prop == *prop2); + CPPUNIT_ASSERT_MESSAGE("Test equality", *prop2 == *baseProp); + CPPUNIT_ASSERT_MESSAGE("Test polymorphic equality", *baseProp == *prop2); + baseProp->RemoveObserver(tag); + } + + template + void TestPropCloning(T prop) + { + T prop2 = prop->Clone(); + CPPUNIT_ASSERT_MESSAGE("Test clone pointer", prop.GetPointer() != prop2.GetPointer()); + CPPUNIT_ASSERT_MESSAGE("Test equality of the clone", *prop == *prop2); + } + + template + void TestProperty(const typename T::ValueType &v1, + const typename T::ValueType &v2, + const std::string &strV1, + const std::string &strV2) + { + typename T::Pointer prop = T::New(v1); + MITK_TEST_OUTPUT(<< "**** Test [" << prop->GetNameOfClass() << "] ****"); + + CPPUNIT_ASSERT_MESSAGE("Test constructor", prop->GetValue() == v1); + std::string msg = std::string("Test GetValueAsString() [") + prop->GetValueAsString() + " == " + strV1 + "]"; + CPPUNIT_ASSERT_MESSAGE(msg, prop->GetValueAsString() == strV1); + + TestPropCloning(prop); + + typename T::Pointer prop2 = T::New(); + prop2->AddObserver(itk::ModifiedEvent(), m_L.m_Cmd.GetPointer()); + CPPUNIT_ASSERT_MESSAGE("Test modified", !m_L.m_Modified); + prop2->SetValue(v2); + CPPUNIT_ASSERT_MESSAGE("Test modified", m_L.Pop()); + CPPUNIT_ASSERT_MESSAGE("Test SetValue()", prop2->GetValue() == v2); + prop2->SetValue(v2); + CPPUNIT_ASSERT_MESSAGE("Test for no modification", !m_L.Pop()); + + TestPropInequality(prop, prop2); + TestPropAssignment(prop, prop2, strV2); + + prop->SetValue(v1); + TestPropPolymorphicAssignment(prop2, prop, strV1); + } - prop2->SetValue(v2); - MITK_TEST_CONDITION_REQUIRED(!l.Pop(), "Test for no modification"); + void TestBoolProperty_Success() + { + TestProperty(false, true, "0", "1"); + } - TestPropInequality(prop, prop2); - TestPropAssignment(prop, prop2, strV2); + void TestIntProperty_Success() + { + TestProperty(3, 5, "3", "5"); + } - prop->SetValue(v1); - TestPropPolymorphicAssignment(prop2, prop, strV1); -} + void TestFloatProperty_Success() + { + TestProperty(0.3f, -23.5f, "0.3", "-23.5"); + } -void TestGenericProperties() -{ - TestProperty(false, true, "0", "1"); - TestProperty(3, 5, "3", "5"); - TestProperty(0.3f, -23.5f, "0.3", "-23.5"); - TestProperty(64.1f, 2.34f, "64.1", "2.34"); + void TestDoubleProperty_Success() + { + TestProperty(64.1f, 2.34f, "64.1", "2.34"); + } + void TestVector3DProperty_Success() { mitk::Vector3D p1; p1[0] = 2.0; p1[1] = 3.0; p1[2] = 4.0; mitk::Vector3D p2; p2[0] = -1.0; p2[1] = 2.0; p2[2] = 3.0; TestProperty(p1, p2, "[2, 3, 4]", "[-1, 2, 3]"); } + void TestPoint3D_Success() { mitk::Point3D p1; p1[0] = 2.0; p1[1] = 3.0; p1[2] = 4.0; mitk::Point3D p2; p2[0] = -1.0; p2[1] = 2.0; p2[2] = 3.0; TestProperty(p1, p2, "[2, 3, 4]", "[-1, 2, 3]"); } + void TestPoint4D_Success() { mitk::Point4D p1; p1[0] = 2.0; p1[1] = 3.0; p1[2] = 4.0; p1[3] = -2.0; mitk::Point4D p2; p2[0] = -1.0; p2[1] = 2.0; p2[2] = 3.0; p2[3] = 5.0; TestProperty(p1, p2, "[2, 3, 4, -2]", "[-1, 2, 3, 5]"); } + void TestPoint3I_Success() { mitk::Point3I p1; p1[0] = 2; p1[1] = 3; p1[2] = 4; mitk::Point3I p2; p2[0] = 8; p2[1] = 7; p2[2] = 6; TestProperty(p1, p2, "[2, 3, 4]", "[8, 7, 6]"); } + void TestFloatLookupTable_Success() { mitk::FloatLookupTable lut1; lut1.SetTableValue(1, 0.3f); lut1.SetTableValue(4, 323.7f); mitk::FloatLookupTable lut2; lut2.SetTableValue(6, -0.3f); lut2.SetTableValue(2, 25.7f); TestProperty(lut1, lut2, "[1 -> 0.3, 4 -> 323.7]", "[2 -> 25.7, 6 -> -0.3]"); } + void TestBoolLookupTable_Success() { mitk::BoolLookupTable lut1; lut1.SetTableValue(3, false); lut1.SetTableValue(5, true); mitk::BoolLookupTable lut2; lut2.SetTableValue(1, false); lut2.SetTableValue(2, false); TestProperty(lut1, lut2, "[3 -> 0, 5 -> 1]", "[1 -> 0, 2 -> 0]"); } + void TestIntLookupTable_Success() { mitk::IntLookupTable lut1; lut1.SetTableValue(5, -12); lut1.SetTableValue(7, 3); mitk::IntLookupTable lut2; lut2.SetTableValue(4, -6); lut2.SetTableValue(8, -45); TestProperty(lut1, lut2, "[5 -> -12, 7 -> 3]", "[4 -> -6, 8 -> -45]"); } + void TestStringLookupTable_Success() { mitk::StringLookupTable lut1; lut1.SetTableValue(0, "a"); lut1.SetTableValue(2, "b"); mitk::StringLookupTable lut2; lut2.SetTableValue(0, "a"); lut2.SetTableValue(2, "c"); TestProperty(lut1, lut2, "[0 -> a, 2 -> b]", "[0 -> a, 2 -> c]"); } -} - -void TestAnnotationProperty() -{ - PropertyModifiedListener l; - - std::string label1("Label1"); - mitk::Point3D point1; - point1[0] = 3; - point1[1] = 5; - point1[2] = -4; - std::string str1 = "Label1[3, 5, -4]"; - - std::string label2("Label2"); - mitk::Point3D point2; - point2[0] = -2; - point2[1] = 8; - point2[2] = -4; - std::string str2 = "Label2[-2, 8, -4]"; - - mitk::AnnotationProperty::Pointer prop = mitk::AnnotationProperty::New(label1, point1); - MITK_TEST_OUTPUT(<< "**** Test [" << prop->GetNameOfClass() << "] ****"); - - MITK_TEST_CONDITION_REQUIRED(prop->GetLabel() == label1 && prop->GetPosition() == point1, "Test constructor"); - std::string msg = std::string("Test GetValueAsString() [") + prop->GetValueAsString() + " == " + str1 + "]"; - MITK_TEST_CONDITION_REQUIRED(prop->GetValueAsString() == str1, msg); - - mitk::AnnotationProperty::Pointer prop2 = mitk::AnnotationProperty::New(); - prop2->AddObserver(itk::ModifiedEvent(), l.m_Cmd.GetPointer()); - MITK_TEST_CONDITION_REQUIRED(!l.m_Modified, "Test not modified"); - prop2->SetLabel(label2); - MITK_TEST_CONDITION_REQUIRED(l.Pop(), "Test modified"); - prop2->SetPosition(point2); - MITK_TEST_CONDITION_REQUIRED(l.Pop(), "Test modified"); - MITK_TEST_CONDITION_REQUIRED(prop2->GetLabel() == label2 && prop2->GetPosition() == point2, "Test Setter"); - - prop2->SetLabel(label2); - MITK_TEST_CONDITION_REQUIRED(!l.Pop(), "Test for no modification"); - prop2->SetPosition(point2); - MITK_TEST_CONDITION_REQUIRED(!l.Pop(), "Test for no modification"); - - TestPropInequality(prop, prop2); - TestPropAssignment(prop, prop2, str2); - - prop->SetLabel(label1); - prop->SetPosition(point1); - TestPropPolymorphicAssignment(prop2, prop, str1); -} - -void TestClippingProperty() -{ - PropertyModifiedListener l; - - bool enabled1 = true; - mitk::Point3D point1; - point1[0] = 3; - point1[1] = 5; - point1[2] = -4; - mitk::Vector3D vec1; - vec1[0] = 0; - vec1[1] = 2; - vec1[2] = -1; - std::string str1 = "1[3, 5, -4][0, 2, -1]"; - - bool enabled2 = false; - mitk::Point3D point2; - point2[0] = -2; - point2[1] = 8; - point2[2] = -4; - mitk::Vector3D vec2; - vec2[0] = 0; - vec2[1] = 2; - vec2[2] = 4; - std::string str2 = "0[-2, 8, -4][0, 2, 4]"; - - mitk::ClippingProperty::Pointer prop = mitk::ClippingProperty::New(point1, vec1); - MITK_TEST_OUTPUT(<< "**** Test [" << prop->GetNameOfClass() << "] ****"); - - MITK_TEST_CONDITION_REQUIRED( - prop->GetClippingEnabled() == enabled1 && prop->GetOrigin() == point1 && prop->GetNormal() == vec1, - "Test constructor"); - std::string msg = std::string("Test GetValueAsString() [") + prop->GetValueAsString() + " == " + str1 + "]"; - MITK_TEST_CONDITION_REQUIRED(prop->GetValueAsString() == str1, msg); - - mitk::ClippingProperty::Pointer prop2 = mitk::ClippingProperty::New(); - prop2->AddObserver(itk::ModifiedEvent(), l.m_Cmd.GetPointer()); - MITK_TEST_CONDITION_REQUIRED(!l.m_Modified, "Test not modified"); - prop2->SetClippingEnabled(enabled2); - MITK_TEST_CONDITION_REQUIRED(!l.Pop(), "Test not modified"); - prop2->SetOrigin(point2); - MITK_TEST_CONDITION_REQUIRED(l.Pop(), "Test modified"); - prop2->SetNormal(vec2); - MITK_TEST_CONDITION_REQUIRED(l.Pop(), "Test modified"); - - MITK_TEST_CONDITION_REQUIRED( - prop2->GetClippingEnabled() == enabled2 && prop2->GetOrigin() == point2 && prop2->GetNormal() == vec2, - "Test Setter"); - - prop2->SetClippingEnabled(enabled2); - MITK_TEST_CONDITION_REQUIRED(!l.Pop(), "Test for no modification"); - prop2->SetOrigin(point2); - MITK_TEST_CONDITION_REQUIRED(!l.Pop(), "Test for no modification"); - prop2->SetNormal(vec2); - MITK_TEST_CONDITION_REQUIRED(!l.Pop(), "Test for no modification"); - - TestPropInequality(prop, prop2); - TestPropAssignment(prop, prop2, str2); - - prop->SetClippingEnabled(enabled1); - prop->SetOrigin(point1); - prop->SetNormal(vec1); - TestPropPolymorphicAssignment(prop2, prop, str1); -} - -int mitkPropertyTest(int /* argc */, char * /*argv*/ []) -{ - MITK_TEST_BEGIN("Testing MITK Properties") - TestGenericProperties(); + void TestAnnotationProperty_Success() + { + std::string label1("Label1"); + mitk::Point3D point1; + point1[0] = 3; + point1[1] = 5; + point1[2] = -4; + std::string str1 = "Label1[3, 5, -4]"; + + std::string label2("Label2"); + mitk::Point3D point2; + point2[0] = -2; + point2[1] = 8; + point2[2] = -4; + std::string str2 = "Label2[-2, 8, -4]"; + + mitk::AnnotationProperty::Pointer prop = mitk::AnnotationProperty::New(label1, point1); + MITK_TEST_OUTPUT(<< "**** Test [" << prop->GetNameOfClass() << "] ****"); + + CPPUNIT_ASSERT_MESSAGE("Test constructor", prop->GetLabel() == label1 && prop->GetPosition() == point1); + std::string msg = std::string("Test GetValueAsString() [") + prop->GetValueAsString() + " == " + str1 + "]"; + CPPUNIT_ASSERT_MESSAGE(msg, prop->GetValueAsString() == str1); + + mitk::AnnotationProperty::Pointer prop2 = mitk::AnnotationProperty::New(); + prop2->AddObserver(itk::ModifiedEvent(), m_L.m_Cmd.GetPointer()); + CPPUNIT_ASSERT_MESSAGE("Test not modified", !m_L.m_Modified); + prop2->SetLabel(label2); + CPPUNIT_ASSERT_MESSAGE("Test modified", m_L.Pop()); + prop2->SetPosition(point2); + CPPUNIT_ASSERT_MESSAGE("Test modified", m_L.Pop()); + CPPUNIT_ASSERT_MESSAGE("Test Setter", prop2->GetLabel() == label2 && prop2->GetPosition() == point2); + + prop2->SetLabel(label2); + CPPUNIT_ASSERT_MESSAGE("Test for no modification", !m_L.Pop()); + prop2->SetPosition(point2); + CPPUNIT_ASSERT_MESSAGE("Test for no modification", !m_L.Pop()); + + TestPropInequality(prop, prop2); + TestPropAssignment(prop, prop2, str2); + + prop->SetLabel(label1); + prop->SetPosition(point1); + TestPropPolymorphicAssignment(prop2, prop, str1); + } - TestAnnotationProperty(); - TestClippingProperty(); + void TestClippingProperty_Success() + { + bool enabled1 = true; + mitk::Point3D point1; + point1[0] = 3; + point1[1] = 5; + point1[2] = -4; + mitk::Vector3D vec1; + vec1[0] = 0; + vec1[1] = 2; + vec1[2] = -1; + std::string str1 = "1[3, 5, -4][0, 2, -1]"; + + bool enabled2 = false; + mitk::Point3D point2; + point2[0] = -2; + point2[1] = 8; + point2[2] = -4; + mitk::Vector3D vec2; + vec2[0] = 0; + vec2[1] = 2; + vec2[2] = 4; + std::string str2 = "0[-2, 8, -4][0, 2, 4]"; + + mitk::ClippingProperty::Pointer prop = mitk::ClippingProperty::New(point1, vec1); + MITK_TEST_OUTPUT(<< "**** Test [" << prop->GetNameOfClass() << "] ****"); + + CPPUNIT_ASSERT_MESSAGE("Test constructor", + prop->GetClippingEnabled() == enabled1 && prop->GetOrigin() == point1 && prop->GetNormal() == vec1); + std::string msg = std::string("Test GetValueAsString() [") + prop->GetValueAsString() + " == " + str1 + "]"; + CPPUNIT_ASSERT_MESSAGE(msg, prop->GetValueAsString() == str1); + + mitk::ClippingProperty::Pointer prop2 = mitk::ClippingProperty::New(); + prop2->AddObserver(itk::ModifiedEvent(), m_L.m_Cmd.GetPointer()); + CPPUNIT_ASSERT_MESSAGE("Test not modified", !m_L.m_Modified); + prop2->SetClippingEnabled(enabled2); + CPPUNIT_ASSERT_MESSAGE("Test not modified", !m_L.Pop()); + prop2->SetOrigin(point2); + CPPUNIT_ASSERT_MESSAGE("Test modified", m_L.Pop()); + prop2->SetNormal(vec2); + CPPUNIT_ASSERT_MESSAGE("Test modified", m_L.Pop()); + + CPPUNIT_ASSERT_MESSAGE("Test Setter", + prop2->GetClippingEnabled() == enabled2 && prop2->GetOrigin() == point2 && prop2->GetNormal() == vec2); + + prop2->SetClippingEnabled(enabled2); + CPPUNIT_ASSERT_MESSAGE("Test for no modification", !m_L.Pop()); + prop2->SetOrigin(point2); + CPPUNIT_ASSERT_MESSAGE("Test for no modification", !m_L.Pop()); + prop2->SetNormal(vec2); + CPPUNIT_ASSERT_MESSAGE("Test for no modification", !m_L.Pop()); + + TestPropInequality(prop, prop2); + TestPropAssignment(prop, prop2, str2); + + prop->SetClippingEnabled(enabled1); + prop->SetOrigin(point1); + prop->SetNormal(vec1); + TestPropPolymorphicAssignment(prop2, prop, str1); + } - mitk::Color c1; - c1[0] = 0.2; - c1[1] = 0.6; - c1[2] = 0.8; - mitk::Color c2; - c2[0] = 0.2; - c2[1] = 0.4; - c2[2] = 0.1; - TestProperty(c1, c2, "0.2 0.6 0.8", "0.2 0.4 0.1"); + void TestColorProperty_Success() + { + mitk::Color c1; + c1[0] = 0.2; + c1[1] = 0.6; + c1[2] = 0.8; + mitk::Color c2; + c2[0] = 0.2; + c2[1] = 0.4; + c2[2] = 0.1; + TestProperty(c1, c2, "0.2 0.6 0.8", "0.2 0.4 0.1"); + } - mitk::LevelWindow lw1(50, 100); - mitk::LevelWindow lw2(120, 30); - TestProperty(lw1, lw2, "L:50 W:100", "L:120 W:30"); + void TestLevelWindowProperty_Success() + { + mitk::LevelWindow lw1(50, 100); + mitk::LevelWindow lw2(120, 30); + TestProperty(lw1, lw2, "L:50 W:100", "L:120 W:30"); + } + void TestSmartPointerProperty_Success() { itk::Object::Pointer sp1 = itk::Object::New(); itk::Object::Pointer sp2 = itk::Object::New(); // to generate the UIDs, we set the smartpointers mitk::SmartPointerProperty::Pointer spp1 = mitk::SmartPointerProperty::New(sp1.GetPointer()); mitk::SmartPointerProperty::Pointer spp2 = mitk::SmartPointerProperty::New(sp2.GetPointer()); TestProperty(sp1, sp2, spp1->GetReferenceUIDFor(sp1), spp2->GetReferenceUIDFor(sp2)); } - TestProperty("1", "2", "1", "2"); + void TestStringProperty_Success() + { + TestProperty("1", "2", "1", "2"); + } + void TestTransferFunctionProperty_Success() { mitk::TransferFunction::Pointer tf1 = mitk::TransferFunction::New(); mitk::TransferFunction::Pointer tf2 = mitk::TransferFunction::New(); tf2->AddScalarOpacityPoint(0.4, 0.8); std::stringstream ss; ss << tf1; std::string strTF1 = ss.str(); ss.str(""); ss << tf2; std::string strTF2 = ss.str(); TestProperty(tf1, tf2, strTF1, strTF2); } + void TestWeakPointerProperty_Success() { itk::Object::Pointer sp1 = itk::Object::New(); itk::Object::Pointer sp2 = itk::Object::New(); mitk::WeakPointerProperty::ValueType wp1 = sp1.GetPointer(); mitk::WeakPointerProperty::ValueType wp2 = sp2.GetPointer(); std::stringstream ss; ss << sp1.GetPointer(); std::string str1 = ss.str(); ss.str(""); ss << sp2.GetPointer(); std::string str2 = ss.str(); TestProperty(wp1, wp2, str1, str2); } + void TestLookupTablePropertyProperty_Success() { mitk::LookupTable::Pointer lut1 = mitk::LookupTable::New(); lut1->GetVtkLookupTable()->SetTableValue(0, 0.2, 0.3, 0.4); mitk::LookupTable::Pointer lut2 = mitk::LookupTable::New(); lut2->GetVtkLookupTable()->SetTableValue(0, 0.2, 0.4, 0.4); std::stringstream ss; ss << lut1; std::string strLUT1 = ss.str(); ss.str(""); ss << lut2; std::string strLUT2 = ss.str(); TestProperty(lut1, lut2, strLUT1, strLUT2); } +}; +MITK_TEST_SUITE_REGISTRATION(mitkProperty) - MITK_TEST_END() -} diff --git a/Modules/Core/test/mitkTinyXMLTest.cpp b/Modules/Core/test/mitkTinyXMLTest.cpp index db5273b47d..ddd251e473 100644 --- a/Modules/Core/test/mitkTinyXMLTest.cpp +++ b/Modules/Core/test/mitkTinyXMLTest.cpp @@ -1,160 +1,159 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ // Testing #include "mitkTestFixture.h" #include // std includes #include #include -#include #include // MITK includes #include "mitkStringProperty.h" #include // itksys #include // VTK includes #include // vnl includes #include class mitkTinyXMLTestSuite : public mitk::TestFixture { CPPUNIT_TEST_SUITE(mitkTinyXMLTestSuite); MITK_TEST(TestingFunctionSetupWorks_Success); MITK_TEST(TestingReadValueFromSetupDocument_Success); MITK_TEST(TestingReadOutValueWorks_Success); MITK_TEST(TestDoubleValueWriteOut_Success); MITK_TEST(TestDoubleValueWriteOutManyDecimalPlaces_Success); CPPUNIT_TEST_SUITE_END(); private: const std::string m_Filename = itksys::SystemTools::GetCurrentWorkingDirectory() + "/TinyXMLTest.txt"; const std::string m_ElementToStoreAttributeName = "DoubleTest"; const std::string m_AttributeToStoreName = "CommaValue"; TiXmlDocument m_Document; TiXmlElement *m_DoubleTest; double calcPrecision(const unsigned int requiredDecimalPlaces) { return pow(10.0, -1.0 * ((double)requiredDecimalPlaces)); } bool Setup(double valueToWrite) { // 1. create simple document auto decl = new TiXmlDeclaration("1.0", "", ""); // TODO what to write here? encoding? etc.... m_Document.LinkEndChild(decl); auto version = new TiXmlElement("Version"); version->SetAttribute("Writer", __FILE__); version->SetAttribute("CVSRevision", "$Revision: 17055 $"); version->SetAttribute("FileVersion", 1); m_Document.LinkEndChild(version); // 2. store one element containing a double value with potentially many after comma digits. auto vElement = new TiXmlElement(m_ElementToStoreAttributeName); vElement->SetDoubleAttribute(m_AttributeToStoreName, valueToWrite); m_Document.LinkEndChild(vElement); // 3. store in file. return m_Document.SaveFile(m_Filename); } public: void setUp() override {} void tearDown() override {} void TestingFunctionSetupWorks_Success() { CPPUNIT_ASSERT_MESSAGE("Test if Setup correctly writes data to file", Setup(1.0)); } int readValueFromSetupDocument(double &readOutValue) { if (!m_Document.LoadFile(m_Filename)) { CPPUNIT_ASSERT_MESSAGE("Test Setup failed, could not open file", false); return TIXML_NO_ATTRIBUTE; } else { m_DoubleTest = m_Document.FirstChildElement(m_ElementToStoreAttributeName); return m_DoubleTest->QueryDoubleAttribute(m_AttributeToStoreName, &readOutValue); } } void TestingReadValueFromSetupDocument_Success() { if (!m_Document.LoadFile(m_Filename)) { CPPUNIT_ASSERT_MESSAGE("Test Setup failed, could not open file", !m_Document.LoadFile(m_Filename)); } else { m_DoubleTest = m_Document.FirstChildElement(m_ElementToStoreAttributeName); CPPUNIT_ASSERT_MESSAGE("Test Setup could open file", m_DoubleTest != nullptr); } } /** * this first test ensures we can correctly readout values from the * TinyXMLDocument. */ void TestingReadOutValueWorks_Success() { double readValue; CPPUNIT_ASSERT_MESSAGE("checking if readout mechanism works.", TIXML_SUCCESS == readValueFromSetupDocument(readValue)); } void TestDoubleValueWriteOut_Success() { const double valueToWrite = -1.123456; const int validDigitsAfterComma = 6; // indicates the number of valid digits after comma of valueToWrite const double neededPrecision = calcPrecision(validDigitsAfterComma + 1); double readValue; Setup(valueToWrite); readValueFromSetupDocument(readValue); CPPUNIT_ASSERT_MESSAGE("Testing if value valueToWrite equals readValue which was retrieved from TinyXML document", mitk::Equal(valueToWrite, readValue, neededPrecision)); } void TestDoubleValueWriteOutManyDecimalPlaces_Success() { const double valueToWrite = -1.12345678910111; const int validDigitsAfterComma = 14; // indicates the number of valid digits after comma of valueToWrite const double neededPrecision = calcPrecision(validDigitsAfterComma + 1); double readValue; Setup(valueToWrite); readValueFromSetupDocument(readValue); CPPUNIT_ASSERT_MESSAGE("Testing if value valueToWrite equals readValue which was retrieved from TinyXML document", mitk::Equal(valueToWrite, readValue, neededPrecision)); } }; MITK_TEST_SUITE_REGISTRATION(mitkTinyXML) diff --git a/Modules/Core/test/mitkUIDGeneratorTest.cpp b/Modules/Core/test/mitkUIDGeneratorTest.cpp index 84b7f86640..12dd6aa337 100644 --- a/Modules/Core/test/mitkUIDGeneratorTest.cpp +++ b/Modules/Core/test/mitkUIDGeneratorTest.cpp @@ -1,59 +1,65 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ +// Testing +#include "mitkTestFixture.h" +#include "mitkTestingMacros.h" +// std includes +#include +// MITK includes #include "mitkUIDGenerator.h" #include #include #include class mitkUIDGeneratorTestSuite : public mitk::TestFixture { CPPUNIT_TEST_SUITE(mitkUIDGeneratorTestSuite); MITK_TEST(UIDGeneratorInstanceRenewalSucceed); MITK_TEST(UIDGeneratorMultipleInstancesSucceed); CPPUNIT_TEST_SUITE_END(); unsigned short m_UidLengthStart = 5; unsigned short m_UidLengthEnd = 20; void UIDGeneratorInstanceRenewalSucceed() { for (auto k = m_UidLengthStart; k < m_UidLengthEnd; ++k) { mitk::UIDGenerator uidGen1("UID_", k); auto uid1_1 = uidGen1.GetUID(); uidGen1 = mitk::UIDGenerator("UID_", k); auto uid2_1 = uidGen1.GetUID(); CPPUNIT_ASSERT_MESSAGE("Different UIDs are not allowed to be equal", uid1_1 != uid2_1); } } void UIDGeneratorMultipleInstancesSucceed() { for (auto k = m_UidLengthStart; k < m_UidLengthEnd; ++k) { mitk::UIDGenerator uidGen1("UID_", k); mitk::UIDGenerator uidGen2("UID_", k); auto uid1_1 = uidGen1.GetUID(); auto uid2_1 = uidGen2.GetUID(); CPPUNIT_ASSERT_MESSAGE("Different UIDs are not allowed to be equal", uid1_1 != uid2_1); } } }; MITK_TEST_SUITE_REGISTRATION(mitkUIDGenerator)