From aba7c45c2c69d402d1b6fc427cde5bfa4661a0e1 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 7 Jan 2009 16:48:35 +0000 Subject: 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. --- src/hash.h | 5 ----- src/paramproc.cpp | 28 ++++++++++++++-------------- src/paramproc.h | 7 +++---- src/unit/fstring.unit | 2 +- src/unitsuite.cpp | 46 ++++++++++++++++++++++++++++++++++++++++------ src/unitsuite.h | 5 +++-- 6 files changed, 61 insertions(+), 32 deletions(-) (limited to 'src') 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 // nFilled, nDeleted, nCapacity ); } - virtual std::pair getAtPos( uint32_t nPos ) - { - return std::pair(aKeys[nPos],aValues[nPos]); - } - virtual key &getKeyAtPos( uint32_t nPos ) { 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() Bu::ParamProc::~ParamProc() { - for( std::list::iterator i = lArg.begin(); + for( Bu::List::iterator i = lArg.begin(); i != lArg.end(); i++ ) { delete *i; } - for( std::list::iterator i = lBan.begin(); + for( Bu::List::iterator i = lBan.begin(); i != lBan.end(); i++ ) { delete *i; @@ -160,12 +160,12 @@ void Bu::ParamProc::addParam( const char *lpWord, char cChar, Proc proc, if( lpValue ) as->sValue = lpValue; - lArg.push_back( as ); + lArg.append( as ); - if( !lBan.empty() ) + if( !lBan.isEmpty() ) { - if( lBan.back()->pBefore == NULL ) - lBan.back()->pBefore = as; + if( lBan.last()->pBefore == NULL ) + lBan.last()->pBefore = as; } } @@ -395,8 +395,8 @@ void Bu::ParamProc::process( int argc, char *argv[] ) Bu::ParamProc::ArgSpec *Bu::ParamProc::checkWord( const char *arg ) { //printf("Checking \"%s\"...\n", arg ); - std::list::const_iterator i; - for( i = lArg.begin(); i != lArg.end(); i++ ) + Bu::List::const_iterator i = lArg.begin(); + for( ; i != lArg.end(); i++ ) { if( (*i)->sWord == "" ) continue; @@ -420,8 +420,8 @@ Bu::ParamProc::ArgSpec *Bu::ParamProc::checkWord( const char *arg ) Bu::ParamProc::ArgSpec *Bu::ParamProc::checkLetr( const char arg ) { //printf("Checking \'%c\'...\n", arg ); - std::list::const_iterator i; - for( i = lArg.begin(); i != lArg.end(); i++ ) + Bu::List::const_iterator i = lArg.begin(); + for( ; i != lArg.end(); i++ ) { if( (*i)->cChar == '\0' ) continue; @@ -449,10 +449,10 @@ int Bu::ParamProc::unknownParam( int /*argc*/, char *argv[] ) int Bu::ParamProc::help( int /*argc*/, char * /*argv*/ [] ) { - std::list::const_iterator b = lBan.begin(); - std::list::const_iterator i; + Bu::List::const_iterator b = lBan.begin(); + Bu::List::const_iterator i = lArg.begin(); int len=0; - for( i = lArg.begin(); i != lArg.end(); i++ ) + for( ; i != lArg.end(); i++ ) { if( len < (*i)->sWord.getSize() + (*i)->sExtra.getSize() ) len = (*i)->sWord.getSize() + (*i)->sExtra.getSize(); @@ -517,6 +517,6 @@ void Bu::ParamProc::addHelpBanner( const char *sHelpBanner ) Banner *pBan = new Banner; pBan->sBanner = sHelpBanner; pBan->pBefore = NULL; - lBan.push_back( pBan ); + lBan.append( pBan ); } 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 @@ #define BU_PARAM_PROC_H #include -#include -#include +#include "bu/list.h" #include "bu/fstring.h" namespace Bu @@ -153,8 +152,8 @@ namespace Bu Bu::FString sBanner; ArgSpec *pBefore; } Banner; - std::list lBan; - std::list lArg; + Bu::List lBan; + Bu::List lArg; }; } 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 @@ unitTest( strcmp( b.getStr(), "abcdef" ) == 0 ); } -{%shared1} +{%shared1:fail} { Bu::FString a("Hey there"); 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() // Argument handling is coming soon, I promise. int Bu::UnitSuite::run( int /*argc*/, char * /*argv */ [] ) { + int iEPass = 0; + int iEFail = 0; + int iUPass = 0; + int iUFail = 0; for( TestList::iterator i = lTests.begin(); i != lTests.end(); i++ ) { printf("%s: ", i->sName.getStr() ); @@ -31,13 +35,22 @@ int Bu::UnitSuite::run( int /*argc*/, char * /*argv */ [] ) try { (this->*(i->fTest))(); - printf("passed.\n"); + switch( i->eExpect ) + { + case expectPass: printf("expected pass.\n"); iEPass++; break; + case expectFail: printf("unexpected pass.\n"); iUPass++; break; + } } catch( Failed &e ) { + switch( i->eExpect ) + { + case expectPass: printf("unexpected "); iUFail++; break; + case expectFail: printf("expected "); iEFail++; break; + } if( e.bFile ) { - printf("unitTest(%s) failed. (%s:%d)\n", + printf("fail in unitTest(%s). (%s:%d)\n", e.str.getStr(), e.sFile.getStr(), e.nLine @@ -45,7 +58,7 @@ int Bu::UnitSuite::run( int /*argc*/, char * /*argv */ [] ) } else { - printf("unitTest(%s) failed.\n", + printf("fail in unitTest(%s).\n", e.str.getStr() ); } @@ -55,20 +68,40 @@ int Bu::UnitSuite::run( int /*argc*/, char * /*argv */ [] ) } catch( std::exception &e ) { - printf("failed with unknown exception. what: %s\n", e.what() ); + switch( i->eExpect ) + { + case expectPass: printf("unexpected "); iUFail++; break; + case expectFail: printf("expected "); iEFail++; break; + } + printf("fail with unknown exception. what: %s\n", e.what() ); if( (iOptions & optStopOnError) ) return 0; } catch( ... ) { - printf("failed with external exception.\n"); + switch( i->eExpect ) + { + case expectPass: printf("unexpected "); iUFail++; break; + case expectFail: printf("expected "); iEFail++; break; + } + printf("fail with external exception.\n"); if( (iOptions & optStopOnError) ) return 0; } } + printf("\nReport:\n" + "\tTotal tests run: %ld\n" + "\tExpected passes: %d\n" + "\tExpected failures: %d\n" + "\tUnexpected passes: %d\n" + "\tUnexpected failures: %d\n\n", + lTests.getSize(), iEPass, iEFail, iUPass, iUFail ); + if( iUPass == 0 && iUFail == 0 ) + printf("\tNothing unexpected.\n\n"); + return 0; } @@ -76,6 +109,7 @@ void Bu::UnitSuite::add( Test fTest, const Bu::FString &sName, Expect e ) { TestInfo ti; ti.sName = sName; + ti.eExpect = e; long index = ti.sName.rfind("::"); if( index != -1 ) { @@ -84,7 +118,7 @@ void Bu::UnitSuite::add( Test fTest, const Bu::FString &sName, Expect e ) ti.sName = tmp; } ti.fTest = fTest; - lTests.push_back( ti ); + lTests.append( ti ); } void 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 @@ #define BU_UNIT_SUITE_H #include -#include +#include "bu/list.h" #include "fstring.h" namespace Bu @@ -97,9 +97,10 @@ namespace Bu { FString sName; Test fTest; + Expect eExpect; } TestInfo; - typedef std::list TestList; + typedef Bu::List TestList; TestList lTests; FString sSuiteName; -- cgit v1.2.3