tests/libjava-mauve/src/gnu/testlet/java/util/zip/Adler32/checksum.java
branchjk_new_structure
changeset 1541 75c2e24dea9a
parent 1540 92ac284961c1
child 1542 be11db817bcf
equal deleted inserted replaced
1540:92ac284961c1 1541:75c2e24dea9a
     1 // Tags: JDK1.1
       
     2 
       
     3 // Copyright (C) 2005 Mark J. Wielaard (mark@klomp.org)
       
     4 
       
     5 // This file is part of Mauve.
       
     6 
       
     7 // Mauve is free software; you can redistribute it and/or modify
       
     8 // it under the terms of the GNU General Public License as published by
       
     9 // the Free Software Foundation; either version 2, or (at your option)
       
    10 // any later version.
       
    11 
       
    12 // Mauve is distributed in the hope that it will be useful,
       
    13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    15 // GNU General Public License for more details.
       
    16 
       
    17 // You should have received a copy of the GNU General Public License
       
    18 // along with Mauve; see the file COPYING.  If not, write to
       
    19 // Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
       
    20 // Boston, MA 02110-1301 USA.
       
    21 
       
    22 package gnu.testlet.java.util.zip.Adler32;
       
    23 
       
    24 import gnu.testlet.Testlet;
       
    25 import gnu.testlet.TestHarness;
       
    26 import java.util.zip.*;
       
    27 
       
    28 public class checksum implements Testlet
       
    29 {
       
    30   // 1000, 6000, ..., 96000 arrays filled with value = (byte) index.
       
    31   private final long[] someMore = new long[] { 486795068L,
       
    32 					       1525910894L,
       
    33 					       3543032800L,
       
    34 					       2483946130L,
       
    35 					       4150712693L,
       
    36 					       3878123687L,
       
    37 					       3650897945L,
       
    38 					       1682829244L,
       
    39 					       1842395054L,
       
    40 					       460416992L,
       
    41 					       3287492690L,
       
    42 					       479453429L,
       
    43 					       3960773095L,
       
    44 					       2008242969L,
       
    45 					       4130540683L,
       
    46 					       1021367854L,
       
    47 					       4065361952L,
       
    48 					       2081116754L,
       
    49 					       4033606837L,
       
    50 					       1162071911L };
       
    51 
       
    52   public void test(TestHarness harness)
       
    53   {
       
    54     byte[] bs;
       
    55     for (int i = 0; i < 20; i++)
       
    56       {
       
    57 	int length = i * 5000 + 1000;
       
    58 	bs = new byte[length];
       
    59 	for (int j = 0; j < bs.length; j++)
       
    60 	  bs[j] = (byte) j;
       
    61 	test(harness, bs, someMore[i]);
       
    62       }
       
    63   }
       
    64 
       
    65   private void test(TestHarness harness, byte[] bs, long result)
       
    66   {
       
    67     Adler32 adler = new Adler32();
       
    68     harness.check(adler.getValue(), 1);
       
    69     adler.update(bs);
       
    70     harness.check(adler.getValue(), result);
       
    71 
       
    72     adler.reset();
       
    73     harness.check(adler.getValue(), 1);
       
    74     for (int i = 0; i < bs.length; i += 1000)
       
    75       adler.update(bs, i, 1000);
       
    76     harness.check(adler.getValue(), result);
       
    77 
       
    78     adler.reset();
       
    79     harness.check(adler.getValue(), 1);
       
    80     for (int i = 0; i < bs.length; i++)
       
    81       adler.update(bs[i]);
       
    82     harness.check(adler.getValue(), result);
       
    83 
       
    84     adler.reset();
       
    85     harness.check(adler.getValue(), 1);
       
    86     for (int i = 0; i < 250; i++)
       
    87       adler.update(bs[i]);
       
    88     for (int i = 250; i < bs.length - 250; i += 250)
       
    89       adler.update(bs, i, 250);
       
    90     for (int i = bs.length - 250; i < bs.length; i++)
       
    91       adler.update(bs[i]);
       
    92     harness.check(adler.getValue(), result);
       
    93   }
       
    94 }