Added another test for StrongPtr.
git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@816 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
parent
5bc174ffce
commit
281d57aa5e
2 changed files with 81 additions and 0 deletions
|
@ -26,6 +26,7 @@
|
|||
using namespace std;
|
||||
using namespace Loki;
|
||||
|
||||
extern void DoWeakLeakTest( void );
|
||||
extern void DoStrongRefCountTests( void );
|
||||
extern void DoStrongRefLinkTests( void );
|
||||
extern void DoStrongReleaseTests( void );
|
||||
|
@ -1010,6 +1011,7 @@ int main( unsigned int argc, const char * argv[] )
|
|||
}
|
||||
|
||||
DoRefLinkTests();
|
||||
DoWeakLeakTest();
|
||||
DoStrongRefCountTests();
|
||||
DoStrongReleaseTests();
|
||||
DoStrongReleaseTests();
|
||||
|
|
|
@ -47,6 +47,65 @@ typedef Loki::StrongPtr< Thingy, true, TwoRefCounts, DisallowConversion,
|
|||
Thingy_DeleteNothing_ptr;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class Counted
|
||||
{
|
||||
public:
|
||||
|
||||
Counted( void ) : m_size( 0 )
|
||||
{
|
||||
s_constructions++;
|
||||
}
|
||||
|
||||
~Counted( void )
|
||||
{
|
||||
s_destructions++;
|
||||
}
|
||||
|
||||
static inline bool AllDestroyed( void )
|
||||
{
|
||||
return ( s_constructions == s_destructions );
|
||||
}
|
||||
|
||||
static inline bool ExtraConstructions( void )
|
||||
{
|
||||
return ( s_constructions > s_destructions );
|
||||
}
|
||||
|
||||
static inline bool ExtraDestructions( void )
|
||||
{
|
||||
return ( s_constructions < s_destructions );
|
||||
}
|
||||
|
||||
static inline unsigned int GetCtorCount( void )
|
||||
{
|
||||
return s_constructions;
|
||||
}
|
||||
|
||||
static inline unsigned int GetDtorCount( void )
|
||||
{
|
||||
return s_destructions;
|
||||
}
|
||||
|
||||
private:
|
||||
/// Not implemented.
|
||||
Counted( const Counted & );
|
||||
/// Not implemented.
|
||||
Counted & operator = ( const Counted & );
|
||||
|
||||
static unsigned int s_constructions;
|
||||
static unsigned int s_destructions;
|
||||
|
||||
int m_size;
|
||||
};
|
||||
|
||||
unsigned int Counted::s_constructions = 0;
|
||||
unsigned int Counted::s_destructions = 0;
|
||||
|
||||
typedef Loki::StrongPtr< Counted, false > Counted_WeakPtr;
|
||||
typedef Loki::StrongPtr< Counted, true > Counted_StrongPtr;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class Earth;
|
||||
|
@ -252,6 +311,26 @@ typedef Loki::StrongPtr< const BaseClass, false, TwoRefCounts, DisallowConversio
|
|||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void DoWeakLeakTest( void )
|
||||
{
|
||||
assert( Counted::AllDestroyed() );
|
||||
assert( Counted::GetCtorCount() == 0 );
|
||||
assert( Counted::GetDtorCount() == 0 );
|
||||
Counted_WeakPtr pWeakInt;
|
||||
{
|
||||
Counted_StrongPtr pStrongInt( new Counted );
|
||||
pWeakInt = pStrongInt;
|
||||
assert( Counted::ExtraConstructions() );
|
||||
assert( Counted::GetCtorCount() == 1 );
|
||||
assert( Counted::GetDtorCount() == 0 );
|
||||
}
|
||||
assert( Counted::AllDestroyed() );
|
||||
assert( Counted::GetCtorCount() == 1 );
|
||||
assert( Counted::GetDtorCount() == 1 );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void DoStrongRefCountTests( void )
|
||||
{
|
||||
|
||||
|
|
Loading…
Reference in a new issue