Medical Imaging Interaction Toolkit  2018.4.99-b20efe7f
Medical Imaging Interaction Toolkit
mitkNodePredicateDataPropertyTest.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 #include "mitkGeometry3D.h"
16 #include "mitkDataNode.h"
17 #include "mitkTestFixture.h"
18 #include "mitkTestingMacros.h"
19 #include "mitkStringProperty.h"
20 
21 
22 class mitkNodePredicateDataPropertyTestSuite : public mitk::TestFixture
23 {
24  CPPUNIT_TEST_SUITE(mitkNodePredicateDataPropertyTestSuite);
25  MITK_TEST(Check_InvalidConstructor);
26  MITK_TEST(Check_InvalidCheckNode);
27  MITK_TEST(Check_CheckName);
28  MITK_TEST(Check_CheckNameAndValue);
29  CPPUNIT_TEST_SUITE_END();
30 
31 private:
35  mitk::DataNode::Pointer m_NullNode;
36  mitk::DataNode::Pointer m_NullDataNode;
37  mitk::DataNode::Pointer m_OtherNode;
38  mitk::DataNode::Pointer m_NoPropNode;
39 
40  mitk::StringProperty::Pointer m_RefProperty;
41 
42 public:
47  void setUp() override
48  {
49  m_RefProperty = mitk::StringProperty::New("value1");
50 
52  m_Data->SetProperty("prop1", mitk::StringProperty::New("value1"));
53  m_Data->SetProperty("prop2", mitk::StringProperty::New("value2"));
54 
56  m_OtherData->SetProperty("prop1", mitk::StringProperty::New("othervalue"));
57 
58  m_NullNode = nullptr;
59 
60  m_NullDataNode = mitk::DataNode::New();
61 
62  m_Node = mitk::DataNode::New();
63  m_Node->SetData(m_Data);
64 
65  m_OtherNode = mitk::DataNode::New();
66  m_OtherNode->SetData(m_OtherData);
67 
68  m_NoPropNode = mitk::DataNode::New();
69  m_NoPropNode->SetData(mitk::BaseDataTestImplementation::New());
70  }
71 
72  void tearDown() override
73  {
74  m_Node = nullptr;
75  m_NullNode = nullptr;
76  m_NullDataNode = nullptr;
77  m_OtherNode = nullptr;
78  m_Data = nullptr;
79  m_OtherData = nullptr;
80  }
81 
82  void Check_InvalidConstructor()
83  {
84  CPPUNIT_ASSERT_THROW(mitk::NodePredicateDataProperty::New(""), mitk::Exception);
85  }
86 
87  void Check_InvalidCheckNode()
88  {
90 
91  CPPUNIT_ASSERT_THROW(predicate->CheckNode(nullptr), mitk::Exception);
92  }
93 
94  void Check_CheckName()
95  {
97 
98  CPPUNIT_ASSERT(!predicate->CheckNode(m_NullDataNode));
99  CPPUNIT_ASSERT(predicate->CheckNode(m_Node));
100  CPPUNIT_ASSERT(predicate->CheckNode(m_OtherNode));
101  CPPUNIT_ASSERT(!predicate->CheckNode(m_NoPropNode));
102  }
103 
104  void Check_CheckNameAndValue()
105  {
107 
108  CPPUNIT_ASSERT(!predicate->CheckNode(m_NullDataNode));
109  CPPUNIT_ASSERT(predicate->CheckNode(m_Node));
110  CPPUNIT_ASSERT(!predicate->CheckNode(m_OtherNode));
111  CPPUNIT_ASSERT(!predicate->CheckNode(m_NoPropNode));
112  }
113 };
114 
115 MITK_TEST_SUITE_REGISTRATION(mitkNodePredicateDataProperty)
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
mitk::DataNode::Pointer m_Node
static Pointer New()
An object of this class represents an exception of MITK. Please don't instantiate exceptions manually...
Definition: mitkException.h:45
Test fixture for parameterized tests.
static Pointer New(const char *_arg)
static Pointer New()