Medical Imaging Interaction Toolkit  2018.4.99-12ad79a3
Medical Imaging Interaction Toolkit
mitkPropertyFiltersTest.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 // Testing
14 #include "mitkTestFixture.h"
15 #include "mitkTestingMacros.h"
16 // std includes
17 #include <string>
18 #include <utility>
19 // MITK includes
20 #include <mitkCoreServices.h>
21 #include <mitkIPropertyFilters.h>
22 #include <mitkProperties.h>
23 #include <mitkPropertyFilter.h>
24 // VTK includes
25 #include <vtkDebugLeaks.h>
26 
27 class mitkPropertyFiltersTestSuite : public mitk::TestFixture
28 {
29  CPPUNIT_TEST_SUITE(mitkPropertyFiltersTestSuite);
30  MITK_TEST(GetPropertyFiltersService_Success);
31  MITK_TEST(ApplyGlobalPropertyFilter_Success);
32  MITK_TEST(ApplyRestrictedPropertyFilter_Success);
33  CPPUNIT_TEST_SUITE_END();
34 
35 private:
36  mitk::IPropertyFilters *m_PropertyFilters;
37  typedef std::map<std::string, mitk::BaseProperty::Pointer> PropertyMap;
38  typedef PropertyMap::const_iterator PropertyMapConstIterator;
39  PropertyMap m_PropertyMap;
40  mitk::PropertyFilter m_Filter;
41  mitk::PropertyFilter m_RestrictedFilter;
42  PropertyMap m_FilteredPropertyMap;
43  PropertyMapConstIterator m_It1;
44  PropertyMapConstIterator m_It2;
45  PropertyMapConstIterator m_It3;
46 
47 public:
48  void setUp()
49  {
50  m_PropertyFilters = mitk::CoreServices::GetPropertyFilters();
51 
52  m_PropertyMap.insert(std::make_pair("propertyName1", mitk::BoolProperty::New().GetPointer()));
53  m_PropertyMap.insert(std::make_pair("propertyName2", mitk::BoolProperty::New().GetPointer()));
54  m_PropertyMap.insert(std::make_pair("propertyName3", mitk::BoolProperty::New().GetPointer()));
55 
56  m_Filter.AddEntry("propertyName1", mitk::PropertyFilter::Whitelist);
57  m_Filter.AddEntry("propertyName2", mitk::PropertyFilter::Whitelist);
58 
59  m_RestrictedFilter.AddEntry("propertyName2", mitk::PropertyFilter::Blacklist);
60 
61  m_PropertyFilters->AddFilter(m_Filter);
62  m_PropertyFilters->AddFilter(m_RestrictedFilter, "className");
63  }
64  void tearDown()
65  {
66  m_PropertyFilters = nullptr;
67  }
68 
69  void GetPropertyFiltersService_Success()
70  {
71  CPPUNIT_ASSERT_MESSAGE("Get property filters service", m_PropertyFilters != nullptr);
72  }
73 
74  void ApplyGlobalPropertyFilter_Success()
75  {
76  m_FilteredPropertyMap = m_PropertyFilters->ApplyFilter(m_PropertyMap);
77  m_It1 = m_FilteredPropertyMap.find("propertyName1");
78  m_It2 = m_FilteredPropertyMap.find("propertyName2");
79  m_It3 = m_FilteredPropertyMap.find("propertyName3");
80 
81  CPPUNIT_ASSERT_MESSAGE("Apply global property filter",
82  m_It1 != m_FilteredPropertyMap.end() && m_It2 != m_FilteredPropertyMap.end() && m_It3 == m_FilteredPropertyMap.end());
83  }
84 
85  void ApplyRestrictedPropertyFilter_Success()
86  {
87  m_FilteredPropertyMap = m_PropertyFilters->ApplyFilter(m_PropertyMap, "className");
88  m_It1 = m_FilteredPropertyMap.find("propertyName1");
89  m_It2 = m_FilteredPropertyMap.find("propertyName2");
90  m_It3 = m_FilteredPropertyMap.find("propertyName3");
91 
92  CPPUNIT_ASSERT_MESSAGE("Apply restricted property filter (also respects global filter)",
93  m_It1 != m_FilteredPropertyMap.end() && m_It2 == m_FilteredPropertyMap.end() && m_It3 == m_FilteredPropertyMap.end());
94  }
95 };
96 MITK_TEST_SUITE_REGISTRATION(mitkPropertyFilters)
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
void AddEntry(const std::string &propertyName, List list)
Add a filter entry for a specific property.
virtual bool AddFilter(const PropertyFilter &filter, const std::string &className="", bool overwrite=false)=0
Add a property filter.
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
virtual std::map< std::string, BaseProperty::Pointer > ApplyFilter(const std::map< std::string, BaseProperty::Pointer > &propertyMap, const std::string &className="") const =0
Apply property filter to property list.
static Pointer New()
Test fixture for parameterized tests.
Interface of property filters service.
static IPropertyFilters * GetPropertyFilters(us::ModuleContext *context=us::GetModuleContext())
Get an IPropertyFilters instance.
Consists of blacklist and whitelist entries.