aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2009-01-07 16:48:35 +0000
committerMike Buland <eichlan@xagasoft.com>2009-01-07 16:48:35 +0000
commitaba7c45c2c69d402d1b6fc427cde5bfa4661a0e1 (patch)
tree5b3849a8190cdb8742b1f43f4b8bbb43c73ababe /src
parent45e065bc4fc93731ea9a0543462bc7cf9e6084d7 (diff)
downloadlibbu++-aba7c45c2c69d402d1b6fc427cde5bfa4661a0e1.tar.gz
libbu++-aba7c45c2c69d402d1b6fc427cde5bfa4661a0e1.tar.bz2
libbu++-aba7c45c2c69d402d1b6fc427cde5bfa4661a0e1.tar.xz
libbu++-aba7c45c2c69d402d1b6fc427cde5bfa4661a0e1.zip
Corrected a couple of places where std:: classes were being used and shouldn't
have been. Also made the Unit tests actually use expected values, so you can mark a test as "expected fail" and it'll know. It also prints out cute reports at the end of each run.
Diffstat (limited to 'src')
-rw-r--r--src/hash.h5
-rw-r--r--src/paramproc.cpp28
-rw-r--r--src/paramproc.h7
-rw-r--r--src/unit/fstring.unit2
-rw-r--r--src/unitsuite.cpp46
-rw-r--r--src/unitsuite.h5
6 files changed, 61 insertions, 32 deletions
diff --git a/src/hash.h b/src/hash.h
index e717c60..8c58645 100644
--- a/src/hash.h
+++ b/src/hash.h
@@ -894,11 +894,6 @@ namespace Bu
894 // nFilled, nDeleted, nCapacity ); 894 // nFilled, nDeleted, nCapacity );
895 } 895 }
896 896
897 virtual std::pair<key,value> getAtPos( uint32_t nPos )
898 {
899 return std::pair<key,value>(aKeys[nPos],aValues[nPos]);
900 }
901
902 virtual key &getKeyAtPos( uint32_t nPos ) 897 virtual key &getKeyAtPos( uint32_t nPos )
903 { 898 {
904 return aKeys[nPos]; 899 return aKeys[nPos];
diff --git a/src/paramproc.cpp b/src/paramproc.cpp
index 7aeb819..819a4da 100644
--- a/src/paramproc.cpp
+++ b/src/paramproc.cpp
@@ -121,13 +121,13 @@ Bu::ParamProc::ParamProc()
121 121
122Bu::ParamProc::~ParamProc() 122Bu::ParamProc::~ParamProc()
123{ 123{
124 for( std::list<ArgSpec *>::iterator i = lArg.begin(); 124 for( Bu::List<ArgSpec *>::iterator i = lArg.begin();
125 i != lArg.end(); i++ ) 125 i != lArg.end(); i++ )
126 { 126 {
127 delete *i; 127 delete *i;
128 } 128 }
129 129
130 for( std::list<Banner *>::iterator i = lBan.begin(); 130 for( Bu::List<Banner *>::iterator i = lBan.begin();
131 i != lBan.end(); i++ ) 131 i != lBan.end(); i++ )
132 { 132 {
133 delete *i; 133 delete *i;
@@ -160,12 +160,12 @@ void Bu::ParamProc::addParam( const char *lpWord, char cChar, Proc proc,
160 if( lpValue ) 160 if( lpValue )
161 as->sValue = lpValue; 161 as->sValue = lpValue;
162 162
163 lArg.push_back( as ); 163 lArg.append( as );
164 164
165 if( !lBan.empty() ) 165 if( !lBan.isEmpty() )
166 { 166 {
167 if( lBan.back()->pBefore == NULL ) 167 if( lBan.last()->pBefore == NULL )
168 lBan.back()->pBefore = as; 168 lBan.last()->pBefore = as;
169 } 169 }
170} 170}
171 171
@@ -395,8 +395,8 @@ void Bu::ParamProc::process( int argc, char *argv[] )
395Bu::ParamProc::ArgSpec *Bu::ParamProc::checkWord( const char *arg ) 395Bu::ParamProc::ArgSpec *Bu::ParamProc::checkWord( const char *arg )
396{ 396{
397 //printf("Checking \"%s\"...\n", arg ); 397 //printf("Checking \"%s\"...\n", arg );
398 std::list<ArgSpec *>::const_iterator i; 398 Bu::List<ArgSpec *>::const_iterator i = lArg.begin();
399 for( i = lArg.begin(); i != lArg.end(); i++ ) 399 for( ; i != lArg.end(); i++ )
400 { 400 {
401 if( (*i)->sWord == "" ) 401 if( (*i)->sWord == "" )
402 continue; 402 continue;
@@ -420,8 +420,8 @@ Bu::ParamProc::ArgSpec *Bu::ParamProc::checkWord( const char *arg )
420Bu::ParamProc::ArgSpec *Bu::ParamProc::checkLetr( const char arg ) 420Bu::ParamProc::ArgSpec *Bu::ParamProc::checkLetr( const char arg )
421{ 421{
422 //printf("Checking \'%c\'...\n", arg ); 422 //printf("Checking \'%c\'...\n", arg );
423 std::list<ArgSpec *>::const_iterator i; 423 Bu::List<ArgSpec *>::const_iterator i = lArg.begin();
424 for( i = lArg.begin(); i != lArg.end(); i++ ) 424 for( ; i != lArg.end(); i++ )
425 { 425 {
426 if( (*i)->cChar == '\0' ) 426 if( (*i)->cChar == '\0' )
427 continue; 427 continue;
@@ -449,10 +449,10 @@ int Bu::ParamProc::unknownParam( int /*argc*/, char *argv[] )
449 449
450int Bu::ParamProc::help( int /*argc*/, char * /*argv*/ [] ) 450int Bu::ParamProc::help( int /*argc*/, char * /*argv*/ [] )
451{ 451{
452 std::list<Banner *>::const_iterator b = lBan.begin(); 452 Bu::List<Banner *>::const_iterator b = lBan.begin();
453 std::list<ArgSpec *>::const_iterator i; 453 Bu::List<ArgSpec *>::const_iterator i = lArg.begin();
454 int len=0; 454 int len=0;
455 for( i = lArg.begin(); i != lArg.end(); i++ ) 455 for( ; i != lArg.end(); i++ )
456 { 456 {
457 if( len < (*i)->sWord.getSize() + (*i)->sExtra.getSize() ) 457 if( len < (*i)->sWord.getSize() + (*i)->sExtra.getSize() )
458 len = (*i)->sWord.getSize() + (*i)->sExtra.getSize(); 458 len = (*i)->sWord.getSize() + (*i)->sExtra.getSize();
@@ -517,6 +517,6 @@ void Bu::ParamProc::addHelpBanner( const char *sHelpBanner )
517 Banner *pBan = new Banner; 517 Banner *pBan = new Banner;
518 pBan->sBanner = sHelpBanner; 518 pBan->sBanner = sHelpBanner;
519 pBan->pBefore = NULL; 519 pBan->pBefore = NULL;
520 lBan.push_back( pBan ); 520 lBan.append( pBan );
521} 521}
522 522
diff --git a/src/paramproc.h b/src/paramproc.h
index bd59948..b7dbae3 100644
--- a/src/paramproc.h
+++ b/src/paramproc.h
@@ -9,8 +9,7 @@
9#define BU_PARAM_PROC_H 9#define BU_PARAM_PROC_H
10 10
11#include <stdint.h> 11#include <stdint.h>
12#include <string> 12#include "bu/list.h"
13#include <list>
14#include "bu/fstring.h" 13#include "bu/fstring.h"
15 14
16namespace Bu 15namespace Bu
@@ -153,8 +152,8 @@ namespace Bu
153 Bu::FString sBanner; 152 Bu::FString sBanner;
154 ArgSpec *pBefore; 153 ArgSpec *pBefore;
155 } Banner; 154 } Banner;
156 std::list<Banner *> lBan; 155 Bu::List<Banner *> lBan;
157 std::list<ArgSpec *> lArg; 156 Bu::List<ArgSpec *> lArg;
158 }; 157 };
159} 158}
160 159
diff --git a/src/unit/fstring.unit b/src/unit/fstring.unit
index 93065fe..3912de2 100644
--- a/src/unit/fstring.unit
+++ b/src/unit/fstring.unit
@@ -35,7 +35,7 @@
35 unitTest( strcmp( b.getStr(), "abcdef" ) == 0 ); 35 unitTest( strcmp( b.getStr(), "abcdef" ) == 0 );
36} 36}
37 37
38{%shared1} 38{%shared1:fail}
39{ 39{
40 Bu::FString a("Hey there"); 40 Bu::FString a("Hey there");
41 Bu::FString b( a ); 41 Bu::FString b( a );
diff --git a/src/unitsuite.cpp b/src/unitsuite.cpp
index b61baa5..7421496 100644
--- a/src/unitsuite.cpp
+++ b/src/unitsuite.cpp
@@ -24,6 +24,10 @@ Bu::UnitSuite::~UnitSuite()
24// Argument handling is coming soon, I promise. 24// Argument handling is coming soon, I promise.
25int Bu::UnitSuite::run( int /*argc*/, char * /*argv */ [] ) 25int Bu::UnitSuite::run( int /*argc*/, char * /*argv */ [] )
26{ 26{
27 int iEPass = 0;
28 int iEFail = 0;
29 int iUPass = 0;
30 int iUFail = 0;
27 for( TestList::iterator i = lTests.begin(); i != lTests.end(); i++ ) 31 for( TestList::iterator i = lTests.begin(); i != lTests.end(); i++ )
28 { 32 {
29 printf("%s: ", i->sName.getStr() ); 33 printf("%s: ", i->sName.getStr() );
@@ -31,13 +35,22 @@ int Bu::UnitSuite::run( int /*argc*/, char * /*argv */ [] )
31 try 35 try
32 { 36 {
33 (this->*(i->fTest))(); 37 (this->*(i->fTest))();
34 printf("passed.\n"); 38 switch( i->eExpect )
39 {
40 case expectPass: printf("expected pass.\n"); iEPass++; break;
41 case expectFail: printf("unexpected pass.\n"); iUPass++; break;
42 }
35 } 43 }
36 catch( Failed &e ) 44 catch( Failed &e )
37 { 45 {
46 switch( i->eExpect )
47 {
48 case expectPass: printf("unexpected "); iUFail++; break;
49 case expectFail: printf("expected "); iEFail++; break;
50 }
38 if( e.bFile ) 51 if( e.bFile )
39 { 52 {
40 printf("unitTest(%s) failed. (%s:%d)\n", 53 printf("fail in unitTest(%s). (%s:%d)\n",
41 e.str.getStr(), 54 e.str.getStr(),
42 e.sFile.getStr(), 55 e.sFile.getStr(),
43 e.nLine 56 e.nLine
@@ -45,7 +58,7 @@ int Bu::UnitSuite::run( int /*argc*/, char * /*argv */ [] )
45 } 58 }
46 else 59 else
47 { 60 {
48 printf("unitTest(%s) failed.\n", 61 printf("fail in unitTest(%s).\n",
49 e.str.getStr() 62 e.str.getStr()
50 ); 63 );
51 } 64 }
@@ -55,20 +68,40 @@ int Bu::UnitSuite::run( int /*argc*/, char * /*argv */ [] )
55 } 68 }
56 catch( std::exception &e ) 69 catch( std::exception &e )
57 { 70 {
58 printf("failed with unknown exception. what: %s\n", e.what() ); 71 switch( i->eExpect )
72 {
73 case expectPass: printf("unexpected "); iUFail++; break;
74 case expectFail: printf("expected "); iEFail++; break;
75 }
76 printf("fail with unknown exception. what: %s\n", e.what() );
59 77
60 if( (iOptions & optStopOnError) ) 78 if( (iOptions & optStopOnError) )
61 return 0; 79 return 0;
62 } 80 }
63 catch( ... ) 81 catch( ... )
64 { 82 {
65 printf("failed with external exception.\n"); 83 switch( i->eExpect )
84 {
85 case expectPass: printf("unexpected "); iUFail++; break;
86 case expectFail: printf("expected "); iEFail++; break;
87 }
88 printf("fail with external exception.\n");
66 89
67 if( (iOptions & optStopOnError) ) 90 if( (iOptions & optStopOnError) )
68 return 0; 91 return 0;
69 } 92 }
70 } 93 }
71 94
95 printf("\nReport:\n"
96 "\tTotal tests run: %ld\n"
97 "\tExpected passes: %d\n"
98 "\tExpected failures: %d\n"
99 "\tUnexpected passes: %d\n"
100 "\tUnexpected failures: %d\n\n",
101 lTests.getSize(), iEPass, iEFail, iUPass, iUFail );
102 if( iUPass == 0 && iUFail == 0 )
103 printf("\tNothing unexpected.\n\n");
104
72 return 0; 105 return 0;
73} 106}
74 107
@@ -76,6 +109,7 @@ void Bu::UnitSuite::add( Test fTest, const Bu::FString &sName, Expect e )
76{ 109{
77 TestInfo ti; 110 TestInfo ti;
78 ti.sName = sName; 111 ti.sName = sName;
112 ti.eExpect = e;
79 long index = ti.sName.rfind("::"); 113 long index = ti.sName.rfind("::");
80 if( index != -1 ) 114 if( index != -1 )
81 { 115 {
@@ -84,7 +118,7 @@ void Bu::UnitSuite::add( Test fTest, const Bu::FString &sName, Expect e )
84 ti.sName = tmp; 118 ti.sName = tmp;
85 } 119 }
86 ti.fTest = fTest; 120 ti.fTest = fTest;
87 lTests.push_back( ti ); 121 lTests.append( ti );
88} 122}
89 123
90void Bu::UnitSuite::setName( const FString &sName ) 124void Bu::UnitSuite::setName( const FString &sName )
diff --git a/src/unitsuite.h b/src/unitsuite.h
index d75211a..97a1aec 100644
--- a/src/unitsuite.h
+++ b/src/unitsuite.h
@@ -9,7 +9,7 @@
9#define BU_UNIT_SUITE_H 9#define BU_UNIT_SUITE_H
10 10
11#include <stdint.h> 11#include <stdint.h>
12#include <list> 12#include "bu/list.h"
13#include "fstring.h" 13#include "fstring.h"
14 14
15namespace Bu 15namespace Bu
@@ -97,9 +97,10 @@ namespace Bu
97 { 97 {
98 FString sName; 98 FString sName;
99 Test fTest; 99 Test fTest;
100 Expect eExpect;
100 } TestInfo; 101 } TestInfo;
101 102
102 typedef std::list<TestInfo> TestList; 103 typedef Bu::List<TestInfo> TestList;
103 TestList lTests; 104 TestList lTests;
104 FString sSuiteName; 105 FString sSuiteName;
105 106