ChecksumTestpublic class ChecksumTest extends TestCase tests for CRC32 and Adler32 checksum algorithms. |
Fields Summary |
---|
private static byte[] | mTestString |
Methods Summary |
---|
private void | adler32Test(byte[] values, long expected)
Adler32 adler = new Adler32();
// try it all at once
adler.update(values);
assertEquals(adler.getValue(), expected);
// try resetting and computing one byte at a time
adler.reset();
for (int i = 0; i < values.length; i++) {
adler.update(values[i]);
}
assertEquals(adler.getValue(), expected);
| private void | cRC32Test(byte[] values, long expected)
CRC32 crc = new CRC32();
// try it all at once
crc.update(values);
assertEquals(crc.getValue(), expected);
// try resetting and computing one byte at a time
crc.reset();
for (int i = 0; i < values.length; i++) {
crc.update(values[i]);
}
assertEquals(crc.getValue(), expected);
| public void | testChecksum()
/*
* Values computed experimentally, using C interfaces.
*/
adler32Test(mTestString, 0x9de210dbL);
cRC32Test(mTestString, 0x939f04afL);
// Test for issue 1016037
wrongChecksumWithAdler32Test();
| private void | wrongChecksumWithAdler32Test()
// Test for issue 1016037
byte[] bytes = {1, 0, 5, 0, 15, 0, 1, 11, 0, 1};
Adler32 adler = new Adler32();
adler.update(bytes);
long arrayChecksum = adler.getValue();
adler.reset();
for (int i = 0; i < bytes.length; i++) {
adler.update(bytes[i]);
}
assertEquals("Checksums not equal: expected: " + arrayChecksum +
" actual: " + adler.getValue(), arrayChecksum, adler.getValue());
|
|