From 99095773aa31bf8eb283d6f6319a29c71e51ca9c Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Fri, 4 Aug 2023 13:23:44 -0700 Subject: Woo! Unit Tests! Found some bugs! --- src/stable/string.cpp | 6 +++--- src/unit/blob.unit | 1 + src/unit/queuebuf.unit | 2 +- src/unstable/blob.cpp | 20 +++++++++++++------- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/stable/string.cpp b/src/stable/string.cpp index d8fd218..6bb2c8e 100644 --- a/src/stable/string.cpp +++ b/src/stable/string.cpp @@ -15,7 +15,7 @@ #include "bu/blob.h" #include -#define nMinSize (256) +#define nMinSize (255) Bu::StringCore::StringCore() : nLength( 0 ), @@ -83,7 +83,7 @@ Bu::StringCore::Chunk *Bu::StringCore::newChunk( long nLen ) const Chunk *pNew = new Chunk; pNew->pNext = NULL; pNew->nLength = nLen; - pNew->pData = new char[(nLenpData = new char[(nLenpData[nLen] = (char)0; return pNew; } @@ -95,7 +95,7 @@ Bu::StringCore::Chunk *Bu::StringCore::copyChunk( pNew->pNext = pSrc->pNext; pNew->nLength = pSrc->nLength; pNew->pData = new char[ - (pNew->nLengthnLength)+1 + (pNew->nLengthnLength)+1 ]; memcpy( pNew->pData, pSrc->pData, pSrc->nLength ); pNew->pData[pNew->nLength] = (char)0; diff --git a/src/unit/blob.unit b/src/unit/blob.unit index ac2ee4f..7c6bbd1 100644 --- a/src/unit/blob.unit +++ b/src/unit/blob.unit @@ -63,6 +63,7 @@ suite Blob unitTest( a != c ); unitTest( a != "catt" ); unitTest( a != "ca" ); + unitTest( a != "c" ); unitTest( !(a == c) ); unitTest( !(a == d) ); unitTest( a == a ); diff --git a/src/unit/queuebuf.unit b/src/unit/queuebuf.unit index 559fdaa..b628893 100644 --- a/src/unit/queuebuf.unit +++ b/src/unit/queuebuf.unit @@ -76,7 +76,7 @@ suite QueueBuf test testRandomData { - srandom(time(NULL)); + srandom(1234); Bu::QueueBuf qb; Bu::String sTmp; Bu::String sTmp2; diff --git a/src/unstable/blob.cpp b/src/unstable/blob.cpp index 13209e0..a9cb99d 100644 --- a/src/unstable/blob.cpp +++ b/src/unstable/blob.cpp @@ -236,16 +236,21 @@ bool Bu::Blob::operator!=( const char *pRhs ) const if( pData == pRhs ) return false; - for( int32_t j = 0; j < iSize && pRhs[j]; j++ ) + int32_t j; + for( j = 0; j < iSize && pRhs[j]; j++ ) { if( pData[j] != pRhs[j] ) + { return true; + } } - if( pRhs[iSize] == '\0' ) - return false; + if( !(iSize == j && pRhs[j] == '\0') ) + { + return true; + } - return true; + return false; } bool Bu::Blob::operator<( const Bu::Blob &rRhs ) const @@ -342,7 +347,7 @@ bool Bu::Blob::operator>( const char *pRhs ) const return pData[j] > pRhs[j]; } - if( pRhs[iSize] == '\0' && iSize-1 > j ) + if( pRhs[j] == '\0' && iSize-1 > j ) return true; return false; @@ -367,13 +372,14 @@ bool Bu::Blob::operator>=( const char *pRhs ) const if( pData == pRhs ) return true; - for( int32_t j = 0; j < iSize && pRhs[j]; j++ ) + int32_t j; + for( j = 0; j < iSize && pRhs[j]; j++ ) { if( pData[j] != pRhs[j] ) return pData[j] > pRhs[j]; } - if( pRhs[iSize] == '\0' ) + if( pRhs[j] == '\0' ) return true; return true; -- cgit v1.2.3