66using StringDB . IO . Compatibility ;
77
88using System ;
9+ using System . Collections . Generic ;
910using System . IO ;
1011using System . Linq ;
1112using System . Text ;
@@ -16,10 +17,49 @@ namespace StringDB.Tests
1617{
1718 public static class StringDB10_0_0Tests
1819 {
20+ public class IntegrationTests
21+ {
22+ [ Fact ]
23+ public void IntegrationTest ( )
24+ {
25+ if ( File . Exists ( "stringdb.db" ) )
26+ File . Delete ( "stringdb.db" ) ;
27+
28+ using ( var db = StringDatabase . Create ( File . Open ( "stringdb.db" , FileMode . OpenOrCreate ) ) )
29+ {
30+ db . Insert ( "test" , "value" ) ;
31+ db . Insert ( "test" , "value2" ) ;
32+ db . Insert ( "test" , "value3" ) ;
33+
34+ db . EnumerateAggressively ( 3 )
35+ . Should ( ) . BeEquivalentTo ( new [ ]
36+ {
37+ new KeyValuePair < string , string > ( "test" , "value" ) ,
38+ new KeyValuePair < string , string > ( "test" , "value2" ) ,
39+ new KeyValuePair < string , string > ( "test" , "value3" ) ,
40+ } ) ;
41+ }
42+
43+ using ( var db = StringDatabase . Create ( File . Open ( "stringdb.db" , FileMode . OpenOrCreate ) ) )
44+ {
45+ db . Insert ( "test" , "value4" ) ;
46+
47+ db . EnumerateAggressively ( 3 )
48+ . Should ( ) . BeEquivalentTo ( new [ ]
49+ {
50+ new KeyValuePair < string , string > ( "test" , "value" ) ,
51+ new KeyValuePair < string , string > ( "test" , "value2" ) ,
52+ new KeyValuePair < string , string > ( "test" , "value3" ) ,
53+ new KeyValuePair < string , string > ( "test" , "value4" )
54+ } ) ;
55+ }
56+ }
57+ }
58+
1959 public static ( MemoryStream ms , StringDB10_0_0LowlevelDatabaseIODevice io ) Generate ( )
2060 {
2161 var ms = new MemoryStream ( ) ;
22- var io = new StringDB10_0_0LowlevelDatabaseIODevice ( ms ) ;
62+ var io = new StringDB10_0_0LowlevelDatabaseIODevice ( ms , true ) ;
2363
2464 return ( ms , io ) ;
2565 }
@@ -57,7 +97,7 @@ public void TooLargeJumpRead()
5797 {
5898 var ( ms , io ) = Generate ( ) ;
5999
60- Action throws = ( ) => io . WriteJump ( 0xDEAD_BEEF ) ;
100+ Action throws = ( ) => io . WriteJump ( 0xDEAD_BEEF_5 ) ;
61101
62102 throws . Should ( )
63103 . ThrowExactly < ArgumentException > ( ) ;
@@ -73,6 +113,20 @@ public void AtEOF()
73113 throws . Should ( )
74114 . ThrowExactly < NotSupportedException > ( ) ;
75115 }
116+
117+ [ Fact ]
118+ public void ReadingVeryLargeVariableInt ( )
119+ {
120+ var ( ms , io ) = Generate ( ) ;
121+
122+ Action throws = ( ) => io . ReadValue ( 8 ) ;
123+
124+ io . Reset ( ) ;
125+ ms . Write ( new byte [ ] { 0xFF , 0xFF , 0xFF , 0xFF , 0b0_1111111 , 0x00 } ) ;
126+
127+ throws . Should ( )
128+ . ThrowExactly < NotSupportedException > ( ) ;
129+ }
76130 }
77131
78132 public static class Write
@@ -204,6 +258,22 @@ public void JumpShortened()
204258 . Should ( )
205259 . Be ( 1337 - pos ) ;
206260 }
261+
262+ [ Fact ]
263+ public void WritesJumpPosition ( )
264+ {
265+ var ( ms , io ) = Generate ( ) ;
266+
267+ io . JumpPos = 0xDEADBEEF5 ;
268+
269+ io . Dispose ( ) ;
270+
271+ ms . Position = 0 ;
272+ var jumpPos = new byte [ 8 ] ;
273+ ms . Read ( jumpPos , 0 , jumpPos . Length ) ;
274+
275+ jumpPos . Should ( ) . BeEquivalentTo ( BitConverter . GetBytes ( ( long ) 0xDEADBEEF5 ) ) ;
276+ }
207277 }
208278 }
209279
0 commit comments