FileDocCategorySizeDatePackage
ChecksumTest.javaAPI DocAndroid 1.5 API3094Wed May 06 22:42:02 BST 2009android.core

ChecksumTest

public class ChecksumTest extends TestCase
tests for CRC32 and Adler32 checksum algorithms.

Fields Summary
private static byte[]
mTestString
Constructors Summary
Methods Summary
private voidadler32Test(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 voidcRC32Test(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 voidtestChecksum()

        /*
         * Values computed experimentally, using C interfaces.
         */
        adler32Test(mTestString, 0x9de210dbL);
        cRC32Test(mTestString, 0x939f04afL);

        // Test for issue 1016037
        wrongChecksumWithAdler32Test();
    
private voidwrongChecksumWithAdler32Test()



    // 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());