diff --git a/Modules/Core/test/mitkBaseDataTest.cpp b/Modules/Core/test/mitkBaseDataTest.cpp index 550dd039a7..cce75d8ab6 100644 --- a/Modules/Core/test/mitkBaseDataTest.cpp +++ b/Modules/Core/test/mitkBaseDataTest.cpp @@ -1,283 +1,282 @@ /*=================================================================== 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(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/mitkPixelTypeTest.cpp b/Modules/Core/test/mitkPixelTypeTest.cpp index c83e2c5bb5..9b54e1040e 100644 --- a/Modules/Core/test/mitkPixelTypeTest.cpp +++ b/Modules/Core/test/mitkPixelTypeTest.cpp @@ -1,154 +1,245 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ -#include "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 506b263029..2fe8aa548d 100644 --- a/Modules/Core/test/mitkPropertyAliasesTest.cpp +++ b/Modules/Core/test/mitkPropertyAliasesTest.cpp @@ -1,67 +1,110 @@ /*=================================================================== 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 #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 ee16f25e66..c067006310 100644 --- a/Modules/Core/test/mitkPropertyDescriptionsTest.cpp +++ b/Modules/Core/test/mitkPropertyDescriptionsTest.cpp @@ -1,47 +1,84 @@ /*=================================================================== 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 +#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 00aeb9d58d..a9654f3c95 100644 --- a/Modules/Core/test/mitkPropertyExtensionsTest.cpp +++ b/Modules/Core/test/mitkPropertyExtensionsTest.cpp @@ -1,67 +1,104 @@ /*=================================================================== 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 +#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 19b7da274a..27b200b7ff 100644 --- a/Modules/Core/test/mitkPropertyFiltersTest.cpp +++ b/Modules/Core/test/mitkPropertyFiltersTest.cpp @@ -1,69 +1,100 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ -#include +// 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 47a7ac4c40..298fb77d66 100644 --- a/Modules/Core/test/mitkPropertyTest.cpp +++ b/Modules/Core/test/mitkPropertyTest.cpp @@ -1,438 +1,493 @@ /*=================================================================== 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 #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 69dd7575aa..3a952f931b 100644 --- a/Modules/Core/test/mitkTinyXMLTest.cpp +++ b/Modules/Core/test/mitkTinyXMLTest.cpp @@ -1,164 +1,163 @@ /*=================================================================== 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 // 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() {} void tearDown() {} 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 9000834607..31469faf8b 100644 --- a/Modules/Core/test/mitkUIDGeneratorTest.cpp +++ b/Modules/Core/test/mitkUIDGeneratorTest.cpp @@ -1,85 +1,99 @@ /*=================================================================== 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 "mitkUIDGenerator.h" #include -#include +// VTK includes +#include -void newGeneratorInstancesHeapTest() +class mitkUIDGeneratorTestSuite : public mitk::TestFixture { - auto uidGen1 = new mitk::UIDGenerator("UID_", 8); - mitk::UIDGenerator *uidGen2 = uidGen1; - std::string uid1_1, uid2_1; - - uid1_1 = uidGen1->GetUID(); - - uidGen1 = new mitk::UIDGenerator("UID_", 8); - - uid2_1 = uidGen1->GetUID(); - - delete uidGen1; - delete uidGen2; - - MITK_TEST_CONDITION(uid1_1 != uid2_1, "Different UIDs are not allowed to be equal"); -} - -void multipleUIDsFromSameGeneratorTest(int /*UIDlength*/) -{ - auto uidGen = new mitk::UIDGenerator("UID_", 8); - std::string uid1, uid2; - uid1 = uidGen->GetUID(); - uid2 = uidGen->GetUID(); - delete uidGen; - MITK_TEST_CONDITION(uid1 != uid2, - "Testing two UIDs from the same generator. Different UIDs are not allowed to be equal"); -} - -void newGeneratorInstancesTest() -{ - mitk::UIDGenerator uidGen1("UID_", 8); - std::string uid1_1, uid2_1; - - uid1_1 = uidGen1.GetUID(); - - uidGen1 = mitk::UIDGenerator("UID_", 8); - - uid2_1 = uidGen1.GetUID(); - - MITK_TEST_CONDITION(uid1_1 != uid2_1, "Different UIDs are not allowed to be equal"); -} - -void severalGeneratorInstancesTest() -{ - mitk::UIDGenerator uidGen1("UID_", 8); - mitk::UIDGenerator uidGen2("UID_", 8); - std::string uid1_1, uid2_1; - - uid1_1 = uidGen1.GetUID(); - uid2_1 = uidGen2.GetUID(); - - MITK_TEST_CONDITION(uid1_1 != uid2_1, "Different UIDs are not allowed to be equal"); -} - -int mitkUIDGeneratorTest(int /*argc*/, char * /*argv*/ []) -{ - MITK_TEST_BEGIN("mitkUIDGeneratorTest"); - severalGeneratorInstancesTest(); - newGeneratorInstancesTest(); - newGeneratorInstancesHeapTest(); - multipleUIDsFromSameGeneratorTest(8); - multipleUIDsFromSameGeneratorTest(16); - MITK_TEST_END(); -} + CPPUNIT_TEST_SUITE(mitkUIDGeneratorTestSuite); + MITK_TEST(newGeneratorInstancesHeap_DifferentUIDs); + MITK_TEST(multipleUIDsFromSameGenerator_DifferentUIDs); + MITK_TEST(newGeneratorInstances_DifferentUIDs); + MITK_TEST(severalGeneratorInstances_DifferentUIDs); + CPPUNIT_TEST_SUITE_END(); + + +private: + std::string m_Uid1, m_Uid2; + +public: + void setUp() + { + } + + void tearDown() + { + m_Uid1 = ""; + m_Uid2 = ""; + } + + void newGeneratorInstancesHeap_DifferentUIDs() + { + auto uidGen1 = new mitk::UIDGenerator("UID_", 8); + mitk::UIDGenerator *uidGen2 = uidGen1; + m_Uid1 = uidGen1->GetUID(); + + uidGen1 = new mitk::UIDGenerator("UID_", 8); + + m_Uid2 = uidGen1->GetUID(); + + delete uidGen1; + delete uidGen2; + + CPPUNIT_ASSERT_MESSAGE("First UIDs of two different generators are not allowed to be equal.", m_Uid1 != m_Uid2); + } + + void multipleUIDsFromSameGenerator_DifferentUIDs() + { + auto uidGen = new mitk::UIDGenerator("UID_", 8); + m_Uid1 = uidGen->GetUID(); + m_Uid2 = uidGen->GetUID(); + delete uidGen; + CPPUNIT_ASSERT_MESSAGE("Testing two UIDs from the same generator. Different UIDs are not allowed to be equal", m_Uid1 != m_Uid2); + } + + void newGeneratorInstances_DifferentUIDs() + { + mitk::UIDGenerator uidGen1("UID_", 8); + m_Uid1 = uidGen1.GetUID(); + + uidGen1 = mitk::UIDGenerator("UID_", 8); + m_Uid2 = uidGen1.GetUID(); + + CPPUNIT_ASSERT_MESSAGE("Testing two UIDs from new Instances. Different UIDs are not allowed to be equal", m_Uid1 != m_Uid2); + } + + void severalGeneratorInstances_DifferentUIDs() + { + mitk::UIDGenerator uidGen1("UID_", 8); + mitk::UIDGenerator uidGen2("UID_", 8); + + m_Uid1 = uidGen1.GetUID(); + m_Uid2 = uidGen2.GetUID(); + + CPPUNIT_ASSERT_MESSAGE("Testing two UIDs from different Generators. Different UIDs are not allowed to be equal", m_Uid1 != m_Uid2); + } +}; +MITK_TEST_SUITE_REGISTRATION(mitkUIDGenerator)