Medical Imaging Interaction Toolkit  2018.4.99-93926fb8
Medical Imaging Interaction Toolkit
mitkPropertyDescriptionsTest.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>
22 // VTK includes
23 #include <vtkDebugLeaks.h>
24 
25 class mitkPropertyDescriptionsTestSuite : public mitk::TestFixture
26 {
27  CPPUNIT_TEST_SUITE(mitkPropertyDescriptionsTestSuite);
28  MITK_TEST(GetPropertyDescriptionService_Success);
29  MITK_TEST(GetPropertyDescription_Success);
30  MITK_TEST(GetOverwrittenDescription_Success);
31  MITK_TEST(GetPropertyDescriptionRestricted_Success);
32  CPPUNIT_TEST_SUITE_END();
33 
34  private:
35  mitk::IPropertyDescriptions *m_PropertyDescriptions;
36  std::string m_Description1;
37 
38  public:
39  void setUp()
40  {
41  m_PropertyDescriptions = mitk::CoreServices::GetPropertyDescriptions();
42  m_PropertyDescriptions->AddDescription("propertyName1", "description1a");
43  m_PropertyDescriptions->AddDescription("propertyName1", "description1b");
44  }
45 
46  void tearDown()
47  {
48  m_PropertyDescriptions = nullptr;
49  }
50 
51  void GetPropertyDescriptionService_Success()
52  {
53  CPPUNIT_ASSERT_MESSAGE("Get property descriptions service", m_PropertyDescriptions != nullptr);
54  }
55 
56  void GetPropertyDescription_Success()
57  {
58  m_Description1 = m_PropertyDescriptions->GetDescription("propertyName1");
59  CPPUNIT_ASSERT_MESSAGE("Get description of \"propertyName1\"", m_Description1 == "description1a");
60  }
61 
62  void GetOverwrittenDescription_Success()
63  {
64  m_PropertyDescriptions->AddDescription("propertyName1", "description1b", "", true);
65  m_Description1 = m_PropertyDescriptions->GetDescription("propertyName1");
66  CPPUNIT_ASSERT_MESSAGE("Get overwritten description of \"propertyName1\"", m_Description1 == "description1b");
67  }
68 
69  void GetPropertyDescriptionRestricted_Success()
70  {
71  m_PropertyDescriptions->AddDescription("propertyName1", "description1c", "className");
72  std::string description2 = m_PropertyDescriptions->GetDescription("propertyName1", "className");
73  m_Description1 = m_PropertyDescriptions->GetDescription("propertyName1");
74 
75  CPPUNIT_ASSERT_MESSAGE("Get description of \"propertyName1\" restricted to \"className\"",
76  m_Description1 == "description1b" && description2 == "description1c");
77  }
78 };
79 
80 MITK_TEST_SUITE_REGISTRATION(mitkPropertyDescriptions)
virtual bool AddDescription(const std::string &propertyName, const std::string &description, const std::string &className="", bool overwrite=false)=0
Add a description for a specific property.
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
static IPropertyDescriptions * GetPropertyDescriptions(us::ModuleContext *context=us::GetModuleContext())
Get an IPropertyDescriptions instance.
Interface of property descriptions service.
Test fixture for parameterized tests.
virtual std::string GetDescription(const std::string &propertyName, const std::string &className="", bool allowNameRegEx=true) const =0
Get the description for a specific property.