Medical Imaging Interaction Toolkit  2016.11.0
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #include <algorithm>
18 #include <mitkCoreServices.h>
19 #include <mitkIPropertyFilters.h>
20 #include <mitkProperties.h>
21 #include <mitkPropertyFilter.h>
22 #include <mitkTestingMacros.h>
23 #include <utility>
24 
25 int mitkPropertyFiltersTest(int, char *[])
26 {
27  MITK_TEST_BEGIN("mitkPropertyFiltersTest");
28 
30  MITK_TEST_CONDITION_REQUIRED(propertyFilters != NULL, "Get property filters service");
31 
32  typedef std::map<std::string, mitk::BaseProperty::Pointer> PropertyMap;
33  typedef PropertyMap::const_iterator PropertyMapConstIterator;
34 
35  PropertyMap propertyMap;
36  propertyMap.insert(std::make_pair("propertyName1", mitk::BoolProperty::New().GetPointer()));
37  propertyMap.insert(std::make_pair("propertyName2", mitk::BoolProperty::New().GetPointer()));
38  propertyMap.insert(std::make_pair("propertyName3", mitk::BoolProperty::New().GetPointer()));
39 
40  mitk::PropertyFilter filter;
41  filter.AddEntry("propertyName1", mitk::PropertyFilter::Whitelist);
42  filter.AddEntry("propertyName2", mitk::PropertyFilter::Whitelist);
43 
44  mitk::PropertyFilter restrictedFilter;
45  restrictedFilter.AddEntry("propertyName2", mitk::PropertyFilter::Blacklist);
46 
47  propertyFilters->AddFilter(filter);
48  propertyFilters->AddFilter(restrictedFilter, "className");
49 
50  PropertyMap filteredPropertyMap = propertyFilters->ApplyFilter(propertyMap);
51  PropertyMapConstIterator it1 = filteredPropertyMap.find("propertyName1");
52  PropertyMapConstIterator it2 = filteredPropertyMap.find("propertyName2");
53  PropertyMapConstIterator it3 = filteredPropertyMap.find("propertyName3");
54 
56  it1 != filteredPropertyMap.end() && it2 != filteredPropertyMap.end() && it3 == filteredPropertyMap.end(),
57  "Apply global property filter");
58 
59  filteredPropertyMap = propertyFilters->ApplyFilter(propertyMap, "className");
60  it1 = filteredPropertyMap.find("propertyName1");
61  it2 = filteredPropertyMap.find("propertyName2");
62  it3 = filteredPropertyMap.find("propertyName3");
63 
65  it1 != filteredPropertyMap.end() && it2 == filteredPropertyMap.end() && it3 == filteredPropertyMap.end(),
66  "Apply restricted property filter (also respects global filter)");
67 
68  MITK_TEST_END();
69 }
void AddEntry(const std::string &propertyName, List list)
Add a filter entry for a specific property.
#define MITK_TEST_CONDITION_REQUIRED(COND, MSG)
virtual bool AddFilter(const PropertyFilter &filter, const std::string &className="", bool overwrite=false)=0
Add a property filter.
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
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()
#define MITK_TEST_CONDITION(COND, MSG)
Interface of property filters service.
and MITK_TEST_END()
static IPropertyFilters * GetPropertyFilters(us::ModuleContext *context=us::GetModuleContext())
Get an IPropertyFilters instance.
int mitkPropertyFiltersTest(int, char *[])
Consists of blacklist and whitelist entries.