Added more tests for weak pointer.

git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@820 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
rich_sposato 2007-03-07 01:17:51 +00:00
parent 0699d642fd
commit b4f940e59b
2 changed files with 62 additions and 14 deletions

View file

@ -161,6 +161,14 @@
<File <File
RelativePath=".\LockTest.cpp" RelativePath=".\LockTest.cpp"
> >
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
Detect64BitPortabilityProblems="true"
/>
</FileConfiguration>
</File> </File>
<File <File
RelativePath=".\main.cpp" RelativePath=".\main.cpp"

View file

@ -103,8 +103,17 @@ private:
unsigned int Counted::s_constructions = 0; unsigned int Counted::s_constructions = 0;
unsigned int Counted::s_destructions = 0; unsigned int Counted::s_destructions = 0;
typedef Loki::StrongPtr< Counted, false > Counted_WeakPtr; typedef ::Loki::StrongPtr< Counted, false > Counted_WeakPtr;
typedef Loki::StrongPtr< Counted, true > Counted_StrongPtr; typedef ::Loki::StrongPtr< Counted, true > Counted_StrongPtr;
typedef ::Loki::StrongPtr< Counted, false, ::Loki::TwoRefLinks > Linked_WeakPtr;
typedef ::Loki::StrongPtr< Counted, true, ::Loki::TwoRefLinks > Linked_StrongPtr;
typedef ::Loki::StrongPtr< Counted, false, ::Loki::LockableTwoRefCounts >
Lockable_WeakPtr;
typedef ::Loki::StrongPtr< Counted, true, ::Loki::LockableTwoRefCounts >
Lockable_StrongPtr;
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@ -313,20 +322,51 @@ typedef Loki::StrongPtr< const BaseClass, false, TwoRefCounts, DisallowConversio
void DoWeakLeakTest( void ) void DoWeakLeakTest( void )
{ {
const unsigned int ctorCount = Counted::GetCtorCount();
const unsigned int dtorCount = Counted::GetDtorCount();
assert( Counted::AllDestroyed() ); assert( Counted::AllDestroyed() );
assert( Counted::GetCtorCount() == 0 );
assert( Counted::GetDtorCount() == 0 ); {
Counted_WeakPtr pWeakInt; Counted_WeakPtr pWeakInt;
{ {
Counted_StrongPtr pStrongInt( new Counted ); Counted_StrongPtr pStrongInt( new Counted );
pWeakInt = pStrongInt; pWeakInt = pStrongInt;
assert( Counted::ExtraConstructions() ); assert( Counted::ExtraConstructions() );
assert( Counted::GetCtorCount() == 1 ); assert( Counted::GetCtorCount() == ctorCount + 1 );
assert( Counted::GetDtorCount() == 0 ); assert( Counted::GetDtorCount() == dtorCount );
} }
assert( Counted::AllDestroyed() ); assert( Counted::AllDestroyed() );
assert( Counted::GetCtorCount() == 1 ); assert( Counted::GetCtorCount() == ctorCount + 1 );
assert( Counted::GetDtorCount() == 1 ); assert( Counted::GetDtorCount() == dtorCount + 1 );
}
{
Lockable_WeakPtr pWeakInt;
{
Lockable_StrongPtr pStrongInt( new Counted );
pWeakInt = pStrongInt;
assert( Counted::ExtraConstructions() );
assert( Counted::GetCtorCount() == ctorCount + 2 );
assert( Counted::GetDtorCount() == dtorCount + 1 );
}
assert( Counted::AllDestroyed() );
assert( Counted::GetCtorCount() == ctorCount + 2 );
assert( Counted::GetDtorCount() == dtorCount + 2 );
}
{
Linked_WeakPtr pWeakInt;
{
Linked_StrongPtr pStrongInt( new Counted );
pWeakInt = pStrongInt;
assert( Counted::ExtraConstructions() );
assert( Counted::GetCtorCount() == ctorCount + 3 );
assert( Counted::GetDtorCount() == dtorCount + 2 );
}
assert( Counted::AllDestroyed() );
assert( Counted::GetCtorCount() == ctorCount + 3 );
assert( Counted::GetDtorCount() == dtorCount + 3 );
}
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------