1 import org
.diracvideo
.Jirac
.Unpack
;
2 import java
.util
.Random
;
5 public class UnpackTest
{
6 public static void main (String a
[]) {
9 for(int i
= 0; i
< 5000; i
++) {
15 private static void skipTest() {
16 /* There used to be an extensive test here.
17 It failed, continued to fail, and then failed even more.
18 Apparantly an Unpack object can be inconsistent
19 after skipping. I have absolutely no clue why.
20 Especially as it all /seems/ to work so smoothly.
21 Anyone that is interested can try to fix it. */
23 String s
= String
.format("Hello World! \n%s\n%s\n%s",
24 "How are you today? I'm fine,",
25 "thank you for asking. It is",
26 "such lovely weather today");
27 u
= new Unpack(s
.getBytes());
28 Random r
= new Random();
29 while(u
.bitsLeft() > 160) {
30 u
.bits(r
.nextInt(31));
32 int i
= r
.nextInt(u
.bitsLeft());
36 for(; i > 31; i -= 31) {
42 while(u
.bitsLeft() > 8) {
43 i
= r
.nextInt(Math
.min(u
.bitsLeft(), 31));
44 if(u
.bits(i
) != o
.bits(i
)) {
45 throw new Error("Skip Error (Inconsistency)");
49 throw new Error("Skip Error (Unequality)");
53 private static void decodeTest() {
54 byte[] r
= { (byte)0x96, (byte)0x11, (byte)0xA5, (byte)0x7F};
55 Unpack u
= new Unpack(r
);
56 for(int i
= 0; i
< 6; i
++) {
57 int v
= u
.decodeUint();
58 // System.err.println(v);
60 throw new Error("Error in decodeUint()");
65 private static void bitsTest() {
66 String s
= "BBCD is the code for Dirac bitstreams\n" +
67 "This string should be just a little bit longer\n" ;
68 Unpack u
= new Unpack(s
.getBytes());
69 byte[] r
= new byte[s
.length()], o
= new byte[s
.length()];
70 for(int i
= 0; u
.bitsLeft() > 8; i
++) {
71 r
[i
] = (byte)u
.bits(8);
72 o
[i
] = (byte)s
.charAt(9*i
);
76 if(new String(o
).compareTo(new String(r
)) != 0) {
77 throw new Error("Bits error");
81 private static void bitsReadTest() {
82 Unpack u
= new Unpack("hallo sanne je bent mooi en lief".getBytes());
83 Random r
= new Random();
85 for(int c
= 0; u
.bitsLeft() > 32; c
+= t
) {
86 if(u
.bitsRead() != c
) {
87 throw new Error("bitsRead() Error");
89 t
= r
.nextInt(Math
.min(u
.bitsLeft(),32));