diff options
Diffstat (limited to 'src/unit')
-rw-r--r-- | src/unit/myriad.unit | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/src/unit/myriad.unit b/src/unit/myriad.unit index 24d3116..f7bea97 100644 --- a/src/unit/myriad.unit +++ b/src/unit/myriad.unit | |||
@@ -109,7 +109,7 @@ suite Myriad | |||
109 | File fMyriad = tempFile( sFileName ); | 109 | File fMyriad = tempFile( sFileName ); |
110 | Myriad m( fMyriad, 32 ); | 110 | Myriad m( fMyriad, 32 ); |
111 | 111 | ||
112 | MyriadStream ms = m.openStream( m.createStream() ); | 112 | MyriadStream ms = m.create( Myriad::ReadWrite ); |
113 | ms.setSize( 150 ); | 113 | ms.setSize( 150 ); |
114 | ms.setPos( 145 ); | 114 | ms.setPos( 145 ); |
115 | char stuff[10]; | 115 | char stuff[10]; |
@@ -163,7 +163,7 @@ suite Myriad | |||
163 | if( iSize < 8 || iSize > 1024 ) | 163 | if( iSize < 8 || iSize > 1024 ) |
164 | throw ExceptionBase("Read bad data, %d", iSize ); | 164 | throw ExceptionBase("Read bad data, %d", iSize ); |
165 | char *buf = new char[iSize-8]; | 165 | char *buf = new char[iSize-8]; |
166 | if( s.read( buf, iSize-8 ) < (size_t)iSize-8 ) | 166 | if( s.read( buf, iSize-8 ) < (Bu::size)iSize-8 ) |
167 | { | 167 | { |
168 | delete[] buf; | 168 | delete[] buf; |
169 | throw ExceptionBase("Block failed verify (insuffient block data)."); | 169 | throw ExceptionBase("Block failed verify (insuffient block data)."); |
@@ -197,13 +197,12 @@ suite Myriad | |||
197 | String sFileName("myriad-XXXXXXX"); | 197 | String sFileName("myriad-XXXXXXX"); |
198 | 198 | ||
199 | File fMyriad = tempFile( sFileName ); | 199 | File fMyriad = tempFile( sFileName ); |
200 | Myriad m( fMyriad ); | 200 | Myriad m( fMyriad, 64 ); |
201 | m.initialize( 64 ); | ||
202 | 201 | ||
203 | Array<int> aStreams; | 202 | Array<int> aStreams; |
204 | for( int j = 0; j < 5; j++ ) | 203 | for( int j = 0; j < 5; j++ ) |
205 | { | 204 | { |
206 | aStreams.append( m.createStream() ); | 205 | aStreams.append( m.create( Bu::Myriad::Read ).getId() ); |
207 | } | 206 | } |
208 | 207 | ||
209 | srandom( 512 ); | 208 | srandom( 512 ); |
@@ -213,7 +212,7 @@ suite Myriad | |||
213 | switch( random()%5 ) | 212 | switch( random()%5 ) |
214 | { | 213 | { |
215 | case 0: | 214 | case 0: |
216 | aStreams.append( m.createStream() ); | 215 | aStreams.append( m.create( Bu::Myriad::Read ).getId() ); |
217 | break; | 216 | break; |
218 | 217 | ||
219 | case 1: | 218 | case 1: |
@@ -221,10 +220,10 @@ suite Myriad | |||
221 | { | 220 | { |
222 | int iStream = random()%aStreams.getSize(); | 221 | int iStream = random()%aStreams.getSize(); |
223 | { | 222 | { |
224 | MyriadStream ms = m.openStream( aStreams[iStream] ); | 223 | MyriadStream ms = m.open( aStreams[iStream], Myriad::Read ); |
225 | verifyStream( ms ); | 224 | verifyStream( ms ); |
226 | } | 225 | } |
227 | m.deleteStream( aStreams[iStream] ); | 226 | m.erase( aStreams[iStream] ); |
228 | Array<int>::iterator i = aStreams.begin(); | 227 | Array<int>::iterator i = aStreams.begin(); |
229 | for( int k = 0; k < iStream; k++ ) | 228 | for( int k = 0; k < iStream; k++ ) |
230 | i++; | 229 | i++; |
@@ -235,11 +234,13 @@ suite Myriad | |||
235 | default: | 234 | default: |
236 | if( aStreams.getSize() == 0 ) | 235 | if( aStreams.getSize() == 0 ) |
237 | { | 236 | { |
238 | aStreams.append( m.createStream() ); | 237 | aStreams.append( |
238 | m.create( Bu::Myriad::Read ).getId() | ||
239 | ); | ||
239 | } | 240 | } |
240 | { | 241 | { |
241 | int iStream = random()%aStreams.getSize(); | 242 | int iStream = random()%aStreams.getSize(); |
242 | MyriadStream ms = m.openStream( aStreams[iStream] ); | 243 | MyriadStream ms = m.open( aStreams[iStream], Myriad::ReadWrite ); |
243 | addBlock( ms ); | 244 | addBlock( ms ); |
244 | verifyStream( ms ); | 245 | verifyStream( ms ); |
245 | } | 246 | } |
@@ -249,7 +250,7 @@ suite Myriad | |||
249 | 250 | ||
250 | for( Array<int>::iterator i = aStreams.begin(); i; i++ ) | 251 | for( Array<int>::iterator i = aStreams.begin(); i; i++ ) |
251 | { | 252 | { |
252 | MyriadStream ms = m.openStream( *i ); | 253 | MyriadStream ms = m.open( *i, Myriad::Read ); |
253 | verifyStream( ms ); | 254 | verifyStream( ms ); |
254 | } | 255 | } |
255 | } | 256 | } |
@@ -259,14 +260,13 @@ suite Myriad | |||
259 | String sFileName("myriad-XXXXXXX"); | 260 | String sFileName("myriad-XXXXXXX"); |
260 | 261 | ||
261 | File fMyriad = tempFile( sFileName ); | 262 | File fMyriad = tempFile( sFileName ); |
262 | Myriad m( fMyriad ); | 263 | Myriad m( fMyriad, 128 ); |
263 | m.initialize( 128 ); | ||
264 | 264 | ||
265 | Array<int> aStream; | 265 | Array<int> aStream; |
266 | 266 | ||
267 | for( int j = 0; j < 5; j++ ) | 267 | for( int j = 0; j < 5; j++ ) |
268 | { | 268 | { |
269 | aStream.append( m.createStream() ); | 269 | aStream.append( m.create( Bu::Myriad::Read ).getId() ); |
270 | } | 270 | } |
271 | 271 | ||
272 | srandom( 1024 ); | 272 | srandom( 1024 ); |
@@ -276,7 +276,7 @@ suite Myriad | |||
276 | { | 276 | { |
277 | for( Array<int>::iterator i = aStream.begin(); i; i++ ) | 277 | for( Array<int>::iterator i = aStream.begin(); i; i++ ) |
278 | { | 278 | { |
279 | MyriadStream ms = m.openStream( *i ); | 279 | MyriadStream ms = m.open( *i, Myriad::ReadWrite ); |
280 | addBlock( ms, false ); | 280 | addBlock( ms, false ); |
281 | ms.setSize( ms.tell() ); | 281 | ms.setSize( ms.tell() ); |
282 | unitTest( ms.read( &b, 1 ) == 0 ); | 282 | unitTest( ms.read( &b, 1 ) == 0 ); |
@@ -301,7 +301,7 @@ suite Myriad | |||
301 | 301 | ||
302 | for( int j = 0; j < 5; j++ ) | 302 | for( int j = 0; j < 5; j++ ) |
303 | { | 303 | { |
304 | aStream.append( m.createStream() ); | 304 | aStream.append( m.create( Bu::Myriad::Read ).getId() ); |
305 | incProgress(); | 305 | incProgress(); |
306 | } | 306 | } |
307 | } | 307 | } |
@@ -315,7 +315,7 @@ suite Myriad | |||
315 | Myriad m( fMyriad ); | 315 | Myriad m( fMyriad ); |
316 | for( Array<int>::iterator i = aStream.begin(); i; i++ ) | 316 | for( Array<int>::iterator i = aStream.begin(); i; i++ ) |
317 | { | 317 | { |
318 | MyriadStream ms = m.openStream( *i ); | 318 | MyriadStream ms = m.open( *i, Myriad::ReadWrite ); |
319 | addBlock( ms, false ); | 319 | addBlock( ms, false ); |
320 | ms.setSize( ms.tell() ); | 320 | ms.setSize( ms.tell() ); |
321 | unitTest( ms.read( &b, 1 ) == 0 ); | 321 | unitTest( ms.read( &b, 1 ) == 0 ); |
@@ -342,17 +342,17 @@ suite Myriad | |||
342 | 342 | ||
343 | for( int j = 0; j < 15; j++ ) | 343 | for( int j = 0; j < 15; j++ ) |
344 | { | 344 | { |
345 | int iStream = m.createStream(); | 345 | MyriadStream ms = m.create( Myriad::Write ); |
346 | int iStream = ms.getId(); | ||
346 | aStream.append( iStream ); | 347 | aStream.append( iStream ); |
347 | VerifyObject vo( random()%1024 ); | 348 | VerifyObject vo( random()%1024 ); |
348 | { | 349 | { |
349 | MyriadStream ms = m.openStream( iStream ); | ||
350 | Archive ar( ms, Archive::save ); | 350 | Archive ar( ms, Archive::save ); |
351 | ar << vo; | 351 | ar << vo; |
352 | unitTest( ms.tell() == vo.getBytesWritten() ); | 352 | unitTest( ms.tell() == vo.getBytesWritten() ); |
353 | ms.setSize( ms.tell() ); | 353 | ms.setSize( ms.tell() ); |
354 | } | 354 | } |
355 | unitTest( m.getStreamSize( iStream ) == vo.getBytesWritten() ); | 355 | unitTest( m.getSize( iStream ) == vo.getBytesWritten() ); |
356 | incProgress(); | 356 | incProgress(); |
357 | } | 357 | } |
358 | } | 358 | } |
@@ -365,18 +365,18 @@ suite Myriad | |||
365 | { | 365 | { |
366 | VerifyObject vo( random()%1024 ); | 366 | VerifyObject vo( random()%1024 ); |
367 | { | 367 | { |
368 | MyriadStream ms = m.openStream( *i ); | 368 | MyriadStream ms = m.open( *i, Myriad::Read ); |
369 | Archive ar( ms, Archive::load ); | 369 | Archive ar( ms, Archive::load ); |
370 | ar >> vo; | 370 | ar >> vo; |
371 | } | 371 | } |
372 | { | 372 | { |
373 | MyriadStream ms = m.openStream( *i ); | 373 | MyriadStream ms = m.open( *i, Myriad::WriteNew ); |
374 | Archive ar( ms, Archive::save ); | 374 | Archive ar( ms, Archive::save ); |
375 | ar << vo; | 375 | ar << vo; |
376 | unitTest( ms.tell() == vo.getBytesWritten() ); | 376 | unitTest( ms.tell() == vo.getBytesWritten() ); |
377 | ms.setSize( ms.tell() ); | 377 | ms.setSize( ms.tell() ); |
378 | } | 378 | } |
379 | unitTest( m.getStreamSize( *i ) == vo.getBytesWritten() ); | 379 | unitTest( m.getSize( *i ) == vo.getBytesWritten() ); |
380 | incProgress(); | 380 | incProgress(); |
381 | } | 381 | } |
382 | } | 382 | } |