Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
mitkPropertyAliasesTest.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 <mitkIPropertyAliases.h>
20 #include <mitkTestingMacros.h>
21 
22 int mitkPropertyAliasesTest(int, char *[])
23 {
24  MITK_TEST_BEGIN("mitkPropertyAliasesTest");
25 
27  MITK_TEST_CONDITION_REQUIRED(propertyAliases != NULL, "Get property aliases service");
28 
29  propertyAliases->AddAlias("propertyName1", "alias1a");
30  propertyAliases->AddAlias("propertyName1", "alias1b");
31  propertyAliases->AddAlias("propertyName2", "alias2a");
32  propertyAliases->AddAlias("propertyName2", "alias2b", "className");
33 
34  typedef std::vector<std::string> Aliases;
35  typedef Aliases::iterator AliasesIterator;
36 
37  Aliases aliases = propertyAliases->GetAliases("propertyName1");
38  AliasesIterator it1 = std::find(aliases.begin(), aliases.end(), "alias1a");
39  AliasesIterator it2 = std::find(aliases.begin(), aliases.end(), "alias1b");
40 
41  MITK_TEST_CONDITION(aliases.size() == 2 && it1 != aliases.end() && it2 != aliases.end(),
42  "Get aliases of \"propertyName1\"");
43 
44  aliases = propertyAliases->GetAliases("propertyName2");
45  it1 = std::find(aliases.begin(), aliases.end(), "alias2a");
46 
47  MITK_TEST_CONDITION(aliases.size() == 1 && it1 != aliases.end(), "Get aliases of \"propertyName2\"");
48 
49  aliases = propertyAliases->GetAliases("propertyName2", "className");
50  it1 = std::find(aliases.begin(), aliases.end(), "alias2b");
51 
52  MITK_TEST_CONDITION(aliases.size() == 1 && it1 != aliases.end(),
53  "Get aliases of \"propertyName2\" restricted to \"className\"");
54 
55  std::string propertyName = propertyAliases->GetPropertyName("alias1b");
56 
57  MITK_TEST_CONDITION(propertyName == "propertyName1", "Get property name of \"alias1b\"");
58 
59  propertyName = propertyAliases->GetPropertyName("alias2b");
60 
61  MITK_TEST_CONDITION(propertyName.empty(), "Get property name of non-existing unrestricted \"alias2b\"");
62 
63  propertyName = propertyAliases->GetPropertyName("alias2b", "className");
64 
65  MITK_TEST_CONDITION(propertyName == "propertyName2", "Get property name of restricted \"alias2b\"");
66 
67  MITK_TEST_END();
68 }
virtual std::string GetPropertyName(const std::string &alias, const std::string &className="")=0
Get property name that is associated to specific alias.
Interface of property aliases service.
#define MITK_TEST_CONDITION_REQUIRED(COND, MSG)
virtual bool AddAlias(const std::string &propertyName, const std::string &alias, const std::string &className="")=0
Add an alias for a specific property.
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
virtual std::vector< std::string > GetAliases(const std::string &propertyName, const std::string &className="")=0
Get aliases for a specific property.
#define MITK_TEST_CONDITION(COND, MSG)
int mitkPropertyAliasesTest(int, char *[])
and MITK_TEST_END()
static IPropertyAliases * GetPropertyAliases(us::ModuleContext *context=us::GetModuleContext())
Get an IPropertyAliases instance.