2019-01-02 15:50:21 +01:00
|
|
|
#include <ebcl/RefCount.hh>
|
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
using namespace ebcl;
|
|
|
|
|
2019-01-02 16:52:38 +01:00
|
|
|
template< bool Atomic >
|
2019-01-02 15:50:21 +01:00
|
|
|
class RefCountTest : public CppUnit::TestFixture
|
|
|
|
{
|
2019-01-02 16:52:38 +01:00
|
|
|
public:
|
|
|
|
class T_Test : public T_ReferenceCountedClass< Atomic > \
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static uint32_t cNew;
|
|
|
|
static uint32_t cDel;
|
|
|
|
T_Test( ) noexcept { cNew ++; }
|
2019-01-02 17:14:08 +01:00
|
|
|
virtual ~T_Test( ) noexcept { cDel ++; }
|
2019-01-02 16:52:38 +01:00
|
|
|
};
|
|
|
|
using P_Test = T_RcPtr< T_Test >;
|
|
|
|
|
2019-01-02 17:14:08 +01:00
|
|
|
class T_Child : public T_Test { };
|
|
|
|
using P_Child = T_RcPtr< T_Child >;
|
|
|
|
|
2019-01-02 16:52:38 +01:00
|
|
|
private:
|
2019-01-02 15:50:21 +01:00
|
|
|
CPPUNIT_TEST_SUITE( RefCountTest );
|
|
|
|
CPPUNIT_TEST( testStackInstance );
|
|
|
|
|
|
|
|
CPPUNIT_TEST( testEmpty );
|
|
|
|
CPPUNIT_TEST( testConstruct );
|
|
|
|
|
|
|
|
CPPUNIT_TEST( testCopyCons );
|
2019-01-02 17:14:08 +01:00
|
|
|
CPPUNIT_TEST( testCopyConsToBase );
|
|
|
|
CPPUNIT_TEST( testCopyConsToChildOk );
|
|
|
|
CPPUNIT_TEST( testCopyConsToChildBad );
|
|
|
|
|
2019-01-02 15:50:21 +01:00
|
|
|
CPPUNIT_TEST( testCopyAss );
|
2019-01-02 17:14:08 +01:00
|
|
|
CPPUNIT_TEST( testCopyAssToBase );
|
|
|
|
CPPUNIT_TEST( testCopyAssToChildOk );
|
|
|
|
CPPUNIT_TEST( testCopyAssToChildBad );
|
|
|
|
|
2019-01-02 15:50:21 +01:00
|
|
|
CPPUNIT_TEST( testMoveCons );
|
2019-01-02 17:14:08 +01:00
|
|
|
CPPUNIT_TEST( testMoveConsToBase );
|
|
|
|
CPPUNIT_TEST( testMoveConsToChildOk );
|
|
|
|
CPPUNIT_TEST( testMoveConsToChildBad );
|
|
|
|
|
2019-01-02 15:50:21 +01:00
|
|
|
CPPUNIT_TEST( testMoveAss );
|
2019-01-02 17:14:08 +01:00
|
|
|
CPPUNIT_TEST( testMoveAssToBase );
|
|
|
|
CPPUNIT_TEST( testMoveAssToChildOk );
|
|
|
|
CPPUNIT_TEST( testMoveAssToChildBad );
|
2019-01-02 16:52:38 +01:00
|
|
|
|
|
|
|
CPPUNIT_TEST( testSwap );
|
2019-01-02 17:52:56 +01:00
|
|
|
|
|
|
|
CPPUNIT_TEST( testEq );
|
|
|
|
CPPUNIT_TEST( testEqChild );
|
|
|
|
|
|
|
|
CPPUNIT_TEST( testNEq );
|
|
|
|
CPPUNIT_TEST( testNEqChild );
|
2019-01-02 15:50:21 +01:00
|
|
|
CPPUNIT_TEST_SUITE_END( );
|
|
|
|
|
|
|
|
public:
|
|
|
|
void setUp( ) override;
|
|
|
|
|
|
|
|
void testStackInstance( );
|
|
|
|
|
|
|
|
void testEmpty( );
|
|
|
|
void testConstruct( );
|
|
|
|
|
|
|
|
void testCopyCons( );
|
2019-01-02 17:14:08 +01:00
|
|
|
void testCopyConsToBase( );
|
|
|
|
void testCopyConsToChildOk( );
|
|
|
|
void testCopyConsToChildBad( );
|
|
|
|
|
2019-01-02 15:50:21 +01:00
|
|
|
void testCopyAss( );
|
2019-01-02 17:14:08 +01:00
|
|
|
void testCopyAssToBase( );
|
|
|
|
void testCopyAssToChildOk( );
|
|
|
|
void testCopyAssToChildBad( );
|
|
|
|
|
2019-01-02 15:50:21 +01:00
|
|
|
void testMoveCons( );
|
2019-01-02 17:14:08 +01:00
|
|
|
void testMoveConsToBase( );
|
|
|
|
void testMoveConsToChildOk( );
|
|
|
|
void testMoveConsToChildBad( );
|
|
|
|
|
2019-01-02 15:50:21 +01:00
|
|
|
void testMoveAss( );
|
2019-01-02 17:14:08 +01:00
|
|
|
void testMoveAssToBase( );
|
|
|
|
void testMoveAssToChildOk( );
|
|
|
|
void testMoveAssToChildBad( );
|
2019-01-02 15:50:21 +01:00
|
|
|
|
2019-01-02 16:52:38 +01:00
|
|
|
void testSwap( );
|
2019-01-02 17:52:56 +01:00
|
|
|
|
|
|
|
void testEq( );
|
|
|
|
void testEqChild( );
|
|
|
|
|
|
|
|
void testNEq( );
|
|
|
|
void testNEqChild( );
|
2019-01-02 16:52:38 +01:00
|
|
|
};
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( RefCountTest< true > );
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( RefCountTest< false > );
|
2019-01-02 15:50:21 +01:00
|
|
|
|
2019-01-02 16:52:38 +01:00
|
|
|
template<> uint32_t RefCountTest< true >::T_Test::cNew = 0;
|
|
|
|
template<> uint32_t RefCountTest< true >::T_Test::cDel = 0;
|
|
|
|
template<> uint32_t RefCountTest< false >::T_Test::cNew = 0;
|
|
|
|
template<> uint32_t RefCountTest< false >::T_Test::cDel = 0;
|
2019-01-02 15:50:21 +01:00
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
2019-01-02 16:52:38 +01:00
|
|
|
template< bool A >
|
|
|
|
void RefCountTest< A >::setUp( )
|
2019-01-02 15:50:21 +01:00
|
|
|
{
|
2019-01-02 16:52:38 +01:00
|
|
|
T_Test::cNew = T_Test::cDel = 0;
|
2019-01-02 15:50:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
2019-01-02 16:52:38 +01:00
|
|
|
template< bool A >
|
|
|
|
void RefCountTest< A >::testStackInstance( )
|
2019-01-02 15:50:21 +01:00
|
|
|
{
|
|
|
|
{
|
2019-01-02 16:52:38 +01:00
|
|
|
T_Test t;
|
|
|
|
CPPUNIT_ASSERT_EQUAL( 1u , T_Test::cNew );
|
|
|
|
CPPUNIT_ASSERT_EQUAL( 0u , t.getReferenceCount( ) );
|
2019-01-02 15:50:21 +01:00
|
|
|
}
|
2019-01-02 16:52:38 +01:00
|
|
|
CPPUNIT_ASSERT_EQUAL( 1u , T_Test::cDel );
|
2019-01-02 15:50:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
2019-01-02 16:52:38 +01:00
|
|
|
template< bool A >
|
|
|
|
void RefCountTest< A >::testEmpty( )
|
2019-01-02 15:50:21 +01:00
|
|
|
{
|
|
|
|
{
|
2019-01-02 16:52:38 +01:00
|
|
|
P_Test p1;
|
|
|
|
CPPUNIT_ASSERT_EQUAL( 0u , T_Test::cNew );
|
2019-01-02 15:50:21 +01:00
|
|
|
CPPUNIT_ASSERT_EQUAL( false , bool{ p1 } );
|
|
|
|
CPPUNIT_ASSERT_EQUAL( true , !p1 );
|
2019-01-02 16:52:38 +01:00
|
|
|
CPPUNIT_ASSERT_EQUAL( (T_Test*) nullptr , p1.get( ) );
|
|
|
|
CPPUNIT_ASSERT_EQUAL( (T_Test*) nullptr , (T_Test*) p1 );
|
2019-01-02 15:50:21 +01:00
|
|
|
}
|
2019-01-02 16:52:38 +01:00
|
|
|
CPPUNIT_ASSERT_EQUAL( 0u , T_Test::cDel );
|
2019-01-02 15:50:21 +01:00
|
|
|
}
|
|
|
|
|
2019-01-02 16:52:38 +01:00
|
|
|
template< bool A >
|
|
|
|
void RefCountTest< A >::testConstruct( )
|
2019-01-02 15:50:21 +01:00
|
|
|
{
|
|
|
|
{
|
2019-01-02 16:52:38 +01:00
|
|
|
P_Test p1{ P_Test::New( ) };
|
|
|
|
CPPUNIT_ASSERT_EQUAL( 1u , T_Test::cNew );
|
2019-01-02 15:50:21 +01:00
|
|
|
CPPUNIT_ASSERT_EQUAL( true , bool{ p1 } );
|
|
|
|
CPPUNIT_ASSERT_EQUAL( false , !p1 );
|
2019-01-02 16:52:38 +01:00
|
|
|
CPPUNIT_ASSERT( (T_Test*) nullptr != p1.get( ) );
|
|
|
|
CPPUNIT_ASSERT( (T_Test*) nullptr != (T_Test*) p1 );
|
2019-01-02 15:50:21 +01:00
|
|
|
CPPUNIT_ASSERT_EQUAL( 1u , p1->getReferenceCount( ) );
|
|
|
|
CPPUNIT_ASSERT_EQUAL( 1u , (*p1).getReferenceCount( ) );
|
|
|
|
}
|
2019-01-02 16:52:38 +01:00
|
|
|
CPPUNIT_ASSERT_EQUAL( 1u , T_Test::cDel );
|
2019-01-02 15:50:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
2019-01-02 16:52:38 +01:00
|
|
|
template< bool A >
|
|
|
|
void RefCountTest< A >::testCopyCons( )
|
2019-01-02 15:50:21 +01:00
|
|
|
{
|
|
|
|
{
|
2019-01-02 16:52:38 +01:00
|
|
|
P_Test p1{ P_Test::New( ) };
|
2019-01-02 15:50:21 +01:00
|
|
|
{
|
2019-01-02 16:52:38 +01:00
|
|
|
P_Test c1{ p1 };
|
|
|
|
CPPUNIT_ASSERT_EQUAL( 1u , T_Test::cNew );
|
2019-01-02 15:50:21 +01:00
|
|
|
CPPUNIT_ASSERT( c1 );
|
|
|
|
CPPUNIT_ASSERT( p1.get( ) == c1.get( ) );
|
|
|
|
CPPUNIT_ASSERT_EQUAL( 2u , p1->getReferenceCount( ) );
|
|
|
|
}
|
2019-01-02 16:52:38 +01:00
|
|
|
CPPUNIT_ASSERT_EQUAL( 0u , T_Test::cDel );
|
2019-01-02 15:50:21 +01:00
|
|
|
CPPUNIT_ASSERT_EQUAL( 1u , p1->getReferenceCount( ) );
|
|
|
|
}
|
2019-01-02 16:52:38 +01:00
|
|
|
CPPUNIT_ASSERT_EQUAL( 1u , T_Test::cDel );
|
2019-01-02 15:50:21 +01:00
|
|
|
}
|
|
|
|
|
2019-01-02 17:14:08 +01:00
|
|
|
template< bool A >
|
|
|
|
void RefCountTest< A >::testCopyConsToBase( )
|
|
|
|
{
|
|
|
|
P_Child p1{ P_Child::New( ) };
|
|
|
|
P_Test p2{ p1 };
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT( bool( p2 ) );
|
|
|
|
CPPUNIT_ASSERT( p1.get( ) == p2.get( ) );
|
|
|
|
CPPUNIT_ASSERT_EQUAL( 2u , p1->getReferenceCount( ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
template< bool A >
|
|
|
|
void RefCountTest< A >::testCopyConsToChildOk( )
|
|
|
|
{
|
|
|
|
P_Test p1{ P_Test::FromRaw( new T_Child( ) ) };
|
|
|
|
P_Child p2{ p1 };
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT( bool( p2 ) );
|
|
|
|
CPPUNIT_ASSERT( p1.get( ) == p2.get( ) );
|
|
|
|
CPPUNIT_ASSERT_EQUAL( 2u , p1->getReferenceCount( ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
template< bool A >
|
|
|
|
void RefCountTest< A >::testCopyConsToChildBad( )
|
|
|
|
{
|
|
|
|
P_Test p1{ P_Test::New( ) };
|
|
|
|
CPPUNIT_ASSERT_THROW( P_Child p2{ p1 } , std::bad_cast );
|
|
|
|
CPPUNIT_ASSERT_EQUAL( 1u , p1->getReferenceCount( ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
2019-01-02 16:52:38 +01:00
|
|
|
template< bool A >
|
|
|
|
void RefCountTest< A >::testCopyAss( )
|
2019-01-02 15:50:21 +01:00
|
|
|
{
|
|
|
|
{
|
2019-01-02 16:52:38 +01:00
|
|
|
P_Test p1{ P_Test::New( ) };
|
2019-01-02 15:50:21 +01:00
|
|
|
{
|
2019-01-02 16:52:38 +01:00
|
|
|
P_Test c1;
|
2019-01-02 15:50:21 +01:00
|
|
|
CPPUNIT_ASSERT( !c1 );
|
|
|
|
c1 = p1;
|
2019-01-02 16:52:38 +01:00
|
|
|
CPPUNIT_ASSERT_EQUAL( 1u , T_Test::cNew );
|
2019-01-02 15:50:21 +01:00
|
|
|
CPPUNIT_ASSERT( c1 );
|
|
|
|
CPPUNIT_ASSERT( p1.get( ) == c1.get( ) );
|
|
|
|
CPPUNIT_ASSERT_EQUAL( 2u , p1->getReferenceCount( ) );
|
|
|
|
}
|
2019-01-02 16:52:38 +01:00
|
|
|
CPPUNIT_ASSERT_EQUAL( 0u , T_Test::cDel );
|
2019-01-02 15:50:21 +01:00
|
|
|
CPPUNIT_ASSERT_EQUAL( 1u , p1->getReferenceCount( ) );
|
|
|
|
}
|
2019-01-02 16:52:38 +01:00
|
|
|
CPPUNIT_ASSERT_EQUAL( 1u , T_Test::cDel );
|
2019-01-02 15:50:21 +01:00
|
|
|
}
|
|
|
|
|
2019-01-02 17:14:08 +01:00
|
|
|
template< bool A >
|
|
|
|
void RefCountTest< A >::testCopyAssToBase( )
|
|
|
|
{
|
|
|
|
P_Child p1{ P_Child::New( ) };
|
|
|
|
P_Test p2;
|
|
|
|
p2 = p1;
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT( bool( p2 ) );
|
|
|
|
CPPUNIT_ASSERT( p1.get( ) == p2.get( ) );
|
|
|
|
CPPUNIT_ASSERT_EQUAL( 2u , p1->getReferenceCount( ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
template< bool A >
|
|
|
|
void RefCountTest< A >::testCopyAssToChildOk( )
|
|
|
|
{
|
|
|
|
P_Test p1{ P_Test::FromRaw( new T_Child( ) ) };
|
|
|
|
P_Child p2;
|
|
|
|
p2 = p1;
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT( bool( p2 ) );
|
|
|
|
CPPUNIT_ASSERT( p1.get( ) == p2.get( ) );
|
|
|
|
CPPUNIT_ASSERT_EQUAL( 2u , p1->getReferenceCount( ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
template< bool A >
|
|
|
|
void RefCountTest< A >::testCopyAssToChildBad( )
|
|
|
|
{
|
|
|
|
P_Test p1{ P_Test::New( ) };
|
|
|
|
P_Child p2;
|
|
|
|
CPPUNIT_ASSERT_THROW( p2 = p1 , std::bad_cast );
|
|
|
|
CPPUNIT_ASSERT_EQUAL( 1u , p1->getReferenceCount( ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
2019-01-02 16:52:38 +01:00
|
|
|
template< bool A >
|
|
|
|
void RefCountTest< A >::testMoveCons( )
|
2019-01-02 15:50:21 +01:00
|
|
|
{
|
2019-01-02 16:52:38 +01:00
|
|
|
P_Test p1{ P_Test::New( ) };
|
2019-01-02 15:50:21 +01:00
|
|
|
{
|
2019-01-02 16:52:38 +01:00
|
|
|
P_Test c1{ std::move( p1 ) };
|
|
|
|
CPPUNIT_ASSERT_EQUAL( 1u , T_Test::cNew );
|
|
|
|
CPPUNIT_ASSERT_EQUAL( 0u , T_Test::cDel );
|
2019-01-02 15:50:21 +01:00
|
|
|
CPPUNIT_ASSERT( c1 );
|
|
|
|
CPPUNIT_ASSERT( !p1 );
|
|
|
|
CPPUNIT_ASSERT_EQUAL( 1u , c1->getReferenceCount( ) );
|
|
|
|
}
|
2019-01-02 16:52:38 +01:00
|
|
|
CPPUNIT_ASSERT_EQUAL( 1u , T_Test::cDel );
|
2019-01-02 15:50:21 +01:00
|
|
|
}
|
|
|
|
|
2019-01-02 17:14:08 +01:00
|
|
|
template< bool A >
|
|
|
|
void RefCountTest< A >::testMoveConsToBase( )
|
|
|
|
{
|
|
|
|
P_Child p1{ P_Child::New( ) };
|
|
|
|
P_Test p2{ std::move( p1 ) };
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT( bool( p2 ) );
|
|
|
|
CPPUNIT_ASSERT( !p1 );
|
|
|
|
CPPUNIT_ASSERT_EQUAL( 1u , p2->getReferenceCount( ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
template< bool A >
|
|
|
|
void RefCountTest< A >::testMoveConsToChildOk( )
|
|
|
|
{
|
|
|
|
P_Test p1{ P_Test::FromRaw( new T_Child( ) ) };
|
|
|
|
P_Child p2{ std::move( p1 ) };
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT( bool( p2 ) );
|
|
|
|
CPPUNIT_ASSERT( !p1 );
|
|
|
|
CPPUNIT_ASSERT_EQUAL( 1u , p2->getReferenceCount( ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
template< bool A >
|
|
|
|
void RefCountTest< A >::testMoveConsToChildBad( )
|
|
|
|
{
|
|
|
|
P_Test p1{ P_Test::New( ) };
|
|
|
|
CPPUNIT_ASSERT_THROW( P_Child p2{ std::move( p1 ) } , std::bad_cast );
|
|
|
|
CPPUNIT_ASSERT( p1 );
|
|
|
|
CPPUNIT_ASSERT_EQUAL( 1u , p1->getReferenceCount( ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
2019-01-02 16:52:38 +01:00
|
|
|
template< bool A >
|
|
|
|
void RefCountTest< A >::testMoveAss( )
|
2019-01-02 15:50:21 +01:00
|
|
|
{
|
2019-01-02 16:52:38 +01:00
|
|
|
P_Test p1{ P_Test::New( ) };
|
2019-01-02 15:50:21 +01:00
|
|
|
{
|
2019-01-02 16:52:38 +01:00
|
|
|
P_Test c1;
|
2019-01-02 15:50:21 +01:00
|
|
|
CPPUNIT_ASSERT( !c1 );
|
|
|
|
c1 = std::move( p1 );
|
2019-01-02 16:52:38 +01:00
|
|
|
CPPUNIT_ASSERT_EQUAL( 1u , T_Test::cNew );
|
|
|
|
CPPUNIT_ASSERT_EQUAL( 0u , T_Test::cDel );
|
2019-01-02 15:50:21 +01:00
|
|
|
CPPUNIT_ASSERT( c1 );
|
|
|
|
CPPUNIT_ASSERT( !p1 );
|
|
|
|
CPPUNIT_ASSERT_EQUAL( 1u , c1->getReferenceCount( ) );
|
|
|
|
}
|
2019-01-02 16:52:38 +01:00
|
|
|
CPPUNIT_ASSERT_EQUAL( 1u , T_Test::cDel );
|
|
|
|
}
|
|
|
|
|
2019-01-02 17:14:08 +01:00
|
|
|
template< bool A >
|
|
|
|
void RefCountTest< A >::testMoveAssToBase( )
|
|
|
|
{
|
|
|
|
P_Child p1{ P_Child::New( ) };
|
|
|
|
P_Test p2;
|
|
|
|
p2 = std::move( p1 );
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT( p2 );
|
|
|
|
CPPUNIT_ASSERT( !p1 );
|
|
|
|
CPPUNIT_ASSERT_EQUAL( 1u , p2->getReferenceCount( ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
template< bool A >
|
|
|
|
void RefCountTest< A >::testMoveAssToChildOk( )
|
|
|
|
{
|
|
|
|
P_Test p1{ P_Test::FromRaw( new T_Child( ) ) };
|
|
|
|
P_Child p2;
|
|
|
|
p2 = std::move( p1 );
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT( p2 );
|
|
|
|
CPPUNIT_ASSERT( !p1 );
|
|
|
|
CPPUNIT_ASSERT_EQUAL( 1u , p2->getReferenceCount( ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
template< bool A >
|
|
|
|
void RefCountTest< A >::testMoveAssToChildBad( )
|
|
|
|
{
|
|
|
|
P_Test p1{ P_Test::New( ) };
|
|
|
|
P_Child p2;
|
|
|
|
CPPUNIT_ASSERT_THROW( p2 = std::move( p1 ) , std::bad_cast );
|
|
|
|
CPPUNIT_ASSERT( p1 );
|
|
|
|
CPPUNIT_ASSERT_EQUAL( 1u , p1->getReferenceCount( ) );
|
|
|
|
}
|
|
|
|
|
2019-01-02 16:52:38 +01:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
template< bool A >
|
|
|
|
void RefCountTest< A >::testSwap( )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
P_Test p1{ P_Test::New( ) };
|
|
|
|
P_Test p2{ };
|
|
|
|
CPPUNIT_ASSERT_EQUAL( 1u , T_Test::cNew );
|
|
|
|
CPPUNIT_ASSERT_EQUAL( 0u , T_Test::cDel );
|
|
|
|
CPPUNIT_ASSERT( p1 );
|
|
|
|
CPPUNIT_ASSERT( !p2 );
|
|
|
|
CPPUNIT_ASSERT_EQUAL( 1u , p1->getReferenceCount( ) );
|
|
|
|
|
|
|
|
p1.swap( p2 );
|
|
|
|
CPPUNIT_ASSERT( !p1 );
|
|
|
|
CPPUNIT_ASSERT( p2 );
|
|
|
|
CPPUNIT_ASSERT_EQUAL( 1u , p2->getReferenceCount( ) );
|
|
|
|
|
|
|
|
p1.swap( p2 );
|
|
|
|
CPPUNIT_ASSERT( p1 );
|
|
|
|
CPPUNIT_ASSERT( !p2 );
|
|
|
|
CPPUNIT_ASSERT_EQUAL( 1u , p1->getReferenceCount( ) );
|
|
|
|
}
|
|
|
|
CPPUNIT_ASSERT_EQUAL( 1u , T_Test::cDel );
|
2019-01-02 15:50:21 +01:00
|
|
|
}
|
2019-01-02 17:52:56 +01:00
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
template< bool A >
|
|
|
|
void RefCountTest< A >::testEq( )
|
|
|
|
{
|
|
|
|
P_Test p1{ P_Test::New( ) },
|
|
|
|
p2{ p1 } ,
|
|
|
|
p3{ P_Test::New( ) },
|
|
|
|
p4;
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT( ( p1 == p1 ) );
|
|
|
|
CPPUNIT_ASSERT( ( p1 == p2 ) );
|
|
|
|
CPPUNIT_ASSERT( !( p1 == p3 ) );
|
|
|
|
CPPUNIT_ASSERT( !( p1 == p4 ) );
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT( ( p2 == p1 ) );
|
|
|
|
CPPUNIT_ASSERT( ( p2 == p2 ) );
|
|
|
|
CPPUNIT_ASSERT( !( p2 == p3 ) );
|
|
|
|
CPPUNIT_ASSERT( !( p2 == p4 ) );
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT( !( p3 == p1 ) );
|
|
|
|
CPPUNIT_ASSERT( !( p3 == p2 ) );
|
|
|
|
CPPUNIT_ASSERT( ( p3 == p3 ) );
|
|
|
|
CPPUNIT_ASSERT( !( p3 == p4 ) );
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT( !( p4 == p1 ) );
|
|
|
|
CPPUNIT_ASSERT( !( p4 == p2 ) );
|
|
|
|
CPPUNIT_ASSERT( !( p4 == p3 ) );
|
|
|
|
CPPUNIT_ASSERT( ( p4 == p4 ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
template< bool A >
|
|
|
|
void RefCountTest< A >::testEqChild( )
|
|
|
|
{
|
|
|
|
P_Child p1{ P_Child::New( ) } ,
|
|
|
|
p2{ P_Child::New( ) };
|
|
|
|
P_Test p3{ p1 } , p4{ p2 };
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT( ( p1 == p1 ) );
|
|
|
|
CPPUNIT_ASSERT( !( p1 == p2 ) );
|
|
|
|
CPPUNIT_ASSERT( ( p1 == p3 ) );
|
|
|
|
CPPUNIT_ASSERT( !( p1 == p4 ) );
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT( !( p2 == p1 ) );
|
|
|
|
CPPUNIT_ASSERT( ( p2 == p2 ) );
|
|
|
|
CPPUNIT_ASSERT( !( p2 == p3 ) );
|
|
|
|
CPPUNIT_ASSERT( ( p2 == p4 ) );
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT( ( p3 == p1 ) );
|
|
|
|
CPPUNIT_ASSERT( !( p3 == p2 ) );
|
|
|
|
CPPUNIT_ASSERT( ( p3 == p3 ) );
|
|
|
|
CPPUNIT_ASSERT( !( p3 == p4 ) );
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT( !( p4 == p1 ) );
|
|
|
|
CPPUNIT_ASSERT( ( p4 == p2 ) );
|
|
|
|
CPPUNIT_ASSERT( !( p4 == p3 ) );
|
|
|
|
CPPUNIT_ASSERT( ( p4 == p4 ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
template< bool A >
|
|
|
|
void RefCountTest< A >::testNEq( )
|
|
|
|
{
|
|
|
|
P_Test p1{ P_Test::New( ) },
|
|
|
|
p2{ p1 } ,
|
|
|
|
p3{ P_Test::New( ) },
|
|
|
|
p4;
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT( !( p1 != p1 ) );
|
|
|
|
CPPUNIT_ASSERT( !( p1 != p2 ) );
|
|
|
|
CPPUNIT_ASSERT( ( p1 != p3 ) );
|
|
|
|
CPPUNIT_ASSERT( ( p1 != p4 ) );
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT( !( p2 != p1 ) );
|
|
|
|
CPPUNIT_ASSERT( !( p2 != p2 ) );
|
|
|
|
CPPUNIT_ASSERT( ( p2 != p3 ) );
|
|
|
|
CPPUNIT_ASSERT( ( p2 != p4 ) );
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT( ( p3 != p1 ) );
|
|
|
|
CPPUNIT_ASSERT( ( p3 != p2 ) );
|
|
|
|
CPPUNIT_ASSERT( !( p3 != p3 ) );
|
|
|
|
CPPUNIT_ASSERT( ( p3 != p4 ) );
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT( ( p4 != p1 ) );
|
|
|
|
CPPUNIT_ASSERT( ( p4 != p2 ) );
|
|
|
|
CPPUNIT_ASSERT( ( p4 != p3 ) );
|
|
|
|
CPPUNIT_ASSERT( !( p4 != p4 ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
template< bool A >
|
|
|
|
void RefCountTest< A >::testNEqChild( )
|
|
|
|
{
|
|
|
|
P_Child p1{ P_Child::New( ) } ,
|
|
|
|
p2{ P_Child::New( ) };
|
|
|
|
P_Test p3{ p1 } , p4{ p2 };
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT( !( p1 != p1 ) );
|
|
|
|
CPPUNIT_ASSERT( ( p1 != p2 ) );
|
|
|
|
CPPUNIT_ASSERT( !( p1 != p3 ) );
|
|
|
|
CPPUNIT_ASSERT( ( p1 != p4 ) );
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT( ( p2 != p1 ) );
|
|
|
|
CPPUNIT_ASSERT( !( p2 != p2 ) );
|
|
|
|
CPPUNIT_ASSERT( ( p2 != p3 ) );
|
|
|
|
CPPUNIT_ASSERT( !( p2 != p4 ) );
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT( !( p3 != p1 ) );
|
|
|
|
CPPUNIT_ASSERT( ( p3 != p2 ) );
|
|
|
|
CPPUNIT_ASSERT( !( p3 != p3 ) );
|
|
|
|
CPPUNIT_ASSERT( ( p3 != p4 ) );
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT( ( p4 != p1 ) );
|
|
|
|
CPPUNIT_ASSERT( !( p4 != p2 ) );
|
|
|
|
CPPUNIT_ASSERT( ( p4 != p3 ) );
|
|
|
|
CPPUNIT_ASSERT( !( p4 != p4 ) );
|
|
|
|
}
|