00001 /*========================================================================= 00002 00003 Program: BlueBerry Platform 00004 Language: C++ 00005 Date: $Date$ 00006 Version: $Revision$ 00007 00008 Copyright (c) German Cancer Research Center, Division of Medical and 00009 Biological Informatics. All rights reserved. 00010 See MITKCopyright.txt or https://www.mitk.org/copyright.html for details. 00011 00012 This software is distributed WITHOUT ANY WARRANTY; without even 00013 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00014 PURPOSE. See the above copyright notices for more information. 00015 00016 =========================================================================*/ 00017 00018 #include "mitkTestingMacros.h" 00019 00020 #include <mitkWeakPointer.h> 00021 #include <itkObject.h> 00022 00023 int mitkWeakPointerTest(int /*argc*/, char* /*argv*/[]) 00024 { 00025 00026 MITK_TEST_BEGIN("WeakPointer") 00027 00028 mitk::WeakPointer<itk::Object> weakPointer; 00029 mitk::WeakPointer<itk::Object> weakPointer2; 00030 00031 // Testing constructors and reference counting 00032 itk::Object::Pointer smartPointer = itk::Object::New(); 00033 mitk::WeakPointer<itk::Object> weakPointer3(smartPointer); 00034 mitk::WeakPointer<itk::Object> weakPointer4(weakPointer); 00035 { 00036 itk::Object::Pointer tmpSmartPointer(weakPointer); 00037 itk::Object::Pointer tmpSmartPointer2(weakPointer2); 00038 MITK_TEST_CONDITION_REQUIRED(tmpSmartPointer.GetPointer() == tmpSmartPointer2.GetPointer(), "Testing equal pointers"); 00039 } 00040 00041 weakPointer = smartPointer; 00042 weakPointer2 = weakPointer; 00043 00044 MITK_TEST_CONDITION_REQUIRED(1 == smartPointer->GetReferenceCount(), "Testing reference count"); 00045 smartPointer = 0; 00046 MITK_TEST_CONDITION_REQUIRED(weakPointer.IsNull(), "Testing expired weak pointer (smart pointer assignment)"); 00047 MITK_TEST_CONDITION_REQUIRED(weakPointer2.IsNull(), "Testing expired weak pointer (weak pointer assignment)"); 00048 MITK_TEST_CONDITION_REQUIRED(weakPointer3.IsNull(), "Testing expired weak pointer (smart pointer constructor)"); 00049 MITK_TEST_CONDITION_REQUIRED(weakPointer4.IsNull(), "Testing expired weak pointer (copy constructor)") 00050 00051 MITK_TEST_END() 00052 }