Medical Imaging Interaction Toolkit  2018.4.99-6ca56567
Medical Imaging Interaction Toolkit
mitkNodePredicateFunctionTest.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 <mitkDataNode.h>
15 #include <mitkTestFixture.h>
16 #include <mitkTestingMacros.h>
17 
18 bool FreeFunction(const mitk::DataNode *node)
19 {
20  return nullptr != node;
21 }
22 
23 struct FunctionObject
24 {
25  bool operator()(const mitk::DataNode *node) const
26  {
27  return nullptr != node;
28  }
29 };
30 
31 class mitkNodePredicateFunctionTestSuite : public mitk::TestFixture
32 {
33  CPPUNIT_TEST_SUITE(mitkNodePredicateFunctionTestSuite);
34  MITK_TEST(CheckFreeFunction);
35  MITK_TEST(CheckFunctionObject);
36  MITK_TEST(CheckMemberFunction);
37  MITK_TEST(CheckLambdaExpression);
38  CPPUNIT_TEST_SUITE_END();
39 
40  mitk::DataNode::Pointer m_NullNode;
42 
43  bool MemberFunction(const mitk::DataNode *node) const
44  {
45  return nullptr != node;
46  }
47 
48  void Check(mitk::NodePredicateBase *predicate) const
49  {
50  CPPUNIT_ASSERT(!predicate->CheckNode(m_NullNode));
51  CPPUNIT_ASSERT(predicate->CheckNode(m_Node));
52  }
53 
54 public:
55  void setUp() override
56  {
57  m_NullNode = nullptr;
58  m_Node = mitk::DataNode::New();
59  }
60 
61  void tearDown() override
62  {
63  m_NullNode = nullptr;
64  m_Node = nullptr;
65  }
66 
67  void CheckFreeFunction()
68  {
70  this->Check(predicate);
71  }
72 
73  void CheckFunctionObject()
74  {
75  FunctionObject functionObject;
76  auto predicate = mitk::NodePredicateFunction::New(functionObject);
77  this->Check(predicate);
78  }
79 
80  void CheckMemberFunction()
81  {
82  using namespace std::placeholders;
83  auto memberFunction = std::bind(&mitkNodePredicateFunctionTestSuite::MemberFunction, this, _1);
84  auto predicate = mitk::NodePredicateFunction::New(memberFunction);
85  this->Check(predicate);
86  }
87 
88  void CheckLambdaExpression()
89  {
90  auto predicate = mitk::NodePredicateFunction::New([](const mitk::DataNode *node) {
91  return nullptr != node;
92  });
93 
94  this->Check(predicate);
95  }
96 };
97 
98 MITK_TEST_SUITE_REGISTRATION(mitkNodePredicateFunction)
bool FreeFunction(const mitk::DataNode *node)
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
static Pointer New(const FunctionType &_arg)
virtual bool CheckNode(const mitk::DataNode *node) const =0
This method will be used to evaluate the node. Has to be overwritten in subclasses.
mitk::DataNode::Pointer m_Node
static Pointer New()
Test fixture for parameterized tests.
Interface for evaluation conditions used in the DataStorage class GetSubset() method.
Class for nodes of the DataTree.
Definition: mitkDataNode.h:57