Code example for CRC32

Methods: getValue, reset, update

0
     */ 
    @TestTargetNew( 
        level = TestLevel.COMPLETE, 
        notes = "", 
        method = "CRC32", 
        args = {} 
    ) 
    public void test_Constructor() { 
        // test methods of java.util.zip.CRC32() 
        CRC32 crc = new CRC32();
        assertEquals("Constructor of CRC32 failed", 0, crc.getValue());
    } 
 
    /** 
     * @tests java.util.zip.CRC32#getValue() 
     */ 
    @TestTargetNew( 
        level = TestLevel.COMPLETE, 
        notes = "", 
        method = "getValue", 
        args = {} 
    ) 
    public void test_getValue() { 
        // test methods of java.util.zip.crc32.getValue() 
        CRC32 crc = new CRC32();
        assertEquals(
                "getValue() should return a zero as a result of constructing a CRC32 instance", 
                0, crc.getValue());
 
        crc.reset();
        crc.update(Integer.MAX_VALUE);
        // System.out.print("value of crc " + crc.getValue()); 
        // Ran JDK and discovered that the value of the CRC should be 
        // 4278190080 
        assertEquals(
                "update(max) failed to update the checksum to the correct value ", 
                4278190080L, crc.getValue());
 
        crc.reset();
        byte byteEmpty[] = new byte[10000];
        crc.update(byteEmpty);