public void testDescending() { // Test 32 byte arrays of descending. byte[] descending = new byte[32]; for (int i = 0; i < 32; i++) { descending[i] = (byte) (31 - i); } assertCrc(0x113fdb5c, descending); }
public void testCrc32cLookupTable() { // See Hacker's Delight 2nd Edition, Figure 14-7. int[] expected = new int[256]; for (int i = 0; i < expected.length; i++) { int crc = i; for (int j = 7; j >= 0; j--) { int mask = -(crc & 1); crc = ((crc >>> 1) ^ (CRC32C_GENERATOR_FLIPPED & mask)); } expected[i] = crc; } int[] actual = Crc32cHashFunction.Crc32cHasher.CRC_TABLE; assertTrue( "Expected: \n" + Arrays.toString(expected) + "\nActual:\n" + Arrays.toString(actual), Arrays.equals(expected, actual)); } }
/** * Verifies that the crc of an array of byte data matches the expected value. * * @param expectedCrc the expected crc value. * @param data the data to run the checksum on. */ private static void assertCrc(int expectedCrc, byte[] data) { int actualCrc = Hashing.crc32c().hashBytes(data).asInt(); assertEquals(expectedCrc, actualCrc); }
/** * Verifies that the crc of an array of byte data matches the expected value. * * @param expectedCrc the expected crc value. * @param data the data to run the checksum on. */ private static void assertCrc(int expectedCrc, byte[] data) { int actualCrc = Hashing.crc32c().hashBytes(data).asInt(); assertEquals(expectedCrc, actualCrc); }
public void testAscending() { // Test 32 byte arrays of ascending. byte[] ascending = new byte[32]; for (int i = 0; i < 32; i++) { ascending[i] = (byte) i; } assertCrc(0x46dd794e, ascending); }
public void testCrc32cLookupTable() { // See Hacker's Delight 2nd Edition, Figure 14-7. int[] expected = new int[256]; for (int i = 0; i < expected.length; i++) { int crc = i; for (int j = 7; j >= 0; j--) { int mask = -(crc & 1); crc = ((crc >>> 1) ^ (CRC32C_GENERATOR_FLIPPED & mask)); } expected[i] = crc; } int[] actual = Crc32cHashFunction.Crc32cHasher.CRC_TABLE; assertTrue( "Expected: \n" + Arrays.toString(expected) + "\nActual:\n" + Arrays.toString(actual), Arrays.equals(expected, actual)); } }
public void testScsiReadCommand() { // Test SCSI read command. byte[] scsiReadCommand = new byte[] { 0x01, (byte) 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x18, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; assertCrc(0xd9963a56, scsiReadCommand); }
public void testFull() { // Test 32 byte array of 0xFF. byte[] fulls = new byte[32]; Arrays.fill(fulls, (byte) 0xFF); assertCrc(0x62a8ab43, fulls); }
public void testZeros() { // Test 32 byte array of 0x00. byte[] zeros = new byte[32]; Arrays.fill(zeros, (byte) 0x00); assertCrc(0x8a9136aa, zeros); }
public void testAscending() { // Test 32 byte arrays of ascending. byte[] ascending = new byte[32]; for (int i = 0; i < 32; i++) { ascending[i] = (byte) i; } assertCrc(0x46dd794e, ascending); }
public void testDescending() { // Test 32 byte arrays of descending. byte[] descending = new byte[32]; for (int i = 0; i < 32; i++) { descending[i] = (byte) (31 - i); } assertCrc(0x113fdb5c, descending); }
public void testScsiReadCommand() { // Test SCSI read command. byte[] scsiReadCommand = new byte[] { 0x01, (byte) 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x18, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; assertCrc(0xd9963a56, scsiReadCommand); }
public void testZeros() { // Test 32 byte array of 0x00. byte[] zeros = new byte[32]; Arrays.fill(zeros, (byte) 0x00); assertCrc(0x8a9136aa, zeros); }
public void testFull() { // Test 32 byte array of 0xFF. byte[] fulls = new byte[32]; Arrays.fill(fulls, (byte) 0xFF); assertCrc(0x62a8ab43, fulls); }