1
1
package io .kaitai .struct .spec ;
2
2
3
+ import io .kaitai .struct .ArrayRegion ;
4
+ import io .kaitai .struct .PositionInfo ;
5
+ import io .kaitai .struct .Region ;
3
6
import io .kaitai .struct .testformats .Debug0 ;
4
7
import org .testng .annotations .Test ;
5
8
6
9
import java .util .ArrayList ;
7
10
import java .util .Arrays ;
8
11
9
12
import static org .testng .Assert .assertEquals ;
13
+ import static org .testng .Assert .assertFalse ;
14
+ import static org .testng .Assert .assertTrue ;
10
15
11
16
public class TestDebug0 extends CommonSpec {
12
17
@ Test
@@ -19,12 +24,30 @@ public void testDebug0() throws Exception {
19
24
20
25
assertEquals (Debug0 ._seqFields , new String [] { "one" , "arrayOfInts" , "_unnamed2" });
21
26
22
- assertEquals (r ._attrStart .get ("one" ).intValue (), 0 );
23
- assertEquals (r ._attrEnd .get ("one" ).intValue (), 1 );
24
- assertEquals (r ._attrStart .get ("arrayOfInts" ).intValue (), 1 );
25
- assertEquals (r ._attrEnd .get ("arrayOfInts" ).intValue (), 4 );
27
+ assertTrue (r instanceof PositionInfo , "Structure in debug mode should implement PositionInfo" );
28
+ assertEquals (r ._regions ().size (), 3 , "Position information should exists for each field" );
26
29
27
- assertEquals (r ._arrStart .get ("arrayOfInts" ).toArray (), new Integer [] { 1 , 2 , 3 });
28
- assertEquals (r ._arrEnd .get ("arrayOfInts" ).toArray (), new Integer [] { 2 , 3 , 4 });
30
+ final Region oneRegion = r ._regions ().get ("one" );
31
+ assertFalse (oneRegion instanceof ArrayRegion , "Non-Array region shouldn't be instanceof ArrayRegion" );
32
+ assertEquals (oneRegion .start , 0 );
33
+ assertEquals (oneRegion .end , 1 );
34
+
35
+ final Region arrayRegion = r ._regions ().get ("arrayOfInts" );
36
+ assertEquals (arrayRegion .start , 1 );
37
+ assertEquals (arrayRegion .end , 4 );
38
+
39
+ assertTrue (arrayRegion instanceof ArrayRegion , "Array region should be instanceof ArrayRegion" );
40
+
41
+ final ArrayRegion array = (ArrayRegion )arrayRegion ;
42
+ assertEquals (array .items .size (), 3 );
43
+
44
+ final long [] starts = { 1 , 2 , 3 };
45
+ final long [] ends = { 2 , 3 , 4 };
46
+ int i = 0 ;
47
+ for (final Region region : array .items ) {
48
+ assertEquals (region .start , starts [i ]);
49
+ assertEquals (region .end , ends [i ]);
50
+ ++i ;
51
+ }
29
52
}
30
53
}
0 commit comments