aboutsummaryrefslogtreecommitdiff
path: root/src/unit
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2010-05-26 19:31:52 +0000
committerMike Buland <eichlan@xagasoft.com>2010-05-26 19:31:52 +0000
commit5b68b0c6abd98fc99acd57a2c5c691468e7dcb97 (patch)
tree614376739d56bdf02e5e64caa431641c112cf17f /src/unit
parent9052520ba21c824d526f67518c66a1c32c6a2f24 (diff)
downloadlibbu++-5b68b0c6abd98fc99acd57a2c5c691468e7dcb97.tar.gz
libbu++-5b68b0c6abd98fc99acd57a2c5c691468e7dcb97.tar.bz2
libbu++-5b68b0c6abd98fc99acd57a2c5c691468e7dcb97.tar.xz
libbu++-5b68b0c6abd98fc99acd57a2c5c691468e7dcb97.zip
Oooh, another minor myriad fix, it's getting solid now. :)
Diffstat (limited to '')
-rw-r--r--src/unit/myriad.unit60
1 files changed, 55 insertions, 5 deletions
diff --git a/src/unit/myriad.unit b/src/unit/myriad.unit
index d27c0dc..a88650f 100644
--- a/src/unit/myriad.unit
+++ b/src/unit/myriad.unit
@@ -25,8 +25,7 @@ suite Myriad
25 FString sFileName("myriad-XXXXXXX"); 25 FString sFileName("myriad-XXXXXXX");
26 26
27 File fMyriad = tempFile( sFileName ); 27 File fMyriad = tempFile( sFileName );
28 Myriad m( fMyriad ); 28 Myriad m( fMyriad, 32 );
29 m.initialize( 64 );
30 29
31 MyriadStream ms = m.openStream( m.createStream() ); 30 MyriadStream ms = m.openStream( m.createStream() );
32 ms.setSize( 150 ); 31 ms.setSize( 150 );
@@ -54,7 +53,21 @@ suite Myriad
54 { 53 {
55 buf[j] = (j+iSize)%256; 54 buf[j] = (j+iSize)%256;
56 } 55 }
57 s.write( buf, iSize-8 ); 56 if( random()%2 == 0 )
57 {
58 s.write( buf, iSize-8 );
59 }
60 else
61 {
62 for( int j = 0; j < iSize-8; )
63 {
64 int iAmnt = (random()%8)+1;
65 if( iAmnt+j > iSize-8 )
66 iAmnt = iSize-8-j;
67 iAmnt = s.write( buf+j, iAmnt );
68 j += iAmnt;
69 }
70 }
58 delete[] buf; 71 delete[] buf;
59 iSize = ~iSize; 72 iSize = ~iSize;
60 s.write( &iSize, 4 ); 73 s.write( &iSize, 4 );
@@ -79,7 +92,8 @@ suite Myriad
79 { 92 {
80 char b = buf[j]; 93 char b = buf[j];
81 delete[] buf; 94 delete[] buf;
82 throw ExceptionBase("Block failed computed data verify (%02X==%02X).", b, (char)((j+iSize)%256) ); 95 throw ExceptionBase("Block failed computed data verify "
96 "(%02X==%02X).", b, (char)((j+iSize)%256) );
83 } 97 }
84 } 98 }
85 delete[] buf; 99 delete[] buf;
@@ -164,7 +178,7 @@ suite Myriad
164 178
165 File fMyriad = tempFile( sFileName ); 179 File fMyriad = tempFile( sFileName );
166 Myriad m( fMyriad ); 180 Myriad m( fMyriad );
167 m.initialize( 64 ); 181 m.initialize( 128 );
168 182
169 Array<int> aStream; 183 Array<int> aStream;
170 184
@@ -190,5 +204,41 @@ suite Myriad
190 } 204 }
191 } 205 }
192 } 206 }
207
208 test stressTruncate2
209 {
210 FString sFileName("myriad-XXXXXXX");
211
212 Array<int> aStream;
213
214 {
215 File fMyriad = tempFile( sFileName );
216 Myriad m( fMyriad, 64 );
217
218 for( int j = 0; j < 5; j++ )
219 {
220 aStream.append( m.createStream() );
221 }
222 }
223
224 srandom( 1024 );
225
226 char b;
227 for( int iter = 0; iter < 2500; iter++ )
228 {
229 File fMyriad( sFileName, File::ReadWrite );
230 Myriad m( fMyriad );
231 for( Array<int>::iterator i = aStream.begin(); i; i++ )
232 {
233 MyriadStream ms = m.openStream( *i );
234 addBlock( ms, false );
235 ms.setSize( ms.tell() );
236 unitTest( ms.read( &b, 1 ) == 0 );
237 ms.setPos( 0 );
238 verifyBlock( ms );
239 unitTest( ms.read( &b, 1 ) == 0 );
240 }
241 }
242 }
193} 243}
194 244