Exemple #1
0
void CRC32Test::testGetValue() {

    // test methods of java.util.zip.crc32.getValue()
    CRC32 crc;
    CPPUNIT_ASSERT_EQUAL_MESSAGE( "getValue() should return a zero as a result of constructing a CRC32 instance",
                                  0LL, crc.getValue() );

    crc.reset();
    crc.update( Integer::MAX_VALUE );

    // Ran JDK and discovered that the value of the CRC should be
    // 4278190080
    CPPUNIT_ASSERT_EQUAL_MESSAGE( "update(max) failed to update the checksum to the correct value ",
                                  4278190080LL, crc.getValue() );

    crc.reset();
    std::vector<unsigned char> byteEmpty( 10000, 0 );
    crc.update( byteEmpty );

    // Ran JDK and discovered that the value of the CRC should be
    // 1295764014
    CPPUNIT_ASSERT_EQUAL_MESSAGE( "update(byte[]) failed to update the checksum to the correct value ",
                                  1295764014LL, crc.getValue() );

    crc.reset();
    crc.update( 1 );

    // Ran JDK and discovered that the value of the CRC should be
    // 2768625435
    // CPPUNIT_ASSERT_EQUAL_MESSAGE( "update(int) failed to update the checksum to the correct
    // value ",2768625435L, crc.getValue());
    crc.reset();
    CPPUNIT_ASSERT_EQUAL_MESSAGE( "reset failed to reset the checksum value to zero",
                                  0LL, crc.getValue());
}
Exemple #2
0
void CRC32Test::testUpdateArrayIndexed() {

    static const int SIZE = 3;
    unsigned char byteArray[] = {1, 2, 3};
    CRC32 crc;

    int off = 2;// accessing the 2nd element of byteArray
    int len = 1;
    int lenError = 3;
    int offError = 4;
    crc.update( byteArray, SIZE, off, len );

    // Ran JDK and discovered that the value of the CRC should be
    // 1259060791
    CPPUNIT_ASSERT_EQUAL_MESSAGE( "update(unsigned char[],int,int) failed to update the checksum to the correct value ",
                                  1259060791LL, crc.getValue() );

    CPPUNIT_ASSERT_THROW_MESSAGE(
        "Should have thrown an IndexOutOfBoundsException for lenError",
        crc.update( byteArray, SIZE, off, lenError ),
        IndexOutOfBoundsException );

    CPPUNIT_ASSERT_THROW_MESSAGE(
        "Should have thrown an IndexOutOfBoundsException for offError",
        crc.update( byteArray, SIZE, offError, len ),
        IndexOutOfBoundsException );
}
Exemple #3
0
void CRC32Test::testUpdateI() {

    CRC32 crc;
    crc.update( 1 );

    // Ran JDK and discovered that the value of the CRC should be
    // 2768625435
    CPPUNIT_ASSERT_EQUAL_MESSAGE( "update(1) failed to update the checksum to the correct value ",
                                  2768625435LL, crc.getValue() );

    crc.reset();
    crc.update( Integer::MAX_VALUE );

    // Ran JDK and discovered that the value of the CRC should be
    // 4278190080
    CPPUNIT_ASSERT_EQUAL_MESSAGE( "update(max) failed to update the checksum to the correct value ",
                                  4278190080LL, crc.getValue() );

    crc.reset();
    crc.update( Integer::MIN_VALUE );

    // Ran JDK and discovered that the value of the CRC should be
    // 3523407757
    CPPUNIT_ASSERT_EQUAL_MESSAGE( "update(min) failed to update the checksum to the correct value ",
                                  3523407757LL, crc.getValue() );
}
//! A CRC-32 is calculated over the load data, including any pad bytes
//! that are required in the last data cipher block. Including the
//! pad bytes in the CRC makes it vastly easier for the ROM to calculate
//! the CRC for validation.
uint32_t EncoreBootImage::LoadCommand::calculateCRC() const
{
	uint32_t result;
	CRC32 crc;
	crc.update(m_data, m_length);
	if (m_padCount)
	{
		// include random padding in the CRC
		crc.update(m_padding, m_padCount);
	}
	crc.truncatedFinal(reinterpret_cast<uint8_t*>(&result), sizeof(result));
	
	return result;
}
Exemple #5
0
void CRC32Test::testUpdateArray() {

    unsigned char byteArray[] = { 1, 2 };
    CRC32 crc;
    crc.update( byteArray, 2, 0, 2 );

    // Ran JDK and discovered that the value of the CRC should be
    // 3066839698
    CPPUNIT_ASSERT_EQUAL_MESSAGE( "update(unsigned char[]) failed to update the checksum to the correct value ",
                                  3066839698LL, crc.getValue() );

    crc.reset();
    std::vector<unsigned char> byteEmpty( 10000, 0 );
    crc.update( byteEmpty );

    // Ran JDK and discovered that the value of the CRC should be
    // 1295764014
    CPPUNIT_ASSERT_EQUAL_MESSAGE( "update(unsigned char[]) failed to update the checksum to the correct value ",
                                  1295764014LL, crc.getValue() );
}
Exemple #6
0
void CRC32Test::testReset() {

    CRC32 crc;
    crc.update( 1 );

    // Ran JDK and discovered that the value of the CRC should be
    // 2768625435
    CPPUNIT_ASSERT_EQUAL_MESSAGE( "update(int) failed to update the checksum to the correct value ",
                                  2768625435LL, crc.getValue() );
    crc.reset();
    CPPUNIT_ASSERT_EQUAL_MESSAGE( "reset failed to reset the checksum value to zero",
                                  0LL, crc.getValue() );
}