Ptr_UnitTests.cpp

Go to the documentation of this file.
00001 #include "Teuchos_UnitTestHarness.hpp"
00002 #include "Teuchos_Ptr.hpp"
00003 #include "Teuchos_getConst.hpp"
00004 #include "TestClasses.hpp"
00005 
00006 
00007 namespace {
00008 
00009 
00010 using Teuchos::null;
00011 using Teuchos::Ptr;
00012 using Teuchos::RCP;
00013 using Teuchos::rcp;
00014 using Teuchos::ptrFromRef;
00015 using Teuchos::rcpFromPtr;
00016 using Teuchos::NullReferenceError;
00017 using Teuchos::DanglingReferenceError;
00018 using Teuchos::RCP_STRONG;
00019 using Teuchos::RCP_WEAK;
00020 using Teuchos::RCP_STRENGTH_INVALID;
00021 
00022 
00023 TEUCHOS_UNIT_TEST( Ptr, nonnull )
00024 {
00025   ECHO(A a);
00026   ECHO(Ptr<A> a_ptr = ptrFromRef(a));
00027   TEST_EQUALITY_CONST(is_null(a_ptr), false);
00028   TEST_EQUALITY_CONST(nonnull(a_ptr), true);
00029   ECHO(a_ptr = null);
00030   TEST_EQUALITY_CONST(is_null(a_ptr), true);
00031   TEST_EQUALITY_CONST(nonnull(a_ptr), false);
00032 }
00033 
00034 
00035 TEUCHOS_UNIT_TEST( Ptr, rcpFromPtr_weakRef )
00036 {
00037   ECHO(RCP<A> a_rcp = rcp(new A));
00038   ECHO(Ptr<A> a_ptr = a_rcp.ptr());
00039   ECHO(RCP<A> a_rcp2 = rcpFromPtr(a_ptr));
00040   TEST_EQUALITY(a_rcp2.getRawPtr(), a_rcp.getRawPtr());
00041 #ifdef TEUCHOS_DEBUG
00042   TEST_ASSERT(a_rcp2.shares_resource(a_rcp));
00043 #else
00044   // In an optimized build, the object a_rcp2 has its own RCPNode object that
00045   // is unrelated to the orgininal a_rcp object.  This cuts down on overhead.
00046 #endif
00047   ECHO(a_rcp = null);
00048 #ifdef TEUCHOS_DEBUG
00049   TEST_THROW(a_ptr.getRawPtr(), DanglingReferenceError);
00050   TEST_THROW(a_rcp2.getRawPtr(), DanglingReferenceError);
00051 #endif
00052   
00053 }
00054 
00055 
00056 TEUCHOS_UNIT_TEST( Ptr, rcpFromPtr_rawRef )
00057 {
00058   ECHO(A a);
00059   ECHO(Ptr<A> a_ptr = ptrFromRef(a));
00060   ECHO(RCP<A> a_rcp2 = rcpFromPtr(a_ptr));
00061   TEST_EQUALITY(a_rcp2.getRawPtr(), &a);
00062 }
00063 
00064 
00065 TEUCHOS_UNIT_TEST( Ptr, rcpFromPtr_null )
00066 {
00067   ECHO(Ptr<A> a_ptr);
00068   ECHO(RCP<A> a_rcp2 = rcpFromPtr(a_ptr));
00069   TEST_EQUALITY(a_rcp2, null);
00070 }
00071 
00072 
00073 } // namespace
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on Tue Oct 20 10:13:59 2009 for Teuchos Package Browser (Single Doxygen Collection) by  doxygen 1.6.1