Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkWeakPointerTest.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 "mitkTestingMacros.h"
18 
19 #include <itkObject.h>
20 #include <mitkWeakPointer.h>
21 
22 int mitkWeakPointerTest(int /*argc*/, char * /*argv*/ [])
23 {
24  MITK_TEST_BEGIN("WeakPointer")
25 
27  mitk::WeakPointer<itk::Object> weakPointer2;
28 
29  // Testing constructors and reference counting
30  itk::Object::Pointer smartPointer = itk::Object::New();
31  mitk::WeakPointer<itk::Object> weakPointer3(smartPointer);
32  mitk::WeakPointer<itk::Object> weakPointer4(weakPointer);
33  {
34  itk::Object::Pointer tmpSmartPointer(weakPointer);
35  itk::Object::Pointer tmpSmartPointer2(weakPointer2);
36  MITK_TEST_CONDITION_REQUIRED(tmpSmartPointer.GetPointer() == tmpSmartPointer2.GetPointer(),
37  "Testing equal pointers");
38  }
39 
40  weakPointer = smartPointer;
41  weakPointer2 = weakPointer;
42 
43  MITK_TEST_CONDITION_REQUIRED(1 == smartPointer->GetReferenceCount(), "Testing reference count");
44  smartPointer = nullptr;
45  MITK_TEST_CONDITION_REQUIRED(weakPointer.IsNull(), "Testing expired weak pointer (smart pointer assignment)");
46  MITK_TEST_CONDITION_REQUIRED(weakPointer2.IsNull(), "Testing expired weak pointer (weak pointer assignment)");
47  MITK_TEST_CONDITION_REQUIRED(weakPointer3.IsNull(), "Testing expired weak pointer (smart pointer constructor)");
48  MITK_TEST_CONDITION_REQUIRED(weakPointer4.IsNull(), "Testing expired weak pointer (copy constructor)")
49 
51 }
itk::SmartPointer< Self > Pointer
#define MITK_TEST_CONDITION_REQUIRED(COND, MSG)
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
int mitkWeakPointerTest(int, char *[])
Implements a weak reference to an object.
bool IsNull() const
and MITK_TEST_END()
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.