File: checksum.java

package info (click to toggle)
mauve 20120103-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 28,504 kB
  • sloc: java: 250,155; sh: 2,834; xml: 208; makefile: 66
file content (94 lines) | stat: -rw-r--r-- 2,746 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Tags: JDK1.1

// Copyright (C) 2005 Mark J. Wielaard (mark@klomp.org)

// This file is part of Mauve.

// Mauve is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2, or (at your option)
// any later version.

// Mauve is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Mauve; see the file COPYING.  If not, write to
// Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
// Boston, MA 02110-1301 USA.

package gnu.testlet.java.util.zip.Adler32;

import gnu.testlet.Testlet;
import gnu.testlet.TestHarness;
import java.util.zip.*;

public class checksum implements Testlet
{
  // 1000, 6000, ..., 96000 arrays filled with value = (byte) index.
  private final long[] someMore = new long[] { 486795068L,
					       1525910894L,
					       3543032800L,
					       2483946130L,
					       4150712693L,
					       3878123687L,
					       3650897945L,
					       1682829244L,
					       1842395054L,
					       460416992L,
					       3287492690L,
					       479453429L,
					       3960773095L,
					       2008242969L,
					       4130540683L,
					       1021367854L,
					       4065361952L,
					       2081116754L,
					       4033606837L,
					       1162071911L };

  public void test(TestHarness harness)
  {
    byte[] bs;
    for (int i = 0; i < 20; i++)
      {
	int length = i * 5000 + 1000;
	bs = new byte[length];
	for (int j = 0; j < bs.length; j++)
	  bs[j] = (byte) j;
	test(harness, bs, someMore[i]);
      }
  }

  private void test(TestHarness harness, byte[] bs, long result)
  {
    Adler32 adler = new Adler32();
    harness.check(adler.getValue(), 1);
    adler.update(bs);
    harness.check(adler.getValue(), result);

    adler.reset();
    harness.check(adler.getValue(), 1);
    for (int i = 0; i < bs.length; i += 1000)
      adler.update(bs, i, 1000);
    harness.check(adler.getValue(), result);

    adler.reset();
    harness.check(adler.getValue(), 1);
    for (int i = 0; i < bs.length; i++)
      adler.update(bs[i]);
    harness.check(adler.getValue(), result);

    adler.reset();
    harness.check(adler.getValue(), 1);
    for (int i = 0; i < 250; i++)
      adler.update(bs[i]);
    for (int i = 250; i < bs.length - 250; i += 250)
      adler.update(bs, i, 250);
    for (int i = bs.length - 250; i < bs.length; i++)
      adler.update(bs[i]);
    harness.check(adler.getValue(), result);
  }
}