From cc0392d4337116c5c271ac8062dee14931e7ff53 Mon Sep 17 00:00:00 2001 From: rich_sposato Date: Sat, 13 Jan 2007 01:47:23 +0000 Subject: [PATCH] Added tests for StrongPtr comparison operators. git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@805 7ec92016-0320-0410-acc4-a06ded1c099a --- test/SmartPtr/main.cpp | 2 + test/SmartPtr/strong.cpp | 91 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 92 insertions(+), 1 deletion(-) diff --git a/test/SmartPtr/main.cpp b/test/SmartPtr/main.cpp index 440684f..3918a8d 100644 --- a/test/SmartPtr/main.cpp +++ b/test/SmartPtr/main.cpp @@ -32,6 +32,7 @@ extern void DoStrongReleaseTests( void ); extern void DoWeakCycleTests( void ); extern void DoStrongConstTests( void ); extern void DoStrongForwardReferenceTest( void ); +extern void DoStrongCompareTests( void ); extern void DoLockedPtrTest( void ); extern void DoLockedStorageTest( void ); @@ -1013,6 +1014,7 @@ int main( unsigned int argc, const char * argv[] ) DoStrongReleaseTests(); DoStrongReleaseTests(); DoWeakCycleTests(); + DoStrongCompareTests(); DoForwardReferenceTest(); DoStrongForwardReferenceTest(); diff --git a/test/SmartPtr/strong.cpp b/test/SmartPtr/strong.cpp index 2071161..2a5349d 100644 --- a/test/SmartPtr/strong.cpp +++ b/test/SmartPtr/strong.cpp @@ -970,6 +970,95 @@ void friend_handling2() BaseClass * pNull ; Ptr w1( new BaseClass ); ReleaseAll( w1, pNull ); +} + +// ---------------------------------------------------------------------------- + +void DoStrongCompareTests( void ) +{ + Earth * p1 = new Earth; + Earth * p2 = new Earth; + Earth_StrongPtr sp1( p1 ); + Earth_StrongPtr sp2( p2 ); + const bool isOneLess = ( p1 < p2 ); + if ( isOneLess ) + { + assert( sp1 < p2 ); + assert( sp1 < sp2 ); + assert( sp1 <= p2 ); + assert( sp1 <= sp2 ); + assert( sp1 <= p1 ); + assert( sp1 == p1 ); + assert( sp1 == sp1 ); + assert( sp1 != p2 ); + assert( sp1 != sp2 ); + assert( sp2 > p1 ); + assert( sp2 > sp1 ); + assert( sp2 >= p1 ); + assert( sp2 >= sp1 ); + assert( sp2 >= p2 ); + assert( sp2 == p2 ); + assert( sp2 == sp2 ); + assert( sp2 != p1 ); + assert( sp2 != sp1 ); + assert( p1 < p2 ); + assert( p1 < sp2 ); + assert( p1 <= p2 ); + assert( p1 <= sp2 ); + assert( p1 <= sp1 ); + assert( p1 == p1 ); + assert( p1 == sp1 ); + assert( p1 != p2 ); + assert( p1 != sp2 ); + assert( p2 > p1 ); + assert( p2 > sp1 ); + assert( p2 >= p1 ); + assert( p2 >= sp1 ); + assert( p2 >= sp2 ); + assert( p2 == p2 ); + assert( p2 == sp2 ); + assert( p2 != p1 ); + assert( p2 != sp1 ); + } + else + { + assert( sp2 < p1 ); + assert( sp2 < sp1 ); + assert( sp2 <= p1 ); + assert( sp2 <= p2 ); + assert( sp2 <= sp1 ); + assert( sp2 == p2 ); + assert( sp2 == sp2 ); + assert( sp2 != p1 ); + assert( sp2 != sp1 ); + assert( sp1 > p2 ); + assert( sp1 > sp2 ); + assert( sp1 >= p2 ); + assert( sp1 >= p1 ); + assert( sp1 >= sp2 ); + assert( sp1 == p1 ); + assert( sp1 == sp1 ); + assert( sp1 != p2 ); + assert( sp1 != sp2 ); + assert( p2 < p1 ); + assert( p2 < sp1 ); + assert( p2 <= p1 ); + assert( p2 <= sp1 ); + assert( p2 <= sp2 ); + assert( p2 == p2 ); + assert( p2 == sp2 ); + assert( p2 != p1 ); + assert( p2 != sp1 ); + assert( p1 > p2 ); + assert( p1 > sp2 ); + assert( p1 >= p2 ); + assert( p1 >= sp2 ); + assert( p1 >= sp1 ); + assert( p1 == p1 ); + assert( p1 == sp1 ); + assert( p1 != p2 ); + assert( p1 != sp2 ); + } +} - } // ----------------------------------------------------------------------------