Beispiel #1
0
 /*
 val= 393220
 val= 1
 val= 3817105751 t=10982
  */
 public static void testAdler()
 {
     Console.WriteLine("Testing Adler32");
     Adler32 crc1 = new Adler32();
     crc1.Update(new byte[] { 1, 2 });
     Console.WriteLine("val= " + crc1.GetValue());
     if (crc1.GetValue() != 393220) throw new Exception("Bad Adler32!");
     crc1.Reset();
     Console.WriteLine("val= " + crc1.GetValue());
     if (crc1.GetValue() != 1) throw new Exception("Bad Adler32!!");
     Random r = new Random();
     byte[] all = new byte[2000 * 4];
     long t0 = Environment.TickCount;
     for (int n = 0; n < 2000; n++) {
         byte[] b = createBytes7(n < 50 ? n : n * n - 7);
         Adler32 crc = new Adler32();
         int offset = 0;
         while (offset < b.Length) {
             int len = r.Next(b.Length - offset) + 1;
             crc.Update(b, offset, len);
             offset += len;
         }
         long x = crc.GetValue();
         all[n * 4] = (byte)((x >> 24) & 0xff);
         all[n * 4 + 1] = (byte)((x >> 16) & 0xff);
         all[n * 4 + 2] = (byte)((x >> 8) & 0xff);
         all[n * 4 + 3] = (byte)((x ) & 0xff);
     }
     long t1 = Environment.TickCount;
     Adler32 a = new Adler32();
     a.Update(all);
     long v = a.GetValue();
     Console.WriteLine("val= " + v + " t=" + (t1 - t0));
     if (v != 3817105751) throw new Exception("Bad Adler32");// tested with Java CRC32
 }
Beispiel #2
0
 internal void InitCrctest()
 {
     this.crctest = new Adler32 ();
 }