Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
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 (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 <algorithm>
19 // MITK includes
20 #include <mitkCoreServices.h>
21 #include <mitkIPropertyAliases.h>
22 // VTK includes
23 #include <vtkDebugLeaks.h>
24 
25 class mitkPropertyAliasesTestSuite : public mitk::TestFixture
26 {
27  CPPUNIT_TEST_SUITE(mitkPropertyAliasesTestSuite);
28  MITK_TEST(GetPropertyAliasesService_Success);
29  MITK_TEST(GetAliases_Success);
30  MITK_TEST(GetAliasesRestricted_Success);
31  MITK_TEST(GetPropertyName_Success);
32  MITK_TEST(GetPropertyNameNonexisting_Empty);
33  MITK_TEST(GetPropertyNameRestricted_Success);
34  CPPUNIT_TEST_SUITE_END();
35 
36 private:
37  mitk::IPropertyAliases *m_PropertyAliases;
38  typedef std::vector<std::string> Aliases;
39  Aliases m_Aliases;
40  std::string m_PropertyName;
41 
42 public:
43  void setUp()
44  {
45  m_PropertyAliases = mitk::CoreServices::GetPropertyAliases();
46  m_PropertyAliases->AddAlias("propertyName1", "alias1a");
47  m_PropertyAliases->AddAlias("propertyName1", "alias1b");
48  m_PropertyAliases->AddAlias("propertyName2", "alias2a");
49  m_PropertyAliases->AddAlias("propertyName2", "alias2b", "className");
50  }
51  void tearDown()
52  {
53  m_PropertyAliases = nullptr;
54  }
55 
56 
57  void GetPropertyAliasesService_Success()
58  {
59  CPPUNIT_ASSERT_MESSAGE("Get property aliases service", m_PropertyAliases != nullptr);
60  }
61 
62  void GetAliases_Success()
63  {
64  m_Aliases = m_PropertyAliases->GetAliases("propertyName1");
65  auto it1 = std::find(m_Aliases.begin(), m_Aliases.end(), "alias1a");
66  auto it2 = std::find(m_Aliases.begin(), m_Aliases.end(), "alias1b");
67 
68  CPPUNIT_ASSERT_MESSAGE("Get aliases of \"propertyName1\"", m_Aliases.size() == 2 && it1 != m_Aliases.end() && it2 != m_Aliases.end());
69 
70  m_Aliases = m_PropertyAliases->GetAliases("propertyName2");
71  it1 = std::find(m_Aliases.begin(), m_Aliases.end(), "alias2a");
72 
73  CPPUNIT_ASSERT_MESSAGE("Get aliases of \"propertyName2\"", m_Aliases.size() == 1 && it1 != m_Aliases.end());
74  }
75 
76  void GetAliasesRestricted_Success()
77  {
78  m_Aliases = m_PropertyAliases->GetAliases("propertyName2", "className");
79  auto it1 = std::find(m_Aliases.begin(), m_Aliases.end(), "alias2b");
80 
81  CPPUNIT_ASSERT_MESSAGE("Get aliases of \"propertyName2\" restricted to \"className\"", m_Aliases.size() == 1 && it1 != m_Aliases.end());
82  }
83 
84  void GetPropertyName_Success()
85  {
86  m_PropertyName = m_PropertyAliases->GetPropertyName("alias1b");
87 
88  CPPUNIT_ASSERT_MESSAGE("Get property name of \"alias1b\"", m_PropertyName == "propertyName1");
89  }
90 
91  void GetPropertyNameNonexisting_Empty()
92  {
93  m_PropertyName = m_PropertyAliases->GetPropertyName("alias2b");
94 
95  CPPUNIT_ASSERT_MESSAGE("Get property name of non-existing unrestricted \"alias2b\"", m_PropertyName.empty());
96  }
97 
98  void GetPropertyNameRestricted_Success()
99  {
100  m_PropertyName = m_PropertyAliases->GetPropertyName("alias2b", "className");
101 
102  CPPUNIT_ASSERT_MESSAGE("Get property name of restricted \"alias2b\"", m_PropertyName == "propertyName2");
103  }
104 };
105 
106 MITK_TEST_SUITE_REGISTRATION(mitkPropertyAliases)
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.
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
virtual bool AddAlias(const std::string &propertyName, const std::string &alias, const std::string &className="")=0
Add an alias for a specific property.
virtual std::vector< std::string > GetAliases(const std::string &propertyName, const std::string &className="")=0
Get aliases for a specific property.
Test fixture for parameterized tests.
static IPropertyAliases * GetPropertyAliases(us::ModuleContext *context=us::GetModuleContext())
Get an IPropertyAliases instance.