summaryrefslogtreecommitdiff
path: root/src/unit
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2010-05-25 05:42:26 +0000
committerMike Buland <eichlan@xagasoft.com>2010-05-25 05:42:26 +0000
commit286dc953c1e0e4a75589e4068e29a317a03f23dd (patch)
tree2144b0e7847222b0c6b8f6e87d8a5118e85e8b66 /src/unit
parenta0c6e974a3393642bda80fed5bce464a6c6cf2ec (diff)
downloadlibbu++-286dc953c1e0e4a75589e4068e29a317a03f23dd.tar.gz
libbu++-286dc953c1e0e4a75589e4068e29a317a03f23dd.tar.bz2
libbu++-286dc953c1e0e4a75589e4068e29a317a03f23dd.tar.xz
libbu++-286dc953c1e0e4a75589e4068e29a317a03f23dd.zip
More myriad tests and features, passes perfectly so far.
Diffstat (limited to 'src/unit')
-rw-r--r--src/unit/myriad.unit64
1 files changed, 60 insertions, 4 deletions
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;
20 20
21suite Myriad 21suite Myriad
22{ 22{
23 void addBlock( Stream &s ) 23 test setSize
24 { 24 {
25 s.setPosEnd( 0 ); 25 FString sFileName("myriad-XXXXXXX");
26
27 File fMyriad = tempFile( sFileName );
28 Myriad m( fMyriad );
29 m.initialize( 64 );
30
31 MyriadStream ms = m.openStream( m.createStream() );
32 ms.setSize( 150 );
33 ms.setPos( 145 );
34 char stuff[10];
35 unitTest( ms.read( stuff, 10 ) == 5 );
36
37 ms.setSize( 12 );
38 unitTest( ms.read( stuff, 10 ) == 0 );
39 unitTest( ms.write( "hello", 5 ) == 5 );
40 unitTest( ms.tell() == 17 );
41
42 ms.setSize( 500 );
43 unitTest( ms.tell() == 17 );
44 }
45
46 void addBlock( Stream &s, bool bAppend=true )
47 {
48 if( bAppend )
49 s.setPosEnd( 0 );
26 int iSize = (random()%1016)+8; 50 int iSize = (random()%1016)+8;
27 s.write( &iSize, 4 ); 51 s.write( &iSize, 4 );
28 char *buf = new char[iSize-8]; 52 char *buf = new char[iSize-8];
@@ -72,7 +96,7 @@ suite Myriad
72 verifyBlock( s ); 96 verifyBlock( s );
73 } 97 }
74 98
75 test grow1 99 test stressGrow
76 { 100 {
77 FString sFileName("myriad-XXXXXXX"); 101 FString sFileName("myriad-XXXXXXX");
78 102
@@ -90,7 +114,6 @@ suite Myriad
90 114
91 for( int j = 0; j < 2500; j++ ) 115 for( int j = 0; j < 2500; j++ )
92 { 116 {
93
94 switch( random()%5 ) 117 switch( random()%5 )
95 { 118 {
96 case 0: 119 case 0:
@@ -134,5 +157,38 @@ suite Myriad
134 verifyStream( ms ); 157 verifyStream( ms );
135 } 158 }
136 } 159 }
160
161 test stressTruncate
162 {
163 FString sFileName("myriad-XXXXXXX");
164
165 File fMyriad = tempFile( sFileName );
166 Myriad m( fMyriad );
167 m.initialize( 64 );
168
169 Array<int> aStream;
170
171 for( int j = 0; j < 5; j++ )
172 {
173 aStream.append( m.createStream() );
174 }
175
176 srandom( 1024 );
177
178 char b;
179 for( int iter = 0; iter < 2500; iter++ )
180 {
181 for( Array<int>::iterator i = aStream.begin(); i; i++ )
182 {
183 MyriadStream ms = m.openStream( *i );
184 addBlock( ms, false );
185 ms.setSize( ms.tell() );
186 unitTest( ms.read( &b, 1 ) == 0 );
187 ms.setPos( 0 );
188 verifyBlock( ms );
189 unitTest( ms.read( &b, 1 ) == 0 );
190 }
191 }
192 }
137} 193}
138 194