aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2007-08-23 20:17:52 +0000
committerMike Buland <eichlan@xagasoft.com>2007-08-23 20:17:52 +0000
commit4873aad0fe15b3f46c6372b661ce926795922a6e (patch)
tree4a03079f45e39e2ed9d42f389f299f1d6dbe007a /src
parentda6ebe9bd659916122ee973818c3d1f98ce2e007 (diff)
downloadlibbu++-4873aad0fe15b3f46c6372b661ce926795922a6e.tar.gz
libbu++-4873aad0fe15b3f46c6372b661ce926795922a6e.tar.bz2
libbu++-4873aad0fe15b3f46c6372b661ce926795922a6e.tar.xz
libbu++-4873aad0fe15b3f46c6372b661ce926795922a6e.zip
The list now supports insertSorted, and the UnitSuite supports more options,
including StopOnError and handling/reporting of external exceptions.
Diffstat (limited to '')
-rw-r--r--src/list.h49
-rw-r--r--src/unitsuite.cpp21
-rw-r--r--src/unitsuite.h8
3 files changed, 77 insertions, 1 deletions
diff --git a/src/list.h b/src/list.h
index 388df7c..839494d 100644
--- a/src/list.h
+++ b/src/list.h
@@ -142,6 +142,55 @@ namespace Bu
142 } 142 }
143 143
144 /** 144 /**
145 * Insert a new item in sort order by searching for the first item that
146 * is larger and inserting this before it, or at the end if none are
147 * larger. If this is the only function used to insert data in the
148 * List all items will be sorted. To use this, the value type must
149 * support the > operator.
150 */
151 void insertSorted( const value &v )
152 {
153 Link *pNew = la.allocate( 1 );
154 pNew->pValue = va.allocate( 1 );
155 va.construct( pNew->pValue, v );
156 nSize++;
157 if( pFirst == NULL )
158 {
159 // Empty list
160 pFirst = pLast = pNew;
161 pNew->pNext = pNew->pPrev = NULL;
162 return;
163 }
164 else
165 {
166 Link *pCur = pFirst;
167 for(;;)
168 {
169 if( !(v > *(pCur->pValue)) )
170 {
171 pNew->pNext = pCur;
172 pNew->pPrev = pCur->pPrev;
173 pCur->pPrev = pNew;
174 if( pNew->pPrev == NULL )
175 pFirst = pNew;
176 else
177 pNew->pPrev->pNext = pNew;
178 return;
179 }
180 pCur = pCur->pNext;
181 if( pCur == NULL )
182 {
183 pNew->pNext = NULL;
184 pNew->pPrev = pLast;
185 pLast->pNext = pNew;
186 pLast = pNew;
187 return;
188 }
189 }
190 }
191 }
192
193 /**
145 * An iterator to iterate through your list. 194 * An iterator to iterate through your list.
146 */ 195 */
147 typedef struct iterator 196 typedef struct iterator
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 @@
1#include "unitsuite.h" 1#include "unitsuite.h"
2 2
3Bu::UnitSuite::UnitSuite() 3Bu::UnitSuite::UnitSuite() :
4 iOptions( 0 )
5{
6}
7
8Bu::UnitSuite::UnitSuite( int iOptions ) :
9 iOptions( iOptions )
4{ 10{
5} 11}
6 12
@@ -35,10 +41,23 @@ int Bu::UnitSuite::run( int argc, char *argv[] )
35 e.str.getStr() 41 e.str.getStr()
36 ); 42 );
37 } 43 }
44
45 if( (iOptions & optStopOnError) )
46 return 0;
47 }
48 catch( std::exception &e )
49 {
50 printf("failed with unknown exception. what: %s\n", e.what() );
51
52 if( (iOptions & optStopOnError) )
53 return 0;
38 } 54 }
39 catch( ... ) 55 catch( ... )
40 { 56 {
41 printf("failed with external exception.\n"); 57 printf("failed with external exception.\n");
58
59 if( (iOptions & optStopOnError) )
60 return 0;
42 } 61 }
43 } 62 }
44 63
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
49 { 49 {
50 public: 50 public:
51 UnitSuite(); 51 UnitSuite();
52 UnitSuite( int iOptions );
52 virtual ~UnitSuite(); 53 virtual ~UnitSuite();
53 54
54 int run( int argc=0, char *argv[]=NULL ); 55 int run( int argc=0, char *argv[]=NULL );
@@ -68,6 +69,11 @@ namespace Bu
68 int nLine; 69 int nLine;
69 bool bFile; 70 bool bFile;
70 }; 71 };
72
73 enum
74 {
75 optStopOnError = 0x000001
76 };
71 77
72 protected: 78 protected:
73 void add( Test fTest, Bu::FString sName ); 79 void add( Test fTest, Bu::FString sName );
@@ -83,6 +89,8 @@ namespace Bu
83 typedef std::list<TestInfo> TestList; 89 typedef std::list<TestInfo> TestList;
84 TestList lTests; 90 TestList lTests;
85 FString sSuiteName; 91 FString sSuiteName;
92
93 int iOptions;
86 }; 94 };
87} 95}
88 96