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
mitkPropertyExtensionsTest.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 <mitkCoreServices.h>
19 #include <mitkPropertyExtension.h>
20 #include <mitkTestingMacros.h>
21 
22 class TestPropertyExtension : public mitk::PropertyExtension
23 {
24 public:
25  mitkClassMacro(TestPropertyExtension, mitk::PropertyExtension);
26  mitkNewMacro1Param(Self, const std::string &);
27 
28  std::string GetName() const { return m_Name; }
29 private:
30  explicit TestPropertyExtension(const std::string &name) : m_Name(name) {}
31  ~TestPropertyExtension() {}
32  std::string m_Name;
33 };
34 
35 int mitkPropertyExtensionsTest(int, char *[])
36 {
37  MITK_TEST_BEGIN("mitkPropertyExtensionsTest");
38 
40  MITK_TEST_CONDITION_REQUIRED(propertyExtensions != NULL, "Get property extensions service");
41 
42  propertyExtensions->AddExtension("propertyName1", TestPropertyExtension::New("extension1a").GetPointer());
43  propertyExtensions->AddExtension("propertyName1", TestPropertyExtension::New("extension1b").GetPointer());
45  dynamic_cast<TestPropertyExtension *>(propertyExtensions->GetExtension("propertyName1").GetPointer());
46 
47  MITK_TEST_CONDITION(extension1.IsNotNull() && extension1->GetName() == "extension1a",
48  "Get extension of \"propertyName1\"");
49 
50  propertyExtensions->AddExtension("propertyName1", TestPropertyExtension::New("extension1b").GetPointer(), "", true);
51  extension1 = dynamic_cast<TestPropertyExtension *>(propertyExtensions->GetExtension("propertyName1").GetPointer());
52 
53  MITK_TEST_CONDITION(extension1.IsNotNull() && extension1->GetName() == "extension1b",
54  "Get overwritten extension of \"propertyName1\"");
55 
56  propertyExtensions->AddExtension(
57  "propertyName1", TestPropertyExtension::New("extension1c").GetPointer(), "className");
59  dynamic_cast<TestPropertyExtension *>(propertyExtensions->GetExtension("propertyName1", "className").GetPointer());
60  extension1 = dynamic_cast<TestPropertyExtension *>(propertyExtensions->GetExtension("propertyName1").GetPointer());
61 
62  MITK_TEST_CONDITION(extension1.IsNotNull() && extension1->GetName() == "extension1b" && extension2.IsNotNull() &&
63  extension2->GetName() == "extension1c",
64  "Get extension of \"propertyName1\" restricted to \"className\"");
65 
66  MITK_TEST_END();
67 }
#define mitkNewMacro1Param(classname, type)
Definition: mitkCommon.h:76
int mitkPropertyExtensionsTest(int, char *[])
static IPropertyExtensions * GetPropertyExtensions(us::ModuleContext *context=us::GetModuleContext())
Get an IPropertyExtensions instance.
#define MITK_TEST_CONDITION_REQUIRED(COND, MSG)
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
virtual PropertyExtension::Pointer GetExtension(const std::string &propertyName, const std::string &className="")=0
Get the extension of a specific property.
Interface of property extensions service.
#define MITK_TEST_CONDITION(COND, MSG)
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:44
Base class for all property extensions.
static std::string GetName(std::string fileName, std::string suffix)
and MITK_TEST_END()
virtual bool AddExtension(const std::string &propertyName, PropertyExtension::Pointer extension, const std::string &className="", bool overwrite=false)=0
Add an extension to a specific property.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.