diff --git a/Modules/Core/test/mitkBaseDataTest.cpp b/Modules/Core/test/mitkBaseDataTest.cpp index 8a146ff36f..5d79d46616 100644 --- a/Modules/Core/test/mitkBaseDataTest.cpp +++ b/Modules/Core/test/mitkBaseDataTest.cpp @@ -1,210 +1,283 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ // Testing #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(TestingGetTimeGeometry_Success); - MITK_TEST(TestingGetGeometry_Failure); + 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(TestingSetAndGetProperty_Success); - MITK_TEST(TestingSetAndGetPropertyList_Success); - MITK_TEST(TestingUpdateOutputInformation_Failure); - MITK_TEST(TestingCopyInformation_Failure); + + 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::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_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_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 + // Create a BaseData implementation MITK_INFO << "Creating a base data instance..."; - - m_baseDataImpl = mitk::BaseDataTestImplementation::New(); - CPPUNIT_ASSERT_MESSAGE("Testing instantiation", m_baseDataImpl.IsNotNull()); - CPPUNIT_ASSERT_MESSAGE("BaseDataTestImplementation is initialized", m_baseDataImpl->IsInitialized()); - CPPUNIT_ASSERT_MESSAGE("BaseDataTestImplementation is initialized and empty", m_baseDataImpl->IsEmpty()); + CPPUNIT_ASSERT_MESSAGE("Testing instantiation", m_BaseDataImpl.IsNotNull()); + } - m_cloneBaseData = m_baseDataImpl->Clone(); - CPPUNIT_ASSERT_MESSAGE("Testing instantiation of base data clone", m_cloneBaseData.IsNotNull()); - 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 InitializationOfBaseData_Success() + { + CPPUNIT_ASSERT_MESSAGE("BaseDataTestImplementation is initialized", m_BaseDataImpl->IsInitialized()); + CPPUNIT_ASSERT_MESSAGE("BaseDataTestImplementation is initialized and empty", m_BaseDataImpl->IsEmpty()); + } - MITK_INFO << "Testing setter and getter for geometries..."; + 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 TestingGetTimeGeometry_Success() + void InitializationOfCloneBaseData_Success() { - // test method GetTimeGeometry() - m_baseDataImpl = mitk::BaseDataTestImplementation::New(); - m_geo2 = mitk::ProportionalTimeGeometry::New(); - CPPUNIT_ASSERT_MESSAGE("Testing creation of TimeGeometry", m_baseDataImpl->GetTimeGeometry()); + CPPUNIT_ASSERT_MESSAGE("Clone of BaseDataTestImplementation is initialized", m_CloneBaseData->IsInitialized()); + CPPUNIT_ASSERT_MESSAGE("Clone of BaseDataTestImplementation is initialized and empty", m_CloneBaseData->IsEmpty()); + } - m_baseDataImpl->SetTimeGeometry(m_geo); + void GetAndSetTimeGeometry_Success() + { + // test method GetTimeGeometry() + MITK_INFO << "Testing setter and getter for geometries..."; + CPPUNIT_ASSERT_MESSAGE("Testing creation of TimeGeometry", m_BaseDataImpl->GetTimeGeometry()); + } - CPPUNIT_ASSERT_MESSAGE("Reset Geometry", m_baseDataImpl->GetTimeGeometry() == nullptr); + void ResetTimeGeometry_Success() + { + m_BaseDataImpl->SetTimeGeometry(m_Geo); + CPPUNIT_ASSERT_MESSAGE("Reset Geometry", m_BaseDataImpl->GetTimeGeometry() == nullptr); + } - m_baseDataImpl->SetTimeGeometry(m_geo2); - m_geo2->Initialize(2); - CPPUNIT_ASSERT_MESSAGE("Correct Reinit of TimeGeometry", m_baseDataImpl->GetTimeGeometry() == m_geo2.GetPointer()); + 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 TestingGetGeometry_Failure() + void GetGeometryForSingleTimeGeometries_Failure() { // test method GetGeometry(int timeStep) - m_baseDataImpl = mitk::BaseDataTestImplementation::New(); - CPPUNIT_ASSERT_MESSAGE("... and single Geometries", m_baseDataImpl->GetGeometry(1) == nullptr); + CPPUNIT_ASSERT_MESSAGE("Testing Creation of single TimeGeometries", m_BaseDataImpl->GetGeometry(1) == nullptr); } void TestingExpand_Success() { // test method Expand(unsigned int timeSteps) - m_baseDataImpl = mitk::BaseDataTestImplementation::New(); - m_baseDataImpl->Expand(5); - CPPUNIT_ASSERT_MESSAGE("Expand the geometry to further time slices!", m_baseDataImpl->GetTimeSteps() == 5); + m_BaseDataImpl->Expand(5); + CPPUNIT_ASSERT_MESSAGE("Expand the geometry to further time slices!", m_BaseDataImpl->GetTimeSteps() == 5); } - void TestingGetUpdateGeometry_Success() + void TestingGetUpdateGeometry_Success() { // test method GetUpdatedGeometry(int timeStep); - m_baseDataImpl = mitk::BaseDataTestImplementation::New(); - m_baseDataImpl->Expand(5); - mitk::Geometry3D::Pointer geometry3D = mitk::Geometry3D::New(); - mitk::BaseGeometry::Pointer geo3 = dynamic_cast(geometry3D.GetPointer()); + m_BaseDataImpl->Expand(5); mitk::ProportionalTimeGeometry::Pointer timeGeometry = - dynamic_cast(m_baseDataImpl->GetTimeGeometry()); + dynamic_cast(m_BaseDataImpl->GetTimeGeometry()); if (timeGeometry.IsNotNull()) { - timeGeometry->SetTimeStepGeometry(geo3, 1); + timeGeometry->SetTimeStepGeometry(m_Geo3, 1); } - - CPPUNIT_ASSERT_MESSAGE("Set Geometry for time step 1", m_baseDataImpl->GetUpdatedGeometry(1) == geo3); - CPPUNIT_ASSERT_MESSAGE("Check if modified time is set", m_baseDataImpl->GetMTime() != 0); - m_baseDataImpl->SetClonedGeometry(geo3, 1); - - mitk::ScalarType x[3]; - x[0] = 2; - x[1] = 4; - x[2] = 6; - mitk::Point3D p3d(x); - m_baseDataImpl->SetOrigin(p3d); - geo3->SetOrigin(p3d); - - CPPUNIT_ASSERT_MESSAGE("Testing Origin set", m_baseDataImpl->GetGeometry(1)->GetOrigin() == geo3->GetOrigin()); - m_cloneBaseData = m_baseDataImpl->Clone(); - CPPUNIT_ASSERT_MESSAGE("Testing origin set in clone!", m_cloneBaseData->GetGeometry(1)->GetOrigin() == geo3->GetOrigin()); - - 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 TestingSetAndGetProperty_Success() - { - //test method Set-/GetProperty() - m_baseDataImpl = mitk::BaseDataTestImplementation::New(); - m_baseDataImpl->SetProperty("property38", mitk::StringProperty::New("testproperty")); - CPPUNIT_ASSERT_MESSAGE("Check if base property is set correctly!", m_baseDataImpl->GetProperty("property38")->GetValueAsString() == "testproperty"); - - m_cloneBaseData = m_baseDataImpl->Clone(); - CPPUNIT_ASSERT_MESSAGE("Testing origin set in clone!", m_cloneBaseData->GetProperty("property38")->GetValueAsString() == "testproperty"); + + 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 TestingSetAndGetPropertyList_Success() + 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_baseDataImpl = mitk::BaseDataTestImplementation::New(); - mitk::PropertyList::Pointer propertyList = mitk::PropertyList::New(); - propertyList->SetFloatProperty("floatProperty1", 123.45); - propertyList->SetBoolProperty("visibility", true); - propertyList->SetStringProperty("nameXY", "propertyName"); - m_baseDataImpl->SetPropertyList(propertyList); + 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 list is set correctly!", m_baseDataImpl->GetPropertyList() == propertyList); CPPUNIT_ASSERT_MESSAGE("Check if base property is set correctly in the property list!", - m_baseDataImpl->GetPropertyList()->GetBoolProperty("visibility", value) == true); + m_BaseDataImpl->GetPropertyList()->GetBoolProperty("visibility", value) == true); } - void TestingUpdateOutputInformation_Failure() + void UpdateOutputInformationOfBaseData_Failure() { // test method UpdateOutputInformation() - m_baseDataImpl = mitk::BaseDataTestImplementation::New(); - m_geo2 = mitk::ProportionalTimeGeometry::New(); - m_baseDataImpl->UpdateOutputInformation(); - m_geo2->Initialize(2); - m_geo2.GetPointer(); - CPPUNIT_ASSERT_MESSAGE("TimeGeometry update!", m_baseDataImpl->GetUpdatedTimeGeometry() != m_geo2); + m_BaseDataImpl->UpdateOutputInformation(); + m_Geo2->Initialize(2); + m_Geo2.GetPointer(); + CPPUNIT_ASSERT_MESSAGE("TimeGeometry update!", m_BaseDataImpl->GetUpdatedTimeGeometry() != m_Geo2); } - void TestingCopyInformation_Failure() + void CopyingInformationOfBaseData_Failure() { // Test method CopyInformation() - m_baseDataImpl = mitk::BaseDataTestImplementation::New(); mitk::BaseDataTestImplementation::Pointer newBaseData = mitk::BaseDataTestImplementation::New(); - newBaseData->CopyInformation(m_baseDataImpl); - CPPUNIT_ASSERT_MESSAGE("Check copying of of Basedata Data Object!", newBaseData->GetTimeGeometry()->CountTimeSteps() != 5); + newBaseData->CopyInformation(m_BaseDataImpl); + CPPUNIT_ASSERT_MESSAGE("Check copying of Basedata Data Object!", newBaseData->GetTimeGeometry()->CountTimeSteps() != 5); } }; MITK_TEST_SUITE_REGISTRATION(mitkBaseData)