From 45e065bc4fc93731ea9a0543462bc7cf9e6084d7 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 7 Jan 2009 15:59:57 +0000 Subject: Only two real changes. First, Bu::FString and Bu::FBasicString are in different files. This won't affect any programs at all anywhere. This will just make it easier to maintain and extend later. You still want to include "bu/fstring.h" and use Bu::FString in code. The other is kinda fun. I created a special format for unit tests, they use the extension .unit now and use the mkunit.sh script to convert them to c++ code. There are some nice features here too, maintaining unit tests is much, much easier, and we can have more features without making the code any harder to use. Also, it will be easier to have the unit tests generate reports and be run from a master program and the like. --- src/fbasicstring.cpp | 9 + src/fbasicstring.h | 1132 +++++++++++++++++++++++++++++++++++++++++++++++++ src/fstring.cpp | 8 +- src/fstring.h | 1111 +----------------------------------------------- src/unit/archive.cpp | 145 ------- src/unit/archive.unit | 130 ++++++ src/unit/array.cpp | 101 ----- src/unit/array.unit | 80 ++++ src/unit/file.cpp | 117 ----- src/unit/file.unit | 95 +++++ src/unit/fstring.cpp | 170 -------- src/unit/fstring.unit | 140 ++++++ src/unit/hash.cpp | 109 ----- src/unit/hash.unit | 86 ++++ src/unit/membuf.cpp | 60 --- src/unit/membuf.unit | 45 ++ src/unit/taf.cpp | 133 ------ src/unit/taf.unit | 112 +++++ src/unit/xml.cpp | 39 -- src/unit/xml.unit | 20 + src/unitsuite.cpp | 2 +- src/unitsuite.h | 8 +- 22 files changed, 1869 insertions(+), 1983 deletions(-) create mode 100644 src/fbasicstring.cpp create mode 100644 src/fbasicstring.h delete mode 100644 src/unit/archive.cpp create mode 100644 src/unit/archive.unit delete mode 100644 src/unit/array.cpp create mode 100644 src/unit/array.unit delete mode 100644 src/unit/file.cpp create mode 100644 src/unit/file.unit delete mode 100644 src/unit/fstring.cpp create mode 100644 src/unit/fstring.unit delete mode 100644 src/unit/hash.cpp create mode 100644 src/unit/hash.unit delete mode 100644 src/unit/membuf.cpp create mode 100644 src/unit/membuf.unit delete mode 100644 src/unit/taf.cpp create mode 100644 src/unit/taf.unit delete mode 100644 src/unit/xml.cpp create mode 100644 src/unit/xml.unit (limited to 'src') diff --git a/src/fbasicstring.cpp b/src/fbasicstring.cpp new file mode 100644 index 0000000..6ef4893 --- /dev/null +++ b/src/fbasicstring.cpp @@ -0,0 +1,9 @@ +/* + * Copyright (C) 2007-2008 Xagasoft, All rights reserved. + * + * This file is part of the libbu++ library and is released under the + * terms of the license contained in the file LICENSE. + */ + +#include "fbasicstring.h" + diff --git a/src/fbasicstring.h b/src/fbasicstring.h new file mode 100644 index 0000000..669784b --- /dev/null +++ b/src/fbasicstring.h @@ -0,0 +1,1132 @@ +/* + * Copyright (C) 2007-2008 Xagasoft, All rights reserved. + * + * This file is part of the libbu++ library and is released under the + * terms of the license contained in the file LICENSE. + */ + +#ifndef BU_F_BASIC_STRING_H +#define BU_F_BASIC_STRING_H + +#include +#include + +#ifndef WIN32 +#include +#endif + +#include "bu/archival.h" +#include "bu/archive.h" +#include "bu/util.h" + +namespace Bu +{ + template< typename chr > + struct FStringChunk + { + long nLength; + chr *pData; + FStringChunk *pNext; + }; + /** + * Flexible String class. This class was designed with string passing and + * generation in mind. Like the standard string class you can specify what + * datatype to use for each character. Unlike the standard string class, + * collection of appended and prepended terms is done lazily, making long + * operations that involve many appends very inexpensive. In addition + * internal ref-counting means that if you pass strings around between + * functions there's almost no overhead in time or memory since a reference + * is created and no data is actually copied. This also means that you + * never need to put any FBasicString into a ref-counting container class. + * + *@param chr (typename) Type of character (i.e. char) + *@param nMinSize (int) Chunk size (default: 256) + *@param chralloc (typename) Memory Allocator for chr + *@param chunkalloc (typename) Memory Allocator for chr chunks + */ + template< typename chr, int nMinSize=256, typename chralloc=std::allocator, typename chunkalloc=std::allocator > > + class FBasicString : public Archival + { +#ifndef VALTEST +#define cpy( dest, src, size ) memcpy( dest, src, size*sizeof(chr) ) +#endif + private: + //template< typename chr > + /* struct Chunk + { + long nLength; + chr *pData; + FChunk *pNext; + }; */ + + typedef struct FStringChunk Chunk; + typedef struct FBasicString MyType; + + public: + FBasicString() : + nLength( 0 ), + pFirst( NULL ), + pLast( NULL ) + { + } + + FBasicString( const chr *pData ) : + nLength( 0 ), + pFirst( NULL ), + pLast( NULL ) + { + append( pData ); + } + + FBasicString( const chr *pData, long nLength ) : + nLength( 0 ), + pFirst( NULL ), + pLast( NULL ) + { + append( pData, nLength ); + } + + FBasicString( const MyType &rSrc ) : + Archival(), + nLength( 0 ), + pFirst( NULL ), + pLast( NULL ) + { + if( rSrc.nLength > 0 ) + { + rSrc.flatten(); + append( rSrc.pFirst->pData, rSrc.nLength ); + } + } + + FBasicString( const MyType &rSrc, long nLength ) : + nLength( 0 ), + pFirst( NULL ), + pLast( NULL ) + { + append( rSrc.pFirst->pData, nLength ); + } + + FBasicString( const MyType &rSrc, long nStart, long nLength ) : + nLength( 0 ), + pFirst( NULL ), + pLast( NULL ) + { + append( rSrc.pFirst->pData+nStart, nLength ); + } + + FBasicString( long nSize ) : + nLength( nSize ), + pFirst( NULL ), + pLast( NULL ) + { + pFirst = pLast = newChunk( nSize ); + } + + virtual ~FBasicString() + { + clear(); + } + + /** + *@todo void append( const MyType & sData ) + */ + + /** + * Append data to your string. + *@param pData (const chr *) The data to append. + */ + void append( const chr *pData ) + { + if( !pData ) return; + long nLen; + for( nLen = 0; pData[nLen] != (chr)0; nLen++ ) { } + if( nLen == 0 ) + return; + + Chunk *pNew = newChunk( nLen ); + cpy( pNew->pData, pData, nLen ); + + appendChunk( pNew ); + } + + /** + * Append data to your string. + *@param pData (const chr *) The data to append. + *@param nLen (long) The length of the data to append. + */ + void append( const chr *pData, long nLen ) + { + if( nLen == 0 ) + return; + + Chunk *pNew = newChunk( nLen ); + + cpy( pNew->pData, pData, nLen ); + + appendChunk( pNew ); + } + + /** + * Append a single chr to your string. + *@param cData (const chr &) The character to append. + */ + void append( const chr &cData ) + { + if( pLast && pLast->nLength < nMinSize ) + { + pLast->pData[pLast->nLength] = cData; + ++pLast->nLength; ++nLength; + // pLast->pData[pLast->nLength] = (chr)0; + } + else + { + append( &cData, 1 ); + } + } + + /** + * Append another FString to this one. + *@param sData (MyType &) The FString to append. + */ + void append( const MyType & sData ) + { + append( sData.getStr(), sData.getSize() ); + } + + /** + * Append another FString to this one. + *@param sData (MyType &) The FString to append. + *@param nLen How much data to append. + */ + void append( const MyType & sData, long nLen ) + { + append( sData.getStr(), nLen ); + } + + /** + * Prepend another FString to this one. + *@param sData (MyType &) The FString to prepend. + */ + void prepend( const MyType & sData ) + { + prepend( sData.getStr(), sData.getSize() ); + } + + /** + * Prepend data to your string. + *@param pData (const chr *) The data to prepend. + */ + void prepend( const chr *pData ) + { + if( pData == NULL ) + return; + long nLen; + for( nLen = 0; pData[nLen] != (chr)0; nLen++ ) { } + + Chunk *pNew = newChunk( nLen ); + cpy( pNew->pData, pData, nLen ); + + prependChunk( pNew ); + } + + /** + * Prepend data to your string. + *@param pData (const chr *) The data to prepend. + *@param nLen (long) The length of the data to prepend. + */ + void prepend( const chr *pData, long nLen ) + { + Chunk *pNew = newChunk( nLen ); + + cpy( pNew->pData, pData, nLen ); + + prependChunk( pNew ); + } + + void insert( long nPos, const chr *pData, long nLen ) + { + if( nLen <= 0 ) + return; + if( nPos <= 0 ) + { + prepend( pData, nLen ); + } + else if( nPos >= nLength ) + { + append( pData, nLen ); + } + else + { + flatten(); + Chunk *p1 = newChunk( nPos ); + Chunk *p2 = newChunk( nLen ); + Chunk *p3 = newChunk( nLength-nPos ); + cpy( p1->pData, pFirst->pData, nPos ); + cpy( p2->pData, pData, nLen ); + cpy( p3->pData, pFirst->pData+nPos, nLength-nPos ); + clear(); + appendChunk( p1 ); + appendChunk( p2 ); + appendChunk( p3 ); + } + } + + void insert( long nPos, const MyType &str ) + { + if( nPos <= 0 ) + { + prepend( str ); + } + else if( nPos >= nLength ) + { + append( str ); + } + else + { + flatten(); + Chunk *p1 = newChunk( nPos ); + Chunk *p3 = newChunk( nLength-nPos ); + cpy( p1->pData, pFirst->pData, nPos ); + cpy( p3->pData, pFirst->pData+nPos, nLength-nPos ); + clear(); + appendChunk( p1 ); + for( Chunk *pChnk = str.pFirst; pChnk; pChnk = pChnk->pNext ) + { + appendChunk( copyChunk( pChnk ) ); + } + + appendChunk( p3 ); + } + } + + void insert( long nPos, const chr *pData ) + { + insert( nPos, pData, strlen( pData ) ); + } + + void remove( long nPos, long nLen ) + { + if( nLen <= 0 || nPos < 0 || nPos >= nLength ) + return; + if( nLen > nLength-nPos ) + nLen = nLength-nPos; + flatten(); + cpy( pFirst->pData+nPos, pFirst->pData+nPos+nLen, nLength-nPos-nLen+1 ); + nLength -= nLen; + pFirst->nLength -= nLen; + } + + /** + *@todo void prepend( const chr &cData ) + */ + + /** + * Clear all data from the string. + */ + void clear() + { + realClear(); + } + + /** + * Force the string to resize + *@param nNewSize (long) The new size of the string. + */ + void resize( long nNewSize ) + { + if( nLength == nNewSize ) + return; + if( nNewSize < 0 ) + nNewSize = 0; + + flatten(); + + Chunk *pNew = newChunk( nNewSize ); + long nNewLen = (nNewSize 0 ) + { + cpy( pNew->pData, pFirst->pData, nNewLen ); + aChr.deallocate( pFirst->pData, pFirst->nLength+1 ); + aChunk.deallocate( pFirst, 1 ); + } + pNew->pData[nNewLen] = (chr)0; + pFirst = pLast = pNew; + nLength = nNewSize; + } + + /** + * Get the current size of the string. + *@returns (long) The current size of the string. + */ + long getSize() const + { + return nLength; + } + + /** + * Get a pointer to the string array. + *@returns (chr *) The string data. + */ + chr *getStr() + { + if( pFirst == NULL ) + return (chr *)""; + + flatten(); + pFirst->pData[nLength] = (chr)0; + return pFirst->pData; + } + + /** + * Get a const pointer to the string array. + *@returns (const chr *) The string data. + */ + const chr *getStr() const + { + if( pFirst == NULL ) + return (chr *)""; + + flatten(); + pFirst->pData[nLength] = (chr)0; + return pFirst->pData; + } + + MyType getSubStr( long iStart, long iSize=-1 ) const + { + if( iStart < 0 ) + iStart = 0; + if( iStart >= nLength ) + return ""; + if( iSize < 0 ) + iSize = nLength; + if( iStart+iSize > nLength ) + iSize = nLength-iStart; + if( iSize == 0 ) + return ""; + + flatten(); + MyType ret( pFirst->pData+iStart, iSize ); + return ret; + } + + /** + * (std::string compatability) Get a pointer to the string array. + *@returns (chr *) The string data. + */ + DEPRECATED + chr *c_str() + { + if( pFirst == NULL ) + return NULL; + + flatten(); + pFirst->pData[nLength] = (chr)0; + return pFirst->pData; + } + + /** + * (std::string compatability) Get a const pointer to the string array. + *@returns (const chr *) The string data. + */ + DEPRECATED + const chr *c_str() const + { + if( pFirst == NULL ) + return NULL; + + flatten(); + pFirst->pData[nLength] = (chr)0; + return pFirst->pData; + } + + /** + * Plus equals operator for FString. + *@param pData (const chr *) The data to append to your FString. + */ + MyType &operator +=( const chr *pData ) + { + append( pData ); + + return (*this); + } + + /** + * Plus equals operator for FString. + *@param pData (const MyType &) The FString to append to your FString. + */ + MyType &operator +=( const MyType &rSrc ) + { + if( rSrc.nLength == 0 ) + return (*this); + rSrc.flatten(); + append( rSrc.pFirst->pData, rSrc.nLength ); + + return (*this); + } + + /** + * Plus equals operator for FString. + *@param pData (const chr) The character to append to your FString. + */ + MyType &operator +=( const chr cData ) + { + if( pLast && pLast->nLength < nMinSize ) + { + pLast->pData[pLast->nLength] = cData; + ++pLast->nLength; ++nLength; + // pLast->pData[pLast->nLength] = (chr)0; + } + else + { + append( &cData, 1 ); + } + //append( pData ); + + return (*this); + } + + /** + * Assignment operator. + *@param pData (const chr *) The character array to append to your + * FString. + */ + MyType &operator =( const chr *pData ) + { + clear(); + append( pData ); + + return (*this); + } + + MyType &operator =( const std::basic_string &rData ) + { + clear(); + append( rData.c_str(), rData.size() ); + + return (*this); + } + + MyType operator +( const MyType &rRight ) + { + MyType ret( *this ); + ret.append( rRight ); + return ret; + } + + MyType operator +( const chr *pRight ) + { + MyType ret( *this ); + ret.append( pRight ); + return ret; + } + + MyType operator +( chr *pRight ) + { + MyType ret( *this ); + ret.append( pRight ); + return ret; + } + + /** + * Reset your FString to this character array. + *@param pData (const chr *) The character array to set your FString to. + */ + void set( const chr *pData ) + { + clear(); + append( pData ); + } + + /** + * Reset your FString to this character array. + *@param pData (const chr *) The character array to set your FString to. + *@param nSize (long) The length of the inputted character array. + */ + void set( const chr *pData, long nSize ) + { + clear(); + append( pData, nSize ); + } + + void expand() + { + flatten(); + +#ifndef WIN32 + wordexp_t result; + + /* Expand the string for the program to run. */ + switch (wordexp (pFirst->pData, &result, 0)) + { + case 0: /* Successful. */ + { + set( result.we_wordv[0] ); + wordfree( &result ); + return; + } + break; + case WRDE_NOSPACE: + /* If the error was `WRDE_NOSPACE', + then perhaps part of the result was allocated. */ + wordfree (&result); + default: /* Some other error. */ + return; + } +#endif + } + + /** + * Assignment operator. + *@param rSrc (const MyType &) The FString to set your FString to. + */ + MyType &operator =( const MyType &rSrc ) + { + copyFrom( rSrc ); + + return (*this); + } + + /** + * Equals comparison operator. + *@param pData (const chr *) The character array to compare your FString + * to. + */ + bool operator ==( const chr *pData ) const + { + if( pFirst == NULL ) { + if( pData == NULL ) + return true; + if( pData[0] == (chr)0 ) + return true; + return false; + } + + flatten(); + pFirst->pData[nLength] = (chr)0; + const chr *a = pData; + chr *b = pFirst->pData; + for( long j = 0; *a!=(chr)0 || *b!=(chr)0; j++, a++, b++ ) + { + if( *a != *b ) + return false; + if( *a == (chr)0 && j < nLength ) + return false; + } + + return true; + } + + /** + * Equals comparison operator. + *@param pData (const MyType &) The FString to compare your FString to. + */ + bool operator ==( const MyType &pData ) const + { + if( pFirst == pData.pFirst ) + return true; + if( pFirst == NULL ) + return false; + if( nLength != pData.nLength ) + return false; + + flatten(); + pData.flatten(); + const chr *a = pData.pFirst->pData; + chr *b = pFirst->pData; + for( long j = 0; j < nLength; j++, a++, b++ ) + { + if( *a != *b ) + return false; + } + + return true; + } + + /** + * Not equals comparison operator. + *@param pData (const chr *) The character array to compare your FString + * to. + */ + bool operator !=(const chr *pData ) const + { + return !(*this == pData); + } + + /** + * Not equals comparison operator. + *@param pData (const MyType &) The FString to compare your FString to. + */ + bool operator !=(const MyType &pData ) const + { + return !(*this == pData); + } + + /** + * Indexing operator + *@param nIndex (long) The index of the character you want. + *@returns (chr &) The character at position (nIndex). + */ + chr &operator[]( long nIndex ) + { + flatten(); + + return pFirst->pData[nIndex]; + } + + /** + * Const indexing operator + *@param nIndex (long) The index of the character you want. + *@returns (const chr &) The character at position (nIndex). + */ + const chr &operator[]( long nIndex ) const + { + flatten(); + + return pFirst->pData[nIndex]; + } +/* + operator const chr *() const + { + if( !pFirst ) return NULL; + flatten(); + return pFirst->pData; + } + */ + + operator bool() const + { + return (pFirst != NULL); + } + + bool isSet() const + { + return (pFirst != NULL); + } + + /** + * Is the character at index (nIndex) white space? + *@param nIndex (long) The index of the character you want to check. + *@returns (bool) Is it white space? + */ + bool isWS( long nIndex ) const + { + flatten(); + + return pFirst->pData[nIndex]==' ' || pFirst->pData[nIndex]=='\t' + || pFirst->pData[nIndex]=='\r' || pFirst->pData[nIndex]=='\n'; + } + + /** + * Is the character at index (nIndex) a letter? + *@param nIndex (long) The index of the character you want to check. + *@returns (bool) Is it a letter? + */ + bool isAlpha( long nIndex ) const + { + flatten(); + + return (pFirst->pData[nIndex] >= 'a' && pFirst->pData[nIndex] <= 'z') + || (pFirst->pData[nIndex] >= 'A' && pFirst->pData[nIndex] <= 'Z'); + } + + /** + * Convert your alpha characters to lower case. + */ + void toLower() + { + flatten(); + + for( long j = 0; j < nLength; j++ ) + { + if( pFirst->pData[j] >= 'A' && pFirst->pData[j] <= 'Z' ) + pFirst->pData[j] -= 'A'-'a'; + } + } + + /** + * Convert your alpha characters to upper case. + */ + void toUpper() + { + flatten(); + + for( long j = 0; j < nLength; j++ ) + { + if( pFirst->pData[j] >= 'a' && pFirst->pData[j] <= 'z' ) + pFirst->pData[j] += 'A'-'a'; + } + } + + /** + * Find the index of the first occurrance of (sText) + *@param sText (const chr *) The string to search for. + *@returns (long) The index of the first occurrance. -1 for not found. + */ + long find( const chr cChar ) const + { + flatten(); + for( long j = 0; j < pFirst->nLength; j++ ) + { + if( pFirst->pData[j] == cChar ) + return j; + } + return -1; + } + + /** + * Find the index of the first occurrance of cChar + *@param cChar (const chr) The character to search for. + *@returns (long) The index of the first occurrance. -1 for not found. + */ + long find( const chr *sText ) const + { + long nTLen = strlen( sText ); + flatten(); + for( long j = 0; j < pFirst->nLength-nTLen; j++ ) + { + if( !strncmp( sText, pFirst->pData+j, nTLen ) ) + return j; + } + return -1; + } + + /** + * Find the index of the first occurrance of cChar + *@param sText (const chr *) The string to search for. + *@returns (long) The index of the first occurrance. -1 for not found. + */ + long find( long iStart, const chr cChar ) const + { + flatten(); + for( long j = iStart; j < pFirst->nLength; j++ ) + { + if( pFirst->pData[j] == cChar ) + return j; + } + return -1; + } + + /** + * Find the index of the first occurrance of sText + *@param cChar (const chr) The character to search for. + *@returns (long) The index of the first occurrance. -1 for not found. + */ + long find( long iStart, const chr *sText ) const + { + long nTLen = strlen( sText ); + flatten(); + for( long j = iStart; j < pFirst->nLength-nTLen; j++ ) + { + if( !strncmp( sText, pFirst->pData+j, nTLen ) ) + return j; + } + return -1; + } + + /** + * Do a reverse search for (sText) + *@param sText (const chr *) The string to search for. + *@returns (long) The index of the last occurrance. -1 for not found. + */ + long rfind( const chr *sText ) const + { + long nTLen = strlen( sText ); + flatten(); + for( long j = pFirst->nLength-nTLen-1; j >= 0; j-- ) + { + if( !strncmp( sText, pFirst->pData+j, nTLen ) ) + return j; + } + return -1; + } + + /** + * Remove nAmnt bytes from the front of the string. This function + * operates in O(n) time and should be used sparingly. + */ + void trimFront( long nAmnt ) + { + long nNewLen = nLength - nAmnt; + flatten(); + Chunk *pNew = newChunk( nNewLen ); + cpy( pNew->pData, pFirst->pData+nAmnt, nNewLen ); + clear(); + appendChunk( pNew ); + } + + void format( const char *sFrmt, ...) + { + clear(); + + va_list ap; + va_start( ap, sFrmt ); + + long iLen = vsnprintf( NULL, 0, sFrmt, ap ); + + Chunk *pNew = newChunk( iLen ); + vsnprintf( pNew->pData, iLen+1, sFrmt, ap ); + appendChunk( pNew ); + + va_end( ap ); + } + + void formatAppend( const char *sFrmt, ...) + { + va_list ap; + va_start( ap, sFrmt ); + + long iLen = vsnprintf( NULL, 0, sFrmt, ap ); + + Chunk *pNew = newChunk( iLen ); + vsnprintf( pNew->pData, iLen+1, sFrmt, ap ); + appendChunk( pNew ); + + va_end( ap ); + } + + void formatPrepend( const char *sFrmt, ...) + { + va_list ap; + va_start( ap, sFrmt ); + + long iLen = vsnprintf( NULL, 0, sFrmt, ap ); + + Chunk *pNew = newChunk( iLen ); + vsnprintf( pNew->pData, iLen+1, sFrmt, ap ); + prependChunk( pNew ); + + va_end( ap ); + } + + /** + * Function the archiver calls to archive your FString. + *@param ar (Archive) The archive which is archiving your FString. + */ + void archive( class Archive &ar ) + { + if( ar.isLoading() ) + { + clear(); + long nLen; + ar >> nLen; + + if( nLen > 0 ) + { + Chunk *pNew = newChunk( nLen ); + ar.read( pNew->pData, nLen*sizeof(chr) ); + appendChunk( pNew ); + } + } + else + { + flatten(); + + ar << nLength; + if( nLength ) + ar.write( pFirst->pData, nLength*sizeof(chr) ); + } + } + + typedef chr *iterator; + typedef const chr *const_iterator; + + iterator begin() + { + if( nLength == 0 ) + return NULL; + flatten(); + return pFirst->pData; + } + + const_iterator begin() const + { + if( nLength == 0 ) + return NULL; + flatten(); + return pFirst->pData; + } + + iterator end() + { + if( nLength == 0 ) + return NULL; + return pFirst->pData+pFirst->nLength; + } + + const_iterator end() const + { + if( nLength == 0 ) + return NULL; + return pFirst->pData+pFirst->nLength; + } + + bool isEmpty() const + { + if( nLength == 0 ) + return true; + return false; + } + + private: + void flatten() const + { + if( isFlat() ) + return; + + if( pFirst == NULL ) + return; + + Chunk *pNew = newChunk( nLength ); + chr *pos = pNew->pData; + Chunk *i = pFirst; + for(;;) + { + cpy( pos, i->pData, i->nLength ); + pos += i->nLength; + i = i->pNext; + if( i == NULL ) + break; + } + realClear(); + + pLast = pFirst = pNew; + nLength = pNew->nLength; + } + + void realClear() const + { + if( pFirst == NULL ) + return; + + Chunk *i = pFirst; + for(;;) + { + Chunk *n = i->pNext; + aChr.deallocate( i->pData, i->nLength+1 ); + aChunk.deallocate( i, 1 ); + if( n == NULL ) + break; + i = n; + } + pFirst = pLast = NULL; + nLength = 0; + } + + void copyFrom( const FBasicString &rSrc ) + { + if( rSrc.pFirst == NULL ) + { + clear(); + return; + } + + Chunk *pNew = newChunk( rSrc.nLength ); + chr *pos = pNew->pData; + Chunk *i = rSrc.pFirst; + for(;;) + { + cpy( pos, i->pData, i->nLength ); + pos += i->nLength; + i = i->pNext; + if( i == NULL ) + break; + } + clear(); + + appendChunk( pNew ); + } + + bool isFlat() const + { + return (pFirst == pLast); + } + + Chunk *newChunk() const + { + Chunk *pNew = aChunk.allocate( 1 ); + pNew->pNext = NULL; + return pNew; + } + + Chunk *newChunk( long nLen ) const + { + Chunk *pNew = aChunk.allocate( 1 ); + pNew->pNext = NULL; + pNew->nLength = nLen; + pNew->pData = aChr.allocate( (nLenpData[nLen] = (chr)0; + return pNew; + } + + Chunk *copyChunk( Chunk *pSrc ) const + { + Chunk *pNew = aChunk.allocate( 1 ); + pNew->pNext = pSrc->pNext; + pNew->nLength = pSrc->nLength; + pNew->pData = aChr.allocate( pSrc->nLength+1 ); + cpy( pNew->pData, pSrc->pData, pSrc->nLength ); + pNew->pData[pNew->nLength] = (chr)0; + return pNew; + } + + void appendChunk( Chunk *pNewChunk ) + { + if( pFirst == NULL ) + pLast = pFirst = pNewChunk; + else + { + pLast->pNext = pNewChunk; + pLast = pNewChunk; + } + + nLength += pNewChunk->nLength; + } + + void prependChunk( Chunk *pNewChunk ) + { + if( pFirst == NULL ) + pLast = pFirst = pNewChunk; + else + { + pNewChunk->pNext = pFirst; + pFirst = pNewChunk; + } + + nLength += pNewChunk->nLength; + } + +#ifdef VALTEST + void cpy( chr *dest, const chr *src, long count ) const + { + for( int j = 0; j < count; j++ ) + { + *dest = *src; + dest++; + src++; + } + } +#endif + + private: + mutable long nLength; + mutable Chunk *pFirst; + mutable Chunk *pLast; + + mutable chralloc aChr; + mutable chunkalloc aChunk; + }; + + template FBasicString operator +( const T *pLeft, const FBasicString &rRight ) + { + Bu::FBasicString ret( pLeft ); + ret.append( rRight ); + return ret; + } +} + +#ifndef VALTEST +#undef cpy +#endif + +#endif diff --git a/src/fstring.cpp b/src/fstring.cpp index 3ed4f2b..e4dc716 100644 --- a/src/fstring.cpp +++ b/src/fstring.cpp @@ -8,8 +8,10 @@ #define BU_TRACE #include "bu/trace.h" -#include "fstring.h" -#include "hash.h" +#include "bu/fstring.h" +#include "bu/hash.h" + +template class Bu::FBasicString; template<> uint32_t Bu::__calcHashCode( const Bu::FString &k ) { @@ -37,8 +39,8 @@ std::basic_ostream& operator<< (std::basic_ostream &os, const Bu::FS return os; } - template<> void Bu::__tracer_format( const Bu::FString &v ) { printf("(%ld)\"%s\"", v.getSize(), v.getStr() ); } + diff --git a/src/fstring.h b/src/fstring.h index e1660f9..0793154 100644 --- a/src/fstring.h +++ b/src/fstring.h @@ -8,1121 +8,24 @@ #ifndef BU_F_STRING_H #define BU_F_STRING_H -#include -#include -#include - -#ifndef WIN32 -#include -#endif - -#include "bu/archival.h" -#include "bu/archive.h" -#include "bu/hash.h" -#include "bu/util.h" +#include "bu/fbasicstring.h" namespace Bu { - template< typename chr > - struct FStringChunk - { - long nLength; - chr *pData; - FStringChunk *pNext; - }; - - /** - * Flexible String class. This class was designed with string passing and - * generation in mind. Like the standard string class you can specify what - * datatype to use for each character. Unlike the standard string class, - * collection of appended and prepended terms is done lazily, making long - * operations that involve many appends very inexpensive. In addition - * internal ref-counting means that if you pass strings around between - * functions there's almost no overhead in time or memory since a reference - * is created and no data is actually copied. This also means that you - * never need to put any FBasicString into a ref-counting container class. - * - *@param chr (typename) Type of character (i.e. char) - *@param nMinSize (int) Chunk size (default: 256) - *@param chralloc (typename) Memory Allocator for chr - *@param chunkalloc (typename) Memory Allocator for chr chunks - */ - template< typename chr, int nMinSize=256, typename chralloc=std::allocator, typename chunkalloc=std::allocator > > - class FBasicString : public Archival - { -#ifndef VALTEST -#define cpy( dest, src, size ) memcpy( dest, src, size*sizeof(chr) ) -#endif - private: - typedef struct FStringChunk Chunk; - typedef struct FBasicString MyType; - - public: - FBasicString() : - nLength( 0 ), - pFirst( NULL ), - pLast( NULL ) - { - } - - FBasicString( const chr *pData ) : - nLength( 0 ), - pFirst( NULL ), - pLast( NULL ) - { - append( pData ); - } - - FBasicString( const chr *pData, long nLength ) : - nLength( 0 ), - pFirst( NULL ), - pLast( NULL ) - { - append( pData, nLength ); - } - - FBasicString( const MyType &rSrc ) : - Archival(), - nLength( 0 ), - pFirst( NULL ), - pLast( NULL ) - { - if( rSrc.nLength > 0 ) - { - rSrc.flatten(); - append( rSrc.pFirst->pData, rSrc.nLength ); - } - } - - FBasicString( const MyType &rSrc, long nLength ) : - nLength( 0 ), - pFirst( NULL ), - pLast( NULL ) - { - append( rSrc.pFirst->pData, nLength ); - } - - FBasicString( const MyType &rSrc, long nStart, long nLength ) : - nLength( 0 ), - pFirst( NULL ), - pLast( NULL ) - { - append( rSrc.pFirst->pData+nStart, nLength ); - } - - FBasicString( long nSize ) : - nLength( nSize ), - pFirst( NULL ), - pLast( NULL ) - { - pFirst = pLast = newChunk( nSize ); - } - - virtual ~FBasicString() - { - clear(); - } - - /** - *@todo void append( const MyType & sData ) - */ - - /** - * Append data to your string. - *@param pData (const chr *) The data to append. - */ - void append( const chr *pData ) - { - if( !pData ) return; - long nLen; - for( nLen = 0; pData[nLen] != (chr)0; nLen++ ) { } - if( nLen == 0 ) - return; - - Chunk *pNew = newChunk( nLen ); - cpy( pNew->pData, pData, nLen ); - - appendChunk( pNew ); - } - - /** - * Append data to your string. - *@param pData (const chr *) The data to append. - *@param nLen (long) The length of the data to append. - */ - void append( const chr *pData, long nLen ) - { - if( nLen == 0 ) - return; - - Chunk *pNew = newChunk( nLen ); - - cpy( pNew->pData, pData, nLen ); - - appendChunk( pNew ); - } - - /** - * Append a single chr to your string. - *@param cData (const chr &) The character to append. - */ - void append( const chr &cData ) - { - if( pLast && pLast->nLength < nMinSize ) - { - pLast->pData[pLast->nLength] = cData; - ++pLast->nLength; ++nLength; - // pLast->pData[pLast->nLength] = (chr)0; - } - else - { - append( &cData, 1 ); - } - } - - /** - * Append another FString to this one. - *@param sData (MyType &) The FString to append. - */ - void append( const MyType & sData ) - { - append( sData.getStr(), sData.getSize() ); - } - - /** - * Append another FString to this one. - *@param sData (MyType &) The FString to append. - *@param nLen How much data to append. - */ - void append( const MyType & sData, long nLen ) - { - append( sData.getStr(), nLen ); - } - - /** - * Prepend another FString to this one. - *@param sData (MyType &) The FString to prepend. - */ - void prepend( const MyType & sData ) - { - prepend( sData.getStr(), sData.getSize() ); - } - - /** - * Prepend data to your string. - *@param pData (const chr *) The data to prepend. - */ - void prepend( const chr *pData ) - { - if( pData == NULL ) - return; - long nLen; - for( nLen = 0; pData[nLen] != (chr)0; nLen++ ) { } - - Chunk *pNew = newChunk( nLen ); - cpy( pNew->pData, pData, nLen ); - - prependChunk( pNew ); - } - - /** - * Prepend data to your string. - *@param pData (const chr *) The data to prepend. - *@param nLen (long) The length of the data to prepend. - */ - void prepend( const chr *pData, long nLen ) - { - Chunk *pNew = newChunk( nLen ); - - cpy( pNew->pData, pData, nLen ); - - prependChunk( pNew ); - } - - void insert( long nPos, const chr *pData, long nLen ) - { - if( nLen <= 0 ) - return; - if( nPos <= 0 ) - { - prepend( pData, nLen ); - } - else if( nPos >= nLength ) - { - append( pData, nLen ); - } - else - { - flatten(); - Chunk *p1 = newChunk( nPos ); - Chunk *p2 = newChunk( nLen ); - Chunk *p3 = newChunk( nLength-nPos ); - cpy( p1->pData, pFirst->pData, nPos ); - cpy( p2->pData, pData, nLen ); - cpy( p3->pData, pFirst->pData+nPos, nLength-nPos ); - clear(); - appendChunk( p1 ); - appendChunk( p2 ); - appendChunk( p3 ); - } - } - - void insert( long nPos, const MyType &str ) - { - if( nPos <= 0 ) - { - prepend( str ); - } - else if( nPos >= nLength ) - { - append( str ); - } - else - { - flatten(); - Chunk *p1 = newChunk( nPos ); - Chunk *p3 = newChunk( nLength-nPos ); - cpy( p1->pData, pFirst->pData, nPos ); - cpy( p3->pData, pFirst->pData+nPos, nLength-nPos ); - clear(); - appendChunk( p1 ); - for( Chunk *pChnk = str->pFirst; pChnk; pChnk = pChnk->next ) - { - appendChunk( copyChunk( pChnk ) ); - } - - appendChunk( p3 ); - } - } - - void insert( long nPos, const chr *pData ) - { - insert( nPos, pData, strlen( pData ) ); - } - - void remove( long nPos, long nLen ) - { - if( nLen <= 0 || nPos < 0 || nPos >= nLength ) - return; - if( nLen > nLength-nPos ) - nLen = nLength-nPos; - flatten(); - cpy( pFirst->pData+nPos, pFirst->pData+nPos+nLen, nLength-nPos-nLen+1 ); - nLength -= nLen; - pFirst->nLength -= nLen; - } - - /** - *@todo void prepend( const chr &cData ) - */ - - /** - * Clear all data from the string. - */ - void clear() - { - realClear(); - } - - /** - * Force the string to resize - *@param nNewSize (long) The new size of the string. - */ - void resize( long nNewSize ) - { - if( nLength == nNewSize ) - return; - if( nNewSize < 0 ) - nNewSize = 0; - - flatten(); - - Chunk *pNew = newChunk( nNewSize ); - long nNewLen = (nNewSize 0 ) - { - cpy( pNew->pData, pFirst->pData, nNewLen ); - aChr.deallocate( pFirst->pData, pFirst->nLength+1 ); - aChunk.deallocate( pFirst, 1 ); - } - pNew->pData[nNewLen] = (chr)0; - pFirst = pLast = pNew; - nLength = nNewSize; - } - - /** - * Get the current size of the string. - *@returns (long) The current size of the string. - */ - long getSize() const - { - return nLength; - } - - /** - * Get a pointer to the string array. - *@returns (chr *) The string data. - */ - chr *getStr() - { - if( pFirst == NULL ) - return (chr *)""; - - flatten(); - pFirst->pData[nLength] = (chr)0; - return pFirst->pData; - } - - /** - * Get a const pointer to the string array. - *@returns (const chr *) The string data. - */ - const chr *getStr() const - { - if( pFirst == NULL ) - return (chr *)""; - - flatten(); - pFirst->pData[nLength] = (chr)0; - return pFirst->pData; - } - - MyType getSubStr( long iStart, long iSize=-1 ) const - { - if( iStart < 0 ) - iStart = 0; - if( iStart >= nLength ) - return ""; - if( iSize < 0 ) - iSize = nLength; - if( iStart+iSize > nLength ) - iSize = nLength-iStart; - if( iSize == 0 ) - return ""; - - flatten(); - MyType ret( pFirst->pData+iStart, iSize ); - return ret; - } - - /** - * (std::string compatability) Get a pointer to the string array. - *@returns (chr *) The string data. - */ - DEPRECATED - chr *c_str() - { - if( pFirst == NULL ) - return NULL; - - flatten(); - pFirst->pData[nLength] = (chr)0; - return pFirst->pData; - } - - /** - * (std::string compatability) Get a const pointer to the string array. - *@returns (const chr *) The string data. - */ - DEPRECATED - const chr *c_str() const - { - if( pFirst == NULL ) - return NULL; - - flatten(); - pFirst->pData[nLength] = (chr)0; - return pFirst->pData; - } - - /** - * Plus equals operator for FString. - *@param pData (const chr *) The data to append to your FString. - */ - MyType &operator +=( const chr *pData ) - { - append( pData ); - - return (*this); - } - - /** - * Plus equals operator for FString. - *@param pData (const MyType &) The FString to append to your FString. - */ - MyType &operator +=( const MyType &rSrc ) - { - if( rSrc.nLength == 0 ) - return (*this); - rSrc.flatten(); - append( rSrc.pFirst->pData, rSrc.nLength ); - - return (*this); - } - - /** - * Plus equals operator for FString. - *@param pData (const chr) The character to append to your FString. - */ - MyType &operator +=( const chr cData ) - { - if( pLast && pLast->nLength < nMinSize ) - { - pLast->pData[pLast->nLength] = cData; - ++pLast->nLength; ++nLength; - // pLast->pData[pLast->nLength] = (chr)0; - } - else - { - append( &cData, 1 ); - } - //append( pData ); - - return (*this); - } - - /** - * Assignment operator. - *@param pData (const chr *) The character array to append to your - * FString. - */ - MyType &operator =( const chr *pData ) - { - clear(); - append( pData ); - - return (*this); - } - - MyType &operator =( const std::basic_string &rData ) - { - clear(); - append( rData.c_str(), rData.size() ); - - return (*this); - } - - MyType operator +( const MyType &rRight ) - { - MyType ret( *this ); - ret.append( rRight ); - return ret; - } - - MyType operator +( const chr *pRight ) - { - MyType ret( *this ); - ret.append( pRight ); - return ret; - } - - MyType operator +( chr *pRight ) - { - MyType ret( *this ); - ret.append( pRight ); - return ret; - } - - /** - * Reset your FString to this character array. - *@param pData (const chr *) The character array to set your FString to. - */ - void set( const chr *pData ) - { - clear(); - append( pData ); - } - - /** - * Reset your FString to this character array. - *@param pData (const chr *) The character array to set your FString to. - *@param nSize (long) The length of the inputted character array. - */ - void set( const chr *pData, long nSize ) - { - clear(); - append( pData, nSize ); - } - - void expand() - { - flatten(); - -#ifndef WIN32 - wordexp_t result; - - /* Expand the string for the program to run. */ - switch (wordexp (pFirst->pData, &result, 0)) - { - case 0: /* Successful. */ - { - set( result.we_wordv[0] ); - wordfree( &result ); - return; - } - break; - case WRDE_NOSPACE: - /* If the error was `WRDE_NOSPACE', - then perhaps part of the result was allocated. */ - wordfree (&result); - default: /* Some other error. */ - return; - } -#endif - } - - /** - * Assignment operator. - *@param rSrc (const MyType &) The FString to set your FString to. - */ - MyType &operator =( const MyType &rSrc ) - { - copyFrom( rSrc ); - - return (*this); - } - - /** - * Equals comparison operator. - *@param pData (const chr *) The character array to compare your FString - * to. - */ - bool operator ==( const chr *pData ) const - { - if( pFirst == NULL ) { - if( pData == NULL ) - return true; - if( pData[0] == (chr)0 ) - return true; - return false; - } - - flatten(); - pFirst->pData[nLength] = (chr)0; - const chr *a = pData; - chr *b = pFirst->pData; - for( long j = 0; *a!=(chr)0 || *b!=(chr)0; j++, a++, b++ ) - { - if( *a != *b ) - return false; - if( *a == (chr)0 && j < nLength ) - return false; - } - - return true; - } - - /** - * Equals comparison operator. - *@param pData (const MyType &) The FString to compare your FString to. - */ - bool operator ==( const MyType &pData ) const - { - if( pFirst == pData.pFirst ) - return true; - if( pFirst == NULL ) - return false; - if( nLength != pData.nLength ) - return false; - - flatten(); - pData.flatten(); - const chr *a = pData.pFirst->pData; - chr *b = pFirst->pData; - for( long j = 0; j < nLength; j++, a++, b++ ) - { - if( *a != *b ) - return false; - } - - return true; - } - - /** - * Not equals comparison operator. - *@param pData (const chr *) The character array to compare your FString - * to. - */ - bool operator !=(const chr *pData ) const - { - return !(*this == pData); - } - - /** - * Not equals comparison operator. - *@param pData (const MyType &) The FString to compare your FString to. - */ - bool operator !=(const MyType &pData ) const - { - return !(*this == pData); - } - - /** - * Indexing operator - *@param nIndex (long) The index of the character you want. - *@returns (chr &) The character at position (nIndex). - */ - chr &operator[]( long nIndex ) - { - flatten(); - - return pFirst->pData[nIndex]; - } - - /** - * Const indexing operator - *@param nIndex (long) The index of the character you want. - *@returns (const chr &) The character at position (nIndex). - */ - const chr &operator[]( long nIndex ) const - { - flatten(); - - return pFirst->pData[nIndex]; - } -/* - operator const chr *() const - { - if( !pFirst ) return NULL; - flatten(); - return pFirst->pData; - } - */ - - operator bool() const - { - return (pFirst != NULL); - } - - bool isSet() const - { - return (pFirst != NULL); - } - - /** - * Is the character at index (nIndex) white space? - *@param nIndex (long) The index of the character you want to check. - *@returns (bool) Is it white space? - */ - bool isWS( long nIndex ) const - { - flatten(); - - return pFirst->pData[nIndex]==' ' || pFirst->pData[nIndex]=='\t' - || pFirst->pData[nIndex]=='\r' || pFirst->pData[nIndex]=='\n'; - } - - /** - * Is the character at index (nIndex) a letter? - *@param nIndex (long) The index of the character you want to check. - *@returns (bool) Is it a letter? - */ - bool isAlpha( long nIndex ) const - { - flatten(); - - return (pFirst->pData[nIndex] >= 'a' && pFirst->pData[nIndex] <= 'z') - || (pFirst->pData[nIndex] >= 'A' && pFirst->pData[nIndex] <= 'Z'); - } - - /** - * Convert your alpha characters to lower case. - */ - void toLower() - { - flatten(); - - for( long j = 0; j < nLength; j++ ) - { - if( pFirst->pData[j] >= 'A' && pFirst->pData[j] <= 'Z' ) - pFirst->pData[j] -= 'A'-'a'; - } - } - - /** - * Convert your alpha characters to upper case. - */ - void toUpper() - { - flatten(); - - for( long j = 0; j < nLength; j++ ) - { - if( pFirst->pData[j] >= 'a' && pFirst->pData[j] <= 'z' ) - pFirst->pData[j] += 'A'-'a'; - } - } - - /** - * Find the index of the first occurrance of (sText) - *@param sText (const chr *) The string to search for. - *@returns (long) The index of the first occurrance. -1 for not found. - */ - long find( const chr cChar ) const - { - flatten(); - for( long j = 0; j < pFirst->nLength; j++ ) - { - if( pFirst->pData[j] == cChar ) - return j; - } - return -1; - } - - /** - * Find the index of the first occurrance of cChar - *@param cChar (const chr) The character to search for. - *@returns (long) The index of the first occurrance. -1 for not found. - */ - long find( const chr *sText ) const - { - long nTLen = strlen( sText ); - flatten(); - for( long j = 0; j < pFirst->nLength-nTLen; j++ ) - { - if( !strncmp( sText, pFirst->pData+j, nTLen ) ) - return j; - } - return -1; - } - - /** - * Find the index of the first occurrance of cChar - *@param sText (const chr *) The string to search for. - *@returns (long) The index of the first occurrance. -1 for not found. - */ - long find( long iStart, const chr cChar ) const - { - flatten(); - for( long j = iStart; j < pFirst->nLength; j++ ) - { - if( pFirst->pData[j] == cChar ) - return j; - } - return -1; - } - - /** - * Find the index of the first occurrance of sText - *@param cChar (const chr) The character to search for. - *@returns (long) The index of the first occurrance. -1 for not found. - */ - long find( long iStart, const chr *sText ) const - { - long nTLen = strlen( sText ); - flatten(); - for( long j = iStart; j < pFirst->nLength-nTLen; j++ ) - { - if( !strncmp( sText, pFirst->pData+j, nTLen ) ) - return j; - } - return -1; - } - - /** - * Do a reverse search for (sText) - *@param sText (const chr *) The string to search for. - *@returns (long) The index of the last occurrance. -1 for not found. - */ - long rfind( const chr *sText ) const - { - long nTLen = strlen( sText ); - flatten(); - for( long j = pFirst->nLength-nTLen-1; j >= 0; j-- ) - { - if( !strncmp( sText, pFirst->pData+j, nTLen ) ) - return j; - } - return -1; - } - - /** - * Remove nAmnt bytes from the front of the string. This function - * operates in O(n) time and should be used sparingly. - */ - void trimFront( long nAmnt ) - { - long nNewLen = nLength - nAmnt; - flatten(); - Chunk *pNew = newChunk( nNewLen ); - cpy( pNew->pData, pFirst->pData+nAmnt, nNewLen ); - clear(); - appendChunk( pNew ); - } - - void format( const char *sFrmt, ...) - { - clear(); - - va_list ap; - va_start( ap, sFrmt ); - - long iLen = vsnprintf( NULL, 0, sFrmt, ap ); - - Chunk *pNew = newChunk( iLen ); - vsnprintf( pNew->pData, iLen+1, sFrmt, ap ); - appendChunk( pNew ); - - va_end( ap ); - } - - void formatAppend( const char *sFrmt, ...) - { - va_list ap; - va_start( ap, sFrmt ); - - long iLen = vsnprintf( NULL, 0, sFrmt, ap ); - - Chunk *pNew = newChunk( iLen ); - vsnprintf( pNew->pData, iLen+1, sFrmt, ap ); - appendChunk( pNew ); - - va_end( ap ); - } - - void formatPrepend( const char *sFrmt, ...) - { - va_list ap; - va_start( ap, sFrmt ); - - long iLen = vsnprintf( NULL, 0, sFrmt, ap ); - - Chunk *pNew = newChunk( iLen ); - vsnprintf( pNew->pData, iLen+1, sFrmt, ap ); - prependChunk( pNew ); - - va_end( ap ); - } - - /** - * Function the archiver calls to archive your FString. - *@param ar (Archive) The archive which is archiving your FString. - */ - void archive( class Archive &ar ) - { - if( ar.isLoading() ) - { - clear(); - long nLen; - ar >> nLen; - - if( nLen > 0 ) - { - Chunk *pNew = newChunk( nLen ); - ar.read( pNew->pData, nLen*sizeof(chr) ); - appendChunk( pNew ); - } - } - else - { - flatten(); - - ar << nLength; - if( nLength ) - ar.write( pFirst->pData, nLength*sizeof(chr) ); - } - } - - typedef chr *iterator; - typedef const chr *const_iterator; - - iterator begin() - { - if( nLength == 0 ) - return NULL; - flatten(); - return pFirst->pData; - } - - const_iterator begin() const - { - if( nLength == 0 ) - return NULL; - flatten(); - return pFirst->pData; - } - - iterator end() - { - if( nLength == 0 ) - return NULL; - return pFirst->pData+pFirst->nLength; - } - - const_iterator end() const - { - if( nLength == 0 ) - return NULL; - return pFirst->pData+pFirst->nLength; - } - - bool isEmpty() const - { - if( nLength == 0 ) - return true; - return false; - } - - private: - void flatten() const - { - if( isFlat() ) - return; - - if( pFirst == NULL ) - return; - - Chunk *pNew = newChunk( nLength ); - chr *pos = pNew->pData; - Chunk *i = pFirst; - for(;;) - { - cpy( pos, i->pData, i->nLength ); - pos += i->nLength; - i = i->pNext; - if( i == NULL ) - break; - } - realClear(); - - pLast = pFirst = pNew; - nLength = pNew->nLength; - } - - void realClear() const - { - if( pFirst == NULL ) - return; - - Chunk *i = pFirst; - for(;;) - { - Chunk *n = i->pNext; - aChr.deallocate( i->pData, i->nLength+1 ); - aChunk.deallocate( i, 1 ); - if( n == NULL ) - break; - i = n; - } - pFirst = pLast = NULL; - nLength = 0; - } - - void copyFrom( const FBasicString &rSrc ) - { - if( rSrc.pFirst == NULL ) - { - clear(); - return; - } - - Chunk *pNew = newChunk( rSrc.nLength ); - chr *pos = pNew->pData; - Chunk *i = rSrc.pFirst; - for(;;) - { - cpy( pos, i->pData, i->nLength ); - pos += i->nLength; - i = i->pNext; - if( i == NULL ) - break; - } - clear(); - - appendChunk( pNew ); - } - - bool isFlat() const - { - return (pFirst == pLast); - } - - Chunk *newChunk() const - { - Chunk *pNew = aChunk.allocate( 1 ); - pNew->pNext = NULL; - return pNew; - } - - Chunk *newChunk( long nLen ) const - { - Chunk *pNew = aChunk.allocate( 1 ); - pNew->pNext = NULL; - pNew->nLength = nLen; - pNew->pData = aChr.allocate( (nLenpData[nLen] = (chr)0; - return pNew; - } - - void appendChunk( Chunk *pNewChunk ) - { - if( pFirst == NULL ) - pLast = pFirst = pNewChunk; - else - { - pLast->pNext = pNewChunk; - pLast = pNewChunk; - } - - nLength += pNewChunk->nLength; - } - - void prependChunk( Chunk *pNewChunk ) - { - if( pFirst == NULL ) - pLast = pFirst = pNewChunk; - else - { - pNewChunk->pNext = pFirst; - pFirst = pNewChunk; - } - - nLength += pNewChunk->nLength; - } - -#ifdef VALTEST - void cpy( chr *dest, const chr *src, long count ) const - { - for( int j = 0; j < count; j++ ) - { - *dest = *src; - dest++; - src++; - } - } -#endif - - private: - mutable long nLength; - mutable Chunk *pFirst; - mutable Chunk *pLast; - - mutable chralloc aChr; - mutable chunkalloc aChunk; - }; - typedef FBasicString FString; template<> uint32_t __calcHashCode( const FString &k ); - template<> bool __cmpHashKeys( const FString &a, const FString &b ); - template FBasicString operator +( const T *pLeft, const FBasicString &rRight ) - { - Bu::FBasicString ret( pLeft ); - ret.append( rRight ); - return ret; - } + template<> bool __cmpHashKeys( + const FString &a, const FString &b ); -#ifdef BU_TRACE template void __tracer_format( const t &v ); template<> void __tracer_format( const FString &v ); -#endif } +/***** I dunno about this block, I don't really want to have it... ***** #include -std::basic_ostream& operator<< (std::basic_ostream &os, const Bu::FString &val ); - -#ifndef VALTEST -#undef cpy -#endif +std::basic_ostream& operator<< (std::basic_ostream &os, + const Bu::FString &val ); +*/ #endif diff --git a/src/unit/archive.cpp b/src/unit/archive.cpp deleted file mode 100644 index 8e71f4b..0000000 --- a/src/unit/archive.cpp +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (C) 2007-2008 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include "bu/unitsuite.h" -#include "bu/membuf.h" - -class Unit : public Bu::UnitSuite -{ -public: - Unit() - { - setName("Archive"); - addTest( Unit::testPrimitives ); - addTest( Unit::testContainers ); - } - - virtual ~Unit() - { - } - - void testPrimitives() - { - Bu::MemBuf mb; - { - Bu::Archive ar( mb, Bu::Archive::save ); - ar << (int8_t)1; - ar << (uint8_t)2; - ar << (int16_t)3; - ar << (uint16_t)4; - ar << (int32_t)5; - ar << (uint32_t)6; - ar << (int64_t)7; - ar << (uint64_t)8; - ar << (char)9; - ar << (unsigned char)10; - ar << (short)11; - ar << (unsigned short)12; - ar << (int)13; - ar << (unsigned int)14; - ar << (long)15; - ar << (unsigned long)16; - ar << (long long)17; - ar << (unsigned long long)18; - ar.close(); - } - mb.setPos( 0 ); - { - Bu::Archive ar( mb, Bu::Archive::load ); - int8_t p1; - uint8_t p2; - int16_t p3; - uint16_t p4; - int32_t p5; - uint32_t p6; - int64_t p7; - uint64_t p8; - char p9; - unsigned char p10; - short p11; - unsigned short p12; - int p13; - unsigned int p14; - long p15; - unsigned long p16; - long long p17; - unsigned long long p18; - ar >> p1; - ar >> p2; - ar >> p3; - ar >> p4; - ar >> p5; - ar >> p6; - ar >> p7; - ar >> p8; - ar >> p9; - ar >> p10; - ar >> p11; - ar >> p12; - ar >> p13; - ar >> p14; - ar >> p15; - ar >> p16; - ar >> p17; - ar >> p18; - unitTest( p1 == 1 ); - unitTest( p2 == 2 ); - unitTest( p3 == 3 ); - unitTest( p4 == 4 ); - unitTest( p5 == 5 ); - unitTest( p6 == 6 ); - unitTest( p7 == 7 ); - unitTest( p8 == 8 ); - unitTest( p9 == 9 ); - unitTest( p10 == 10 ); - unitTest( p11 == 11 ); - unitTest( p12 == 12 ); - unitTest( p13 == 13 ); - unitTest( p14 == 14 ); - unitTest( p15 == 15 ); - unitTest( p16 == 16 ); - unitTest( p17 == 17 ); - unitTest( p18 == 18 ); - ar.close(); - } - } - - void testContainers() - { - Bu::MemBuf mb; - { - Bu::Archive ar( mb, Bu::Archive::save ); - Bu::FString sStr("This is a test string."); - Bu::List lList; - lList.append( 10 ); - lList.append( 20 ); - lList.append( 30 ); - lList.append( 40 ); - ar << sStr; - ar << lList; - ar.close(); - } - mb.setPos( 0 ); - { - Bu::Archive ar( mb, Bu::Archive::load ); - Bu::FString sStr; - Bu::List lList; - ar >> sStr; - ar >> lList; - unitTest( sStr == "This is a test string." ); - unitTest( lList.getSize() == 4 ); - Bu::List::iterator i = lList.begin(); - unitTest( *i == 10 ); i++; - unitTest( *i == 20 ); i++; - unitTest( *i == 30 ); i++; - unitTest( *i == 40 ); - ar.close(); - } - } -}; - -int main( int argc, char *argv[] ){ return Unit().run( argc, argv ); } diff --git a/src/unit/archive.unit b/src/unit/archive.unit new file mode 100644 index 0000000..ecc589b --- /dev/null +++ b/src/unit/archive.unit @@ -0,0 +1,130 @@ +// vim: syntax=cpp +/* + * Copyright (C) 2007-2008 Xagasoft, All rights reserved. + * + * This file is part of the libbu++ library and is released under the + * terms of the license contained in the file LICENSE. + */ + +#include "bu/membuf.h" + +{=Init} + +{%testPrimitives} +{ + Bu::MemBuf mb; + { + Bu::Archive ar( mb, Bu::Archive::save ); + ar << (int8_t)1; + ar << (uint8_t)2; + ar << (int16_t)3; + ar << (uint16_t)4; + ar << (int32_t)5; + ar << (uint32_t)6; + ar << (int64_t)7; + ar << (uint64_t)8; + ar << (char)9; + ar << (unsigned char)10; + ar << (short)11; + ar << (unsigned short)12; + ar << (int)13; + ar << (unsigned int)14; + ar << (long)15; + ar << (unsigned long)16; + ar << (long long)17; + ar << (unsigned long long)18; + ar.close(); + } + mb.setPos( 0 ); + { + Bu::Archive ar( mb, Bu::Archive::load ); + int8_t p1; + uint8_t p2; + int16_t p3; + uint16_t p4; + int32_t p5; + uint32_t p6; + int64_t p7; + uint64_t p8; + char p9; + unsigned char p10; + short p11; + unsigned short p12; + int p13; + unsigned int p14; + long p15; + unsigned long p16; + long long p17; + unsigned long long p18; + ar >> p1; + ar >> p2; + ar >> p3; + ar >> p4; + ar >> p5; + ar >> p6; + ar >> p7; + ar >> p8; + ar >> p9; + ar >> p10; + ar >> p11; + ar >> p12; + ar >> p13; + ar >> p14; + ar >> p15; + ar >> p16; + ar >> p17; + ar >> p18; + unitTest( p1 == 1 ); + unitTest( p2 == 2 ); + unitTest( p3 == 3 ); + unitTest( p4 == 4 ); + unitTest( p5 == 5 ); + unitTest( p6 == 6 ); + unitTest( p7 == 7 ); + unitTest( p8 == 8 ); + unitTest( p9 == 9 ); + unitTest( p10 == 10 ); + unitTest( p11 == 11 ); + unitTest( p12 == 12 ); + unitTest( p13 == 13 ); + unitTest( p14 == 14 ); + unitTest( p15 == 15 ); + unitTest( p16 == 16 ); + unitTest( p17 == 17 ); + unitTest( p18 == 18 ); + ar.close(); + } +} + +{%testContainers} +{ + Bu::MemBuf mb; + { + Bu::Archive ar( mb, Bu::Archive::save ); + Bu::FString sStr("This is a test string."); + Bu::List lList; + lList.append( 10 ); + lList.append( 20 ); + lList.append( 30 ); + lList.append( 40 ); + ar << sStr; + ar << lList; + ar.close(); + } + mb.setPos( 0 ); + { + Bu::Archive ar( mb, Bu::Archive::load ); + Bu::FString sStr; + Bu::List lList; + ar >> sStr; + ar >> lList; + unitTest( sStr == "This is a test string." ); + unitTest( lList.getSize() == 4 ); + Bu::List::iterator i = lList.begin(); + unitTest( *i == 10 ); i++; + unitTest( *i == 20 ); i++; + unitTest( *i == 30 ); i++; + unitTest( *i == 40 ); + ar.close(); + } +} diff --git a/src/unit/array.cpp b/src/unit/array.cpp deleted file mode 100644 index f7dc0ae..0000000 --- a/src/unit/array.cpp +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (C) 2007-2008 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include "bu/unitsuite.h" -#include "bu/hash.h" -#include "bu/array.h" - -class Unit : public Bu::UnitSuite -{ -public: - Unit() - { - setName("Array"); - addTest( Unit::general ); - addTest( Unit::iterate1 ); - addTest( Unit::iterate2 ); - addTest( Unit::copy ); - } - - virtual ~Unit() - { - } - - void general() - { - Bu::Array ai; - - ai.append( 5 ); - ai.append( 10 ); - unitTest( ai.getSize() == 2 ); - unitTest( ai.getCapacity() == 10 ); - unitTest( ai[0] == 5 ); - unitTest( ai[1] == 10 ); - } - - void iterate1() - { - Bu::Array ai; - for( int j = 0; j < 10; j++ ) - ai.append( j ); - - int j = 0; - for( Bu::Array::iterator i = ai.begin(); i != ai.end(); i++ ) - unitTest( (*i) == j++ ); - - const Bu::Array &ci = ai; - j = 0; - for( Bu::Array::const_iterator i = ci.begin(); i != ci.end(); i++ ) - unitTest( (*i) == j++ ); - } - - void iterate2() - { - Bu::Array ai; - for( Bu::Array::iterator i = ai.begin(); i != ai.end(); i++ ) - unitFailed("Empty lists shouldn't be iterated through."); - } - - void copy() - { - typedef Bu::Hash StrHash; - typedef Bu::Array StrHashArray; - - StrHash h1; - h1["Hi"] = "Yo"; - h1["Bye"] = "Later"; - - StrHash h2; - h2["Test"] = "Bloop"; - h2["Foo"] = "ooF"; - - StrHashArray a1; - a1.append( h1 ); - a1.append( h2 ); - - StrHashArray a2(a1); - - unitTest( a2[0].get("Hi") == "Yo" ); - unitTest( a2[0].get("Bye") == "Later" ); - unitTest( a2[1].get("Test") == "Bloop" ); - unitTest( a2[1].get("Foo") == "ooF" ); - - StrHashArray a3; - a3 = a1; - - unitTest( a3[0].get("Hi") == "Yo" ); - unitTest( a3[0].get("Bye") == "Later" ); - unitTest( a3[1].get("Test") == "Bloop" ); - unitTest( a3[1].get("Foo") == "ooF" ); - } -}; - -int main( int argc, char *argv[] ) -{ - return Unit().run( argc, argv ); -} - diff --git a/src/unit/array.unit b/src/unit/array.unit new file mode 100644 index 0000000..d5fc573 --- /dev/null +++ b/src/unit/array.unit @@ -0,0 +1,80 @@ +// vim: syntax=cpp +/* + * Copyright (C) 2007-2008 Xagasoft, All rights reserved. + * + * This file is part of the libbu++ library and is released under the + * terms of the license contained in the file LICENSE. + */ + +#include "bu/hash.h" +#include "bu/array.h" + +{=Init} + +{%general} +{ + Bu::Array ai; + + ai.append( 5 ); + ai.append( 10 ); + unitTest( ai.getSize() == 2 ); + unitTest( ai.getCapacity() == 10 ); + unitTest( ai[0] == 5 ); + unitTest( ai[1] == 10 ); +} + +{%iterate1} +{ + Bu::Array ai; + for( int j = 0; j < 10; j++ ) + ai.append( j ); + + int j = 0; + for( Bu::Array::iterator i = ai.begin(); i != ai.end(); i++ ) + unitTest( (*i) == j++ ); + + const Bu::Array &ci = ai; + j = 0; + for( Bu::Array::const_iterator i = ci.begin(); i != ci.end(); i++ ) + unitTest( (*i) == j++ ); +} + +{%iterate2} +{ + Bu::Array ai; + for( Bu::Array::iterator i = ai.begin(); i != ai.end(); i++ ) + unitFailed("Empty lists shouldn't be iterated through."); +} + +{%copy} +{ + typedef Bu::Hash StrHash; + typedef Bu::Array StrHashArray; + + StrHash h1; + h1["Hi"] = "Yo"; + h1["Bye"] = "Later"; + + StrHash h2; + h2["Test"] = "Bloop"; + h2["Foo"] = "ooF"; + + StrHashArray a1; + a1.append( h1 ); + a1.append( h2 ); + + StrHashArray a2(a1); + + unitTest( a2[0].get("Hi") == "Yo" ); + unitTest( a2[0].get("Bye") == "Later" ); + unitTest( a2[1].get("Test") == "Bloop" ); + unitTest( a2[1].get("Foo") == "ooF" ); + + StrHashArray a3; + a3 = a1; + + unitTest( a3[0].get("Hi") == "Yo" ); + unitTest( a3[0].get("Bye") == "Later" ); + unitTest( a3[1].get("Test") == "Bloop" ); + unitTest( a3[1].get("Foo") == "ooF" ); +} diff --git a/src/unit/file.cpp b/src/unit/file.cpp deleted file mode 100644 index cc19fac..0000000 --- a/src/unit/file.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (C) 2007-2008 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include "bu/unitsuite.h" -#include "bu/file.h" - -#include -#include -#include - -class Unit : public Bu::UnitSuite -{ -public: - Unit() - { - setName("File"); - addTest( Unit::writeFull ); - addTest( Unit::readBlocks ); - addTest( Unit::readError1 ); - addTest( Unit::readError2 ); - } - - virtual ~Unit() { } - - // - // Tests go here - // - void writeFull() - { - Bu::File sf("testfile1", Bu::File::Write ); - for( int c = 0; c < 256; c++ ) - { - unsigned char ch = (unsigned char)c; - sf.write( &ch, 1 ); - unitTest( sf.tell() == c+1 ); - } - //unitTest( sf.canRead() == false ); - //unitTest( sf.canWrite() == true ); - //unitTest( sf.canSeek() == true ); - sf.close(); - struct stat sdat; - stat("testfile1", &sdat ); - unitTest( sdat.st_size == 256 ); - } - - void readBlocks() - { - Bu::File sf("testfile1", Bu::File::Read ); - unsigned char buf[50]; - size_t total = 0; - for(;;) - { - size_t s = sf.read( buf, 50 ); - for( size_t c = 0; c < s; c++ ) - { - unitTest( buf[c] == (unsigned char)(c+total) ); - } - total += s; - if( s < 50 ) - { - unitTest( total == 256 ); - unitTest( sf.isEOS() == true ); - break; - } - } - sf.close(); - } - - void readError1() - { - try - { - Bu::File sf("doesn'texist", Bu::File::Read ); - unitFailed("No exception thrown"); - } - catch( Bu::FileException &e ) - { - return; - } - } - - void readError2() - { - Bu::File sf("testfile1", Bu::File::Read ); - char buf[256]; - int r = sf.read( buf, 256 ); - unitTest( r == 256 ); - // You have to read past the end to set the EOS flag. - unitTest( sf.isEOS() == false ); - try - { - if( sf.read( buf, 5 ) > 0 ) - { - unitFailed("Non-zero read result"); - } - else - { - sf.close(); - } - } - catch( Bu::FileException &e ) - { - sf.close(); - return; - } - } -}; - -int main( int argc, char *argv[] ) -{ - return Unit().run( argc, argv ); -} - diff --git a/src/unit/file.unit b/src/unit/file.unit new file mode 100644 index 0000000..e6320ad --- /dev/null +++ b/src/unit/file.unit @@ -0,0 +1,95 @@ +// vim: syntax=cpp +/* + * Copyright (C) 2007-2008 Xagasoft, All rights reserved. + * + * This file is part of the libbu++ library and is released under the + * terms of the license contained in the file LICENSE. + */ + +#include "bu/file.h" + +#include +#include +#include + +{=Init} + +{%writeFull} +{ + Bu::File sf("testfile1", Bu::File::Write ); + for( int c = 0; c < 256; c++ ) + { + unsigned char ch = (unsigned char)c; + sf.write( &ch, 1 ); + unitTest( sf.tell() == c+1 ); + } + //unitTest( sf.canRead() == false ); + //unitTest( sf.canWrite() == true ); + //unitTest( sf.canSeek() == true ); + sf.close(); + struct stat sdat; + stat("testfile1", &sdat ); + unitTest( sdat.st_size == 256 ); +} + +{%readBlocks} +{ + Bu::File sf("testfile1", Bu::File::Read ); + unsigned char buf[50]; + size_t total = 0; + for(;;) + { + size_t s = sf.read( buf, 50 ); + for( size_t c = 0; c < s; c++ ) + { + unitTest( buf[c] == (unsigned char)(c+total) ); + } + total += s; + if( s < 50 ) + { + unitTest( total == 256 ); + unitTest( sf.isEOS() == true ); + break; + } + } + sf.close(); +} + +{%readError1} +{ + try + { + Bu::File sf("doesn'texist", Bu::File::Read ); + unitFailed("No exception thrown"); + } + catch( Bu::FileException &e ) + { + return; + } +} + +{%readError2} +{ + Bu::File sf("testfile1", Bu::File::Read ); + char buf[256]; + int r = sf.read( buf, 256 ); + unitTest( r == 256 ); + // You have to read past the end to set the EOS flag. + unitTest( sf.isEOS() == false ); + try + { + if( sf.read( buf, 5 ) > 0 ) + { + unitFailed("Non-zero read result"); + } + else + { + sf.close(); + } + } + catch( Bu::FileException &e ) + { + sf.close(); + return; + } +} diff --git a/src/unit/fstring.cpp b/src/unit/fstring.cpp deleted file mode 100644 index 9430a83..0000000 --- a/src/unit/fstring.cpp +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Copyright (C) 2007-2008 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include "bu/fstring.h" -#include "bu/unitsuite.h" - -#include - -class Unit : public Bu::UnitSuite -{ -public: - Unit() - { - setName("FString"); - addTest( Unit::compare1 ); - addTest( Unit::compare2 ); - addTest( Unit::appendSingle ); - addTest( Unit::shared1 ); - addTest( Unit::insert ); - addTest( Unit::remove ); - addTest( Unit::add1 ); - addTest( Unit::add2 ); - addTest( Unit::add3 ); - addTest( Unit::add4 ); - addTest( Unit::add5 ); - addTest( Unit::add6 ); - addTest( Unit::subStr1 ); - } - - virtual ~Unit() - { - } - - void compare1() - { - Bu::FString b("Bob"); - unitTest( !(b == "Bobo") ); - unitTest( b == "Bob" ); - } - - void compare2() - { - Bu::FString b("Bobo"); - unitTest( !(b == "Bob") ); - unitTest( b == "Bobo" ); - } - - void appendSingle() - { - Bu::FString b; - for( char l = 'a'; l < 'g'; l++ ) - b += l; - unitTest( b == "abcdef" ); - unitTest( strcmp( b.getStr(), "abcdef" ) == 0 ); - } - - void shared1() - { - Bu::FString a("Hey there"); - Bu::FString b( a ); - unitTest( a.getStr() == b.getStr() ); - b += " guy"; - unitTest( a.getStr() != b.getStr() ); - a = b; - unitTest( a.getStr() == b.getStr() ); - } - - void insert() - { - Bu::FString a("abcd"); - a.insert( 2, "-!-", 3 ); - unitTest( a == "ab-!-cd" ); - - a.insert( 0, "!!", 2 ); - unitTest( a == "!!ab-!-cd" ); - - a.insert( -10, "789", 3 ); - unitTest( a == "789!!ab-!-cd" ); - - a.insert( 12, "89", 2 ); - unitTest( a == "789!!ab-!-cd89" ); - - a.insert( 1203, "12", 2 ); - unitTest( a == "789!!ab-!-cd8912" ); - } - - void remove() - { - Bu::FString a("abHEYcd"); - a.remove( 2, 3 ); - unitTest( a == "abcd" ); - a.remove( 2, 5 ); - unitTest( a == "ab" ); - a += "cdefghijklmnop"; - a.remove( 5, 1 ); - unitTest( a = "abcdeghijklmnop" ); - } - - void add1() - { - Bu::FString a("hi there"); - Bu::FString b(", yeah!"); - Bu::FString c = a + b; - - unitTest( c == "hi there, yeah!" ); - } - - void add2() - { - Bu::FString a("hi there"); - Bu::FString c = a + ", yeah!"; - - unitTest( c == "hi there, yeah!" ); - } - - void add3() - { - Bu::FString a("hi there"); - Bu::FString b(", yeah!"); - Bu::FString c = a + ", Mr. Man" + b; - - unitTest( c == "hi there, Mr. Man, yeah!" ); - } - - void add4() - { - Bu::FString b(", yeah!"); - Bu::FString c = "hi there" + b; - - unitTest( c == "hi there, yeah!" ); - } - - void add5() - { - Bu::FString b; - Bu::FString c = "sup?"; - b += "hey, " + c; - - unitTest( b == "hey, sup?" ); - } - - void add6() - { - Bu::FString a("Hello"); - char b[256] = {"Dude"}; - Bu::FString c = a + "/" + b; - - unitTest( c == "Hello/Dude" ); - } - - void subStr1() - { - Bu::FString a("abcdefghijklmnop"); - unitTest( a.getSubStr( 5, 3 ) == "fgh" ); - unitTest( a.getSubStr( 10 ) == "klmnop" ); - unitTest( a.getSubStr( 40 ) == "" ); - unitTest( a.getSubStr( -10 ) == "abcdefghijklmnop" ); - unitTest( a.getSubStr( -15, 4 ) == "abcd" ); - } -}; - -int main( int argc, char *argv[] ) -{ - return Unit().run( argc, argv ); -} - diff --git a/src/unit/fstring.unit b/src/unit/fstring.unit new file mode 100644 index 0000000..93065fe --- /dev/null +++ b/src/unit/fstring.unit @@ -0,0 +1,140 @@ +// vim: syntax=cpp +/* + * Copyright (C) 2007-2008 Xagasoft, All rights reserved. + * + * This file is part of the libbu++ library and is released under the + * terms of the license contained in the file LICENSE. + */ + +#include "bu/fstring.h" + +#include + +{=Init} + +{%compare1} +{ + Bu::FString b("Bob"); + unitTest( !(b == "Bobo") ); + unitTest( b == "Bob" ); +} + +{%compare2} +{ + Bu::FString b("Bobo"); + unitTest( !(b == "Bob") ); + unitTest( b == "Bobo" ); +} + +{%appendSingle} +{ + Bu::FString b; + for( char l = 'a'; l < 'g'; l++ ) + b += l; + unitTest( b == "abcdef" ); + unitTest( strcmp( b.getStr(), "abcdef" ) == 0 ); +} + +{%shared1} +{ + Bu::FString a("Hey there"); + Bu::FString b( a ); + unitTest( a.getStr() == b.getStr() ); + b += " guy"; + unitTest( a.getStr() != b.getStr() ); + a = b; + unitTest( a.getStr() == b.getStr() ); +} + +{%insert} +{ + Bu::FString a("abcd"); + a.insert( 2, "-!-", 3 ); + unitTest( a == "ab-!-cd" ); + + a.insert( 0, "!!", 2 ); + unitTest( a == "!!ab-!-cd" ); + + a.insert( -10, "789", 3 ); + unitTest( a == "789!!ab-!-cd" ); + + a.insert( 12, "89", 2 ); + unitTest( a == "789!!ab-!-cd89" ); + + a.insert( 1203, "12", 2 ); + unitTest( a == "789!!ab-!-cd8912" ); +} + +{%remove} +{ + Bu::FString a("abHEYcd"); + a.remove( 2, 3 ); + unitTest( a == "abcd" ); + a.remove( 2, 5 ); + unitTest( a == "ab" ); + a += "cdefghijklmnop"; + a.remove( 5, 1 ); + unitTest( a = "abcdeghijklmnop" ); +} + +{%add1} +{ + Bu::FString a("hi there"); + Bu::FString b(", yeah!"); + Bu::FString c = a + b; + + unitTest( c == "hi there, yeah!" ); +} + +{%add2} +{ + Bu::FString a("hi there"); + Bu::FString c = a + ", yeah!"; + + unitTest( c == "hi there, yeah!" ); +} + +{%add3} +{ + Bu::FString a("hi there"); + Bu::FString b(", yeah!"); + Bu::FString c = a + ", Mr. Man" + b; + + unitTest( c == "hi there, Mr. Man, yeah!" ); +} + +{%add4} +{ + Bu::FString b(", yeah!"); + Bu::FString c = "hi there" + b; + + unitTest( c == "hi there, yeah!" ); +} + +{%add5} +{ + Bu::FString b; + Bu::FString c = "sup?"; + b += "hey, " + c; + + unitTest( b == "hey, sup?" ); +} + +{%add6} +{ + Bu::FString a("Hello"); + char b[256] = {"Dude"}; + Bu::FString c = a + "/" + b; + + unitTest( c == "Hello/Dude" ); +} + +{%subStr1} +{ + Bu::FString a("abcdefghijklmnop"); + unitTest( a.getSubStr( 5, 3 ) == "fgh" ); + unitTest( a.getSubStr( 10 ) == "klmnop" ); + unitTest( a.getSubStr( 40 ) == "" ); + unitTest( a.getSubStr( -10 ) == "abcdefghijklmnop" ); + unitTest( a.getSubStr( -15, 4 ) == "abcd" ); +} diff --git a/src/unit/hash.cpp b/src/unit/hash.cpp deleted file mode 100644 index e04a656..0000000 --- a/src/unit/hash.cpp +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (C) 2007-2008 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include "bu/fstring.h" -#include "bu/hash.h" -#include "bu/unitsuite.h" - -#include - -class Unit : public Bu::UnitSuite -{ -private: - typedef Bu::Hash StrIntHash; - typedef Bu::Hash StrStrHash; - typedef Bu::Hash IntStrHash; - -public: - Unit() - { - setName("Hash"); - addTest( Unit::insert1 ); - addTest( Unit::insert2 ); - addTest( Unit::insert3 ); - addTest( Unit::probe1 ); - addTest( Unit::erase1 ); - } - - virtual ~Unit() - { - } - - void probe1() - { - StrIntHash h; - char buf[20]; - for(int i=1;i<10000;i++) - { - sprintf(buf,"%d",i); - Bu::FString sTmp(buf); - h[sTmp] = i; - unitTest( h.has(sTmp) ); - } - } - - void insert1() - { - StrIntHash h; - h["Hi"] = 42; - unitTest( h["Hi"] == 42 ); - } - - void insert2() - { - StrStrHash h; - h["Hi"] = "Yo"; - h["Bye"] = "Later"; - unitTest( h["Hi"].getValue() == "Yo" ); - - StrStrHash h2(h); - unitTest( h2["Hi"].getValue() = "Yo" ); - unitTest( h2["Bye"].getValue() = "Later" ); - - StrStrHash h3; - h3 = h; - unitTest( h3["Hi"].getValue() = "Yo" ); - unitTest( h3["Bye"].getValue() = "Later" ); - } - - void insert3() - { - IntStrHash h; - - for( unsigned int i=1; i<50; i++ ) - { - h[i] = "testing"; - unitTest( h.getSize() == i ); - } - } - - void erase1() - { - StrIntHash h; - h.insert("Number 1", 1 ); - h.insert("Number 2", 2 ); - h.insert("Number 3", 3 ); - h.erase("Number 2"); - h.get("Number 3"); - try { - h.get("Number 2"); - unitFailed("h.get(\"Number 2\") should have thrown an exception."); - } catch( Bu::HashException &e ) { } - - /* printf("\n"); - for( StrIntHash::iterator i = h.begin(); i != h.end(); i++ ) - { - printf(" - \"%s\" = %d\n", i.getKey().getStr(), i.getValue() ); - } */ - } -}; - -int main( int argc, char *argv[] ) -{ - return Unit().run( argc, argv ); -} - diff --git a/src/unit/hash.unit b/src/unit/hash.unit new file mode 100644 index 0000000..bd7da61 --- /dev/null +++ b/src/unit/hash.unit @@ -0,0 +1,86 @@ +// vim: syntax=cpp +/* + * Copyright (C) 2007-2008 Xagasoft, All rights reserved. + * + * This file is part of the libbu++ library and is released under the + * terms of the license contained in the file LICENSE. + */ + +#include "bu/fstring.h" +#include "bu/hash.h" + +#include + +typedef Bu::Hash StrIntHash; +typedef Bu::Hash StrStrHash; +typedef Bu::Hash IntStrHash; + +{=Init} + +{%probe1} +{ + StrIntHash h; + char buf[20]; + for(int i=1;i<10000;i++) + { + sprintf(buf,"%d",i); + Bu::FString sTmp(buf); + h[sTmp] = i; + unitTest( h.has(sTmp) ); + } +} + +{%insert1} +{ + StrIntHash h; + h["Hi"] = 42; + unitTest( h["Hi"] == 42 ); +} + +{%insert2} +{ + StrStrHash h; + h["Hi"] = "Yo"; + h["Bye"] = "Later"; + unitTest( h["Hi"].getValue() == "Yo" ); + + StrStrHash h2(h); + unitTest( h2["Hi"].getValue() = "Yo" ); + unitTest( h2["Bye"].getValue() = "Later" ); + + StrStrHash h3; + h3 = h; + unitTest( h3["Hi"].getValue() = "Yo" ); + unitTest( h3["Bye"].getValue() = "Later" ); +} + +{%insert3} +{ + IntStrHash h; + + for( unsigned int i=1; i<50; i++ ) + { + h[i] = "testing"; + unitTest( h.getSize() == i ); + } +} + +{%erase1} +{ + StrIntHash h; + h.insert("Number 1", 1 ); + h.insert("Number 2", 2 ); + h.insert("Number 3", 3 ); + h.erase("Number 2"); + h.get("Number 3"); + try { + h.get("Number 2"); + unitFailed("h.get(\"Number 2\") should have thrown an exception."); + } catch( Bu::HashException &e ) { } + +/* printf("\n"); + for( StrIntHash::iterator i = h.begin(); i != h.end(); i++ ) + { + printf(" - \"%s\" = %d\n", i.getKey().getStr(), i.getValue() ); + } */ +} diff --git a/src/unit/membuf.cpp b/src/unit/membuf.cpp deleted file mode 100644 index dc02aa3..0000000 --- a/src/unit/membuf.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2007-2008 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include "bu/unitsuite.h" -#include "bu/membuf.h" - -class Unit : public Bu::UnitSuite -{ -public: - Unit() - { - setName("MemBuf"); - addTest( Unit::testWriteRead01 ); - addTest( Unit::testOverwrite1 ); - } - - virtual ~Unit() - { - } - - void testWriteRead01() - { - Bu::MemBuf mb; - unitTest( mb.write("ab", 2 ) == 2 ); - unitTest( mb.write("cde", 3 ) == 3 ); - unitTest( mb.write("FG", 2 ) == 2 ); - - mb.setPos( 0 ); - - char buf[8]; - buf[7] = '\0'; - unitTest( mb.read( buf, 7 ) == 7 ); - unitTest( !strncmp( buf, "abcdeFG", 7 ) ); - unitTest( mb.read( buf, 7 ) == 0 ); - mb.seek( -3 ); - unitTest( mb.read( buf, 7 ) == 3 ); - unitTest( !strncmp( buf, "eFG", 3 ) ); - } - - void testOverwrite1() - { - Bu::MemBuf mb; - unitTest( mb.write("0123456789") == 10 ); - mb.setPos( 4 ); - unitTest( mb.write("-5-") == 3 ); - mb.setPos( 9 ); - mb.write("Hey!!!"); - unitTest( mb.tell() == 15 ); - char buf[50]; - mb.setPos( 0 ); - buf[mb.read( buf, 50 )] = '\0'; - unitTest( !strcmp( buf, "0123-5-78Hey!!!" ) ); - } -}; - -int main( int argc, char *argv[] ){ return Unit().run( argc, argv ); } diff --git a/src/unit/membuf.unit b/src/unit/membuf.unit new file mode 100644 index 0000000..aebf36c --- /dev/null +++ b/src/unit/membuf.unit @@ -0,0 +1,45 @@ +// vim: syntax=cpp +/* + * Copyright (C) 2007-2008 Xagasoft, All rights reserved. + * + * This file is part of the libbu++ library and is released under the + * terms of the license contained in the file LICENSE. + */ + +#include "bu/membuf.h" + +{=Init} + +{%testWriteRead01} +{ + Bu::MemBuf mb; + unitTest( mb.write("ab", 2 ) == 2 ); + unitTest( mb.write("cde", 3 ) == 3 ); + unitTest( mb.write("FG", 2 ) == 2 ); + + mb.setPos( 0 ); + + char buf[8]; + buf[7] = '\0'; + unitTest( mb.read( buf, 7 ) == 7 ); + unitTest( !strncmp( buf, "abcdeFG", 7 ) ); + unitTest( mb.read( buf, 7 ) == 0 ); + mb.seek( -3 ); + unitTest( mb.read( buf, 7 ) == 3 ); + unitTest( !strncmp( buf, "eFG", 3 ) ); +} + +{%testOverwrite1} +{ + Bu::MemBuf mb; + unitTest( mb.write("0123456789") == 10 ); + mb.setPos( 4 ); + unitTest( mb.write("-5-") == 3 ); + mb.setPos( 9 ); + mb.write("Hey!!!"); + unitTest( mb.tell() == 15 ); + char buf[50]; + mb.setPos( 0 ); + buf[mb.read( buf, 50 )] = '\0'; + unitTest( !strcmp( buf, "0123-5-78Hey!!!" ) ); +} diff --git a/src/unit/taf.cpp b/src/unit/taf.cpp deleted file mode 100644 index e4b3ccc..0000000 --- a/src/unit/taf.cpp +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright (C) 2007-2008 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include "bu/unitsuite.h" -#include "bu/file.h" -#include "bu/tafreader.h" -#include "bu/tafwriter.h" -#include "bu/membuf.h" - -#include -#include - -class Unit : public Bu::UnitSuite -{ -public: - Unit() - { - setName("taf"); - addTest( Unit::read1 ); - addTest( Unit::encode1 ); - addTest( Unit::emptyStr1 ); - addTest( Unit::incomplete1 ); - } - - virtual ~Unit() - { - } - - void read1() - { -#define FN_TMP ("/tmp/tmpXXXXXXXX") - Bu::FString sFnTmp(FN_TMP); - Bu::File fOut = Bu::File::tempFile( sFnTmp ); - const char *data = -"{test: name=\"Bob\"}" -; - fOut.write(data,strlen(data)); - fOut.close(); - - Bu::File fIn(sFnTmp.getStr(), Bu::File::Read ); - Bu::TafReader tr(fIn); - - Bu::TafGroup *tn = tr.readGroup(); - unitTest( !strcmp("Bob", tn->getProperty("name").getStr()) ); - delete tn; - - unlink(sFnTmp.getStr()); -#undef FN_TMP - } - - void encode1() - { - Bu::MemBuf mb; - Bu::TafWriter tw( mb ); - - Bu::TafGroup g("Test data"); - Bu::FString sData( 256 ); - for( int j = 0; j < 256; j++ ) - sData[j] = (unsigned char)j; - g.addChild( new Bu::TafProperty("Encoded", sData) ); - tw.writeGroup( &g ); - - static const char *cmpdata = "{\"Test data\":\n \"Encoded\"=\"" - "\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07" - "\\x08\\x09\\x0A\\x0B\\x0C\\x0D\\x0E\\x0F" - "\\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17" - "\\x18\\x19\\x1A\\x1B\\x1C\\x1D\\x1E\\x1F" - " !\\\"#$%&'()*+,-./0123456789:;<=>?@ABCD" - "EFGHIJKLMNOPQRSTUVWXYZ[\\\\]^_`abcdefghi" - "jklmnopqrstuvwxyz{|}~\\x7F" - "\\x80\\x81\\x82\\x83\\x84\\x85\\x86\\x87" - "\\x88\\x89\\x8A\\x8B\\x8C\\x8D\\x8E\\x8F" - "\\x90\\x91\\x92\\x93\\x94\\x95\\x96\\x97" - "\\x98\\x99\\x9A\\x9B\\x9C\\x9D\\x9E\\x9F" - "\\xA0\\xA1\\xA2\\xA3\\xA4\\xA5\\xA6\\xA7" - "\\xA8\\xA9\\xAA\\xAB\\xAC\\xAD\\xAE\\xAF" - "\\xB0\\xB1\\xB2\\xB3\\xB4\\xB5\\xB6\\xB7" - "\\xB8\\xB9\\xBA\\xBB\\xBC\\xBD\\xBE\\xBF" - "\\xC0\\xC1\\xC2\\xC3\\xC4\\xC5\\xC6\\xC7" - "\\xC8\\xC9\\xCA\\xCB\\xCC\\xCD\\xCE\\xCF" - "\\xD0\\xD1\\xD2\\xD3\\xD4\\xD5\\xD6\\xD7" - "\\xD8\\xD9\\xDA\\xDB\\xDC\\xDD\\xDE\\xDF" - "\\xE0\\xE1\\xE2\\xE3\\xE4\\xE5\\xE6\\xE7" - "\\xE8\\xE9\\xEA\\xEB\\xEC\\xED\\xEE\\xEF" - "\\xF0\\xF1\\xF2\\xF3\\xF4\\xF5\\xF6\\xF7" - "\\xF8\\xF9\\xFA\\xFB\\xFC\\xFD\\xFE\\xFF\"\n}\n"; - unitTest( mb.getString() == cmpdata ); - mb.setPos( 0 ); - Bu::TafReader tr( mb ); - Bu::TafGroup *rg = tr.readGroup(); - unitTest( rg->getProperty("Encoded") == sData ); - delete rg; - } - - void emptyStr1() - { - Bu::MemBuf mb; - Bu::TafWriter tw( mb ); - - Bu::TafGroup g("Test Group"); - Bu::FString sVal; - g.addChild( new Bu::TafProperty("Lame", sVal) ); - tw.writeGroup( &g ); - - unitTest( - mb.getString() == "{\"Test Group\":\n \"Lame\"=\"\"\n}\n" ); - } - - void incomplete1() - { - try - { - Bu::MemBuf mb("{Lame: \"Hello=\""); - Bu::TafReader tr( mb ); - delete tr.readGroup(); - unitFailed("Should have thrown an exception, didn't."); - } - catch( Bu::TafException &e ) - { - // Woot - } - } -}; - -int main( int argc, char *argv[] ) -{ - return Unit().run( argc, argv ); -} - diff --git a/src/unit/taf.unit b/src/unit/taf.unit new file mode 100644 index 0000000..5588c85 --- /dev/null +++ b/src/unit/taf.unit @@ -0,0 +1,112 @@ +// vim: syntax=cpp +/* + * Copyright (C) 2007-2008 Xagasoft, All rights reserved. + * + * This file is part of the libbu++ library and is released under the + * terms of the license contained in the file LICENSE. + */ + +#include "bu/file.h" +#include "bu/tafreader.h" +#include "bu/tafwriter.h" +#include "bu/membuf.h" + +#include +#include + +{=Init} + +{%read1} +{ +#define FN_TMP ("/tmp/tmpXXXXXXXX") + Bu::FString sFnTmp(FN_TMP); + Bu::File fOut = Bu::File::tempFile( sFnTmp ); + const char *data = +"{test: name=\"Bob\"}" +; + fOut.write(data,strlen(data)); + fOut.close(); + + Bu::File fIn(sFnTmp.getStr(), Bu::File::Read ); + Bu::TafReader tr(fIn); + + Bu::TafGroup *tn = tr.readGroup(); + unitTest( !strcmp("Bob", tn->getProperty("name").getStr()) ); + delete tn; + + unlink(sFnTmp.getStr()); +#undef FN_TMP +} + +{%encode1} +{ + Bu::MemBuf mb; + Bu::TafWriter tw( mb ); + + Bu::TafGroup g("Test data"); + Bu::FString sData( 256 ); + for( int j = 0; j < 256; j++ ) + sData[j] = (unsigned char)j; + g.addChild( new Bu::TafProperty("Encoded", sData) ); + tw.writeGroup( &g ); + + static const char *cmpdata = "{\"Test data\":\n \"Encoded\"=\"" + "\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07" + "\\x08\\x09\\x0A\\x0B\\x0C\\x0D\\x0E\\x0F" + "\\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17" + "\\x18\\x19\\x1A\\x1B\\x1C\\x1D\\x1E\\x1F" + " !\\\"#$%&'()*+,-./0123456789:;<=>?@ABCD" + "EFGHIJKLMNOPQRSTUVWXYZ[\\\\]^_`abcdefghi" + "jklmnopqrstuvwxyz{|}~\\x7F" + "\\x80\\x81\\x82\\x83\\x84\\x85\\x86\\x87" + "\\x88\\x89\\x8A\\x8B\\x8C\\x8D\\x8E\\x8F" + "\\x90\\x91\\x92\\x93\\x94\\x95\\x96\\x97" + "\\x98\\x99\\x9A\\x9B\\x9C\\x9D\\x9E\\x9F" + "\\xA0\\xA1\\xA2\\xA3\\xA4\\xA5\\xA6\\xA7" + "\\xA8\\xA9\\xAA\\xAB\\xAC\\xAD\\xAE\\xAF" + "\\xB0\\xB1\\xB2\\xB3\\xB4\\xB5\\xB6\\xB7" + "\\xB8\\xB9\\xBA\\xBB\\xBC\\xBD\\xBE\\xBF" + "\\xC0\\xC1\\xC2\\xC3\\xC4\\xC5\\xC6\\xC7" + "\\xC8\\xC9\\xCA\\xCB\\xCC\\xCD\\xCE\\xCF" + "\\xD0\\xD1\\xD2\\xD3\\xD4\\xD5\\xD6\\xD7" + "\\xD8\\xD9\\xDA\\xDB\\xDC\\xDD\\xDE\\xDF" + "\\xE0\\xE1\\xE2\\xE3\\xE4\\xE5\\xE6\\xE7" + "\\xE8\\xE9\\xEA\\xEB\\xEC\\xED\\xEE\\xEF" + "\\xF0\\xF1\\xF2\\xF3\\xF4\\xF5\\xF6\\xF7" + "\\xF8\\xF9\\xFA\\xFB\\xFC\\xFD\\xFE\\xFF\"\n}\n"; + unitTest( mb.getString() == cmpdata ); + mb.setPos( 0 ); + Bu::TafReader tr( mb ); + Bu::TafGroup *rg = tr.readGroup(); + unitTest( rg->getProperty("Encoded") == sData ); + delete rg; +} + +{%emptyStr1} +{ + Bu::MemBuf mb; + Bu::TafWriter tw( mb ); + + Bu::TafGroup g("Test Group"); + Bu::FString sVal; + g.addChild( new Bu::TafProperty("Lame", sVal) ); + tw.writeGroup( &g ); + + unitTest( + mb.getString() == "{\"Test Group\":\n \"Lame\"=\"\"\n}\n" ); +} + +{%incomplete1} +{ + try + { + Bu::MemBuf mb("{Lame: \"Hello=\""); + Bu::TafReader tr( mb ); + delete tr.readGroup(); + unitFailed("Should have thrown an exception, didn't."); + } + catch( Bu::TafException &e ) + { + // Woot + } +} diff --git a/src/unit/xml.cpp b/src/unit/xml.cpp deleted file mode 100644 index e845cc1..0000000 --- a/src/unit/xml.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2007-2008 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include "bu/fstring.h" -#include "bu/unitsuite.h" -#include "bu/xmlreader.h" -#include "bu/membuf.h" - -class Unit : public Bu::UnitSuite -{ -public: - Unit() - { - setName("Xml"); - addTest( Unit::declaration ); - } - - virtual ~Unit() - { - } - - void declaration() - { - Bu::FString sXml(" "); - Bu::MemBuf buf( sXml ); - Bu::XmlReader xr( buf ); - } - -}; - -int main( int argc, char *argv[] ) -{ - return Unit().run( argc, argv ); -} - diff --git a/src/unit/xml.unit b/src/unit/xml.unit new file mode 100644 index 0000000..738ad66 --- /dev/null +++ b/src/unit/xml.unit @@ -0,0 +1,20 @@ +// vim: syntax=cpp +/* + * Copyright (C) 2007-2008 Xagasoft, All rights reserved. + * + * This file is part of the libbu++ library and is released under the + * terms of the license contained in the file LICENSE. + */ + +#include "bu/fstring.h" +#include "bu/xmlreader.h" +#include "bu/membuf.h" + +{=Init} + +{%declaration} +{ + Bu::FString sXml(" "); + Bu::MemBuf buf( sXml ); + Bu::XmlReader xr( buf ); +} diff --git a/src/unitsuite.cpp b/src/unitsuite.cpp index 0008721..b61baa5 100644 --- a/src/unitsuite.cpp +++ b/src/unitsuite.cpp @@ -72,7 +72,7 @@ int Bu::UnitSuite::run( int /*argc*/, char * /*argv */ [] ) return 0; } -void Bu::UnitSuite::add( Test fTest, Bu::FString sName ) +void Bu::UnitSuite::add( Test fTest, const Bu::FString &sName, Expect e ) { TestInfo ti; ti.sName = sName; diff --git a/src/unitsuite.h b/src/unitsuite.h index d27e322..d75211a 100644 --- a/src/unitsuite.h +++ b/src/unitsuite.h @@ -81,9 +81,15 @@ namespace Bu { optStopOnError = 0x000001 }; + + enum Expect + { + expectPass, + expectFail + }; protected: - void add( Test fTest, Bu::FString sName ); + void add( Test fTest, const Bu::FString &sName, Expect e=expectPass ); void setName( const FString &sName ); private: -- cgit v1.2.3