aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2023-08-04 13:23:44 -0700
committerMike Buland <eichlan@xagasoft.com>2023-08-04 13:23:44 -0700
commit99095773aa31bf8eb283d6f6319a29c71e51ca9c (patch)
tree9727523e7d3a035cb4e8e6c1d9eacbe49c766397
parent311d146e2d921bed4ae9d3b19203e935358b30ba (diff)
downloadlibbu++-99095773aa31bf8eb283d6f6319a29c71e51ca9c.tar.gz
libbu++-99095773aa31bf8eb283d6f6319a29c71e51ca9c.tar.bz2
libbu++-99095773aa31bf8eb283d6f6319a29c71e51ca9c.tar.xz
libbu++-99095773aa31bf8eb283d6f6319a29c71e51ca9c.zip
Woo! Unit Tests! Found some bugs!
-rw-r--r--src/stable/string.cpp6
-rw-r--r--src/unit/blob.unit1
-rw-r--r--src/unit/queuebuf.unit2
-rw-r--r--src/unstable/blob.cpp20
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 @@
15#include "bu/blob.h" 15#include "bu/blob.h"
16#include <stdlib.h> 16#include <stdlib.h>
17 17
18#define nMinSize (256) 18#define nMinSize (255)
19 19
20Bu::StringCore::StringCore() : 20Bu::StringCore::StringCore() :
21 nLength( 0 ), 21 nLength( 0 ),
@@ -83,7 +83,7 @@ Bu::StringCore::Chunk *Bu::StringCore::newChunk( long nLen ) const
83 Chunk *pNew = new Chunk; 83 Chunk *pNew = new Chunk;
84 pNew->pNext = NULL; 84 pNew->pNext = NULL;
85 pNew->nLength = nLen; 85 pNew->nLength = nLen;
86 pNew->pData = new char[(nLen<nMinSize)?(nMinSize):(nLen)+1]; 86 pNew->pData = new char[(nLen<nMinSize)?(nMinSize+1):(nLen)+1];
87 pNew->pData[nLen] = (char)0; 87 pNew->pData[nLen] = (char)0;
88 return pNew; 88 return pNew;
89} 89}
@@ -95,7 +95,7 @@ Bu::StringCore::Chunk *Bu::StringCore::copyChunk(
95 pNew->pNext = pSrc->pNext; 95 pNew->pNext = pSrc->pNext;
96 pNew->nLength = pSrc->nLength; 96 pNew->nLength = pSrc->nLength;
97 pNew->pData = new char[ 97 pNew->pData = new char[
98 (pNew->nLength<nMinSize)?(nMinSize):(pNew->nLength)+1 98 (pNew->nLength<nMinSize)?(nMinSize+1):(pNew->nLength)+1
99 ]; 99 ];
100 memcpy( pNew->pData, pSrc->pData, pSrc->nLength ); 100 memcpy( pNew->pData, pSrc->pData, pSrc->nLength );
101 pNew->pData[pNew->nLength] = (char)0; 101 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
63 unitTest( a != c ); 63 unitTest( a != c );
64 unitTest( a != "catt" ); 64 unitTest( a != "catt" );
65 unitTest( a != "ca" ); 65 unitTest( a != "ca" );
66 unitTest( a != "c" );
66 unitTest( !(a == c) ); 67 unitTest( !(a == c) );
67 unitTest( !(a == d) ); 68 unitTest( !(a == d) );
68 unitTest( a == a ); 69 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
76 76
77 test testRandomData 77 test testRandomData
78 { 78 {
79 srandom(time(NULL)); 79 srandom(1234);
80 Bu::QueueBuf qb; 80 Bu::QueueBuf qb;
81 Bu::String sTmp; 81 Bu::String sTmp;
82 Bu::String sTmp2; 82 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
236 if( pData == pRhs ) 236 if( pData == pRhs )
237 return false; 237 return false;
238 238
239 for( int32_t j = 0; j < iSize && pRhs[j]; j++ ) 239 int32_t j;
240 for( j = 0; j < iSize && pRhs[j]; j++ )
240 { 241 {
241 if( pData[j] != pRhs[j] ) 242 if( pData[j] != pRhs[j] )
243 {
242 return true; 244 return true;
245 }
243 } 246 }
244 247
245 if( pRhs[iSize] == '\0' ) 248 if( !(iSize == j && pRhs[j] == '\0') )
246 return false; 249 {
250 return true;
251 }
247 252
248 return true; 253 return false;
249} 254}
250 255
251bool Bu::Blob::operator<( const Bu::Blob &rRhs ) const 256bool Bu::Blob::operator<( const Bu::Blob &rRhs ) const
@@ -342,7 +347,7 @@ bool Bu::Blob::operator>( const char *pRhs ) const
342 return pData[j] > pRhs[j]; 347 return pData[j] > pRhs[j];
343 } 348 }
344 349
345 if( pRhs[iSize] == '\0' && iSize-1 > j ) 350 if( pRhs[j] == '\0' && iSize-1 > j )
346 return true; 351 return true;
347 352
348 return false; 353 return false;
@@ -367,13 +372,14 @@ bool Bu::Blob::operator>=( const char *pRhs ) const
367 if( pData == pRhs ) 372 if( pData == pRhs )
368 return true; 373 return true;
369 374
370 for( int32_t j = 0; j < iSize && pRhs[j]; j++ ) 375 int32_t j;
376 for( j = 0; j < iSize && pRhs[j]; j++ )
371 { 377 {
372 if( pData[j] != pRhs[j] ) 378 if( pData[j] != pRhs[j] )
373 return pData[j] > pRhs[j]; 379 return pData[j] > pRhs[j];
374 } 380 }
375 381
376 if( pRhs[iSize] == '\0' ) 382 if( pRhs[j] == '\0' )
377 return true; 383 return true;
378 384
379 return true; 385 return true;