From 4873aad0fe15b3f46c6372b661ce926795922a6e Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 23 Aug 2007 20:17:52 +0000 Subject: The list now supports insertSorted, and the UnitSuite supports more options, including StopOnError and handling/reporting of external exceptions. --- src/list.h | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ src/unitsuite.cpp | 21 ++++++++++++++++++++- src/unitsuite.h | 8 ++++++++ 3 files changed, 77 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/list.h b/src/list.h index 388df7c..839494d 100644 --- a/src/list.h +++ b/src/list.h @@ -141,6 +141,55 @@ namespace Bu } } + /** + * Insert a new item in sort order by searching for the first item that + * is larger and inserting this before it, or at the end if none are + * larger. If this is the only function used to insert data in the + * List all items will be sorted. To use this, the value type must + * support the > operator. + */ + void insertSorted( const value &v ) + { + Link *pNew = la.allocate( 1 ); + pNew->pValue = va.allocate( 1 ); + va.construct( pNew->pValue, v ); + nSize++; + if( pFirst == NULL ) + { + // Empty list + pFirst = pLast = pNew; + pNew->pNext = pNew->pPrev = NULL; + return; + } + else + { + Link *pCur = pFirst; + for(;;) + { + if( !(v > *(pCur->pValue)) ) + { + pNew->pNext = pCur; + pNew->pPrev = pCur->pPrev; + pCur->pPrev = pNew; + if( pNew->pPrev == NULL ) + pFirst = pNew; + else + pNew->pPrev->pNext = pNew; + return; + } + pCur = pCur->pNext; + if( pCur == NULL ) + { + pNew->pNext = NULL; + pNew->pPrev = pLast; + pLast->pNext = pNew; + pLast = pNew; + return; + } + } + } + } + /** * An iterator to iterate through your list. */ diff --git a/src/unitsuite.cpp b/src/unitsuite.cpp index 2a28eb5..b61f486 100644 --- a/src/unitsuite.cpp +++ b/src/unitsuite.cpp @@ -1,6 +1,12 @@ #include "unitsuite.h" -Bu::UnitSuite::UnitSuite() +Bu::UnitSuite::UnitSuite() : + iOptions( 0 ) +{ +} + +Bu::UnitSuite::UnitSuite( int iOptions ) : + iOptions( iOptions ) { } @@ -35,10 +41,23 @@ int Bu::UnitSuite::run( int argc, char *argv[] ) e.str.getStr() ); } + + if( (iOptions & optStopOnError) ) + return 0; + } + catch( std::exception &e ) + { + printf("failed with unknown exception. what: %s\n", e.what() ); + + if( (iOptions & optStopOnError) ) + return 0; } catch( ... ) { printf("failed with external exception.\n"); + + if( (iOptions & optStopOnError) ) + return 0; } } diff --git a/src/unitsuite.h b/src/unitsuite.h index 578b4cc..aed7659 100644 --- a/src/unitsuite.h +++ b/src/unitsuite.h @@ -49,6 +49,7 @@ namespace Bu { public: UnitSuite(); + UnitSuite( int iOptions ); virtual ~UnitSuite(); int run( int argc=0, char *argv[]=NULL ); @@ -68,6 +69,11 @@ namespace Bu int nLine; bool bFile; }; + + enum + { + optStopOnError = 0x000001 + }; protected: void add( Test fTest, Bu::FString sName ); @@ -83,6 +89,8 @@ namespace Bu typedef std::list TestList; TestList lTests; FString sSuiteName; + + int iOptions; }; } -- cgit v1.2.3