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:
parent
0699d642fd
commit
b4f940e59b
2 changed files with 62 additions and 14 deletions
|
@ -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"
|
||||||
|
|
|
@ -101,10 +101,19 @@ 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, 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;
|
||||||
|
|
||||||
typedef Loki::StrongPtr< Counted, false > Counted_WeakPtr;
|
|
||||||
typedef Loki::StrongPtr< Counted, true > Counted_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_StrongPtr pStrongInt( new Counted );
|
Counted_WeakPtr pWeakInt;
|
||||||
pWeakInt = pStrongInt;
|
{
|
||||||
assert( Counted::ExtraConstructions() );
|
Counted_StrongPtr pStrongInt( new Counted );
|
||||||
assert( Counted::GetCtorCount() == 1 );
|
pWeakInt = pStrongInt;
|
||||||
assert( Counted::GetDtorCount() == 0 );
|
assert( Counted::ExtraConstructions() );
|
||||||
|
assert( Counted::GetCtorCount() == ctorCount + 1 );
|
||||||
|
assert( Counted::GetDtorCount() == dtorCount );
|
||||||
|
}
|
||||||
|
assert( Counted::AllDestroyed() );
|
||||||
|
assert( Counted::GetCtorCount() == ctorCount + 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 );
|
||||||
}
|
}
|
||||||
assert( Counted::AllDestroyed() );
|
|
||||||
assert( Counted::GetCtorCount() == 1 );
|
|
||||||
assert( Counted::GetDtorCount() == 1 );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in a new issue