From 286dc953c1e0e4a75589e4068e29a317a03f23dd Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 25 May 2010 05:42:26 +0000 Subject: More myriad tests and features, passes perfectly so far. --- src/unit/myriad.unit | 64 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 60 insertions(+), 4 deletions(-) (limited to 'src/unit') diff --git a/src/unit/myriad.unit b/src/unit/myriad.unit index ed121cc..d27c0dc 100644 --- a/src/unit/myriad.unit +++ b/src/unit/myriad.unit @@ -20,9 +20,33 @@ using namespace Bu; suite Myriad { - void addBlock( Stream &s ) + test setSize { - s.setPosEnd( 0 ); + FString sFileName("myriad-XXXXXXX"); + + File fMyriad = tempFile( sFileName ); + Myriad m( fMyriad ); + m.initialize( 64 ); + + MyriadStream ms = m.openStream( m.createStream() ); + ms.setSize( 150 ); + ms.setPos( 145 ); + char stuff[10]; + unitTest( ms.read( stuff, 10 ) == 5 ); + + ms.setSize( 12 ); + unitTest( ms.read( stuff, 10 ) == 0 ); + unitTest( ms.write( "hello", 5 ) == 5 ); + unitTest( ms.tell() == 17 ); + + ms.setSize( 500 ); + unitTest( ms.tell() == 17 ); + } + + void addBlock( Stream &s, bool bAppend=true ) + { + if( bAppend ) + s.setPosEnd( 0 ); int iSize = (random()%1016)+8; s.write( &iSize, 4 ); char *buf = new char[iSize-8]; @@ -72,7 +96,7 @@ suite Myriad verifyBlock( s ); } - test grow1 + test stressGrow { FString sFileName("myriad-XXXXXXX"); @@ -90,7 +114,6 @@ suite Myriad for( int j = 0; j < 2500; j++ ) { - switch( random()%5 ) { case 0: @@ -134,5 +157,38 @@ suite Myriad verifyStream( ms ); } } + + test stressTruncate + { + FString sFileName("myriad-XXXXXXX"); + + File fMyriad = tempFile( sFileName ); + Myriad m( fMyriad ); + m.initialize( 64 ); + + Array aStream; + + for( int j = 0; j < 5; j++ ) + { + aStream.append( m.createStream() ); + } + + srandom( 1024 ); + + char b; + for( int iter = 0; iter < 2500; iter++ ) + { + for( Array::iterator i = aStream.begin(); i; i++ ) + { + MyriadStream ms = m.openStream( *i ); + addBlock( ms, false ); + ms.setSize( ms.tell() ); + unitTest( ms.read( &b, 1 ) == 0 ); + ms.setPos( 0 ); + verifyBlock( ms ); + unitTest( ms.read( &b, 1 ) == 0 ); + } + } + } } -- cgit v1.2.3