/* crc_prb.c */ #include #include #include "crc.h" void main ( void ); void test01 ( void ); void test02 ( void ); void test03 ( void ); /******************************************************************************/ void main ( void ) /******************************************************************************/ { printf ( "\n" ); printf ( "CRC_PRB\n"); printf ( " Test CRC routines.\n"); test01 ( ); test02 ( ); test03 ( ); printf ( "\n" ); printf ( "CRC_PRB\n"); printf ( " Normal end of CRC tests.\n"); exit; } /**********************************************************************/ void test01 ( void ) /**********************************************************************/ /* TEST01 tests MAKE_CRC_TABLE. */ { int i; printf ( "\n" ); printf ( "TEST01\n" ); printf ( " MAKE_CRC_TABLE sets up the 256 entry CRC table.\n" ); printf ( "\n" ); printf ( " Each entry is an unsigned long integer. We'll print\n" ); printf ( " signed versions of the entries.\n" ); make_crc_table(); print_crc_table(); return; } /**********************************************************************/ void test02 ( void ) /**********************************************************************/ /* TEST02 tests CRC. */ { unsigned char buf[10]; unsigned char c; int len = 10; unsigned long my_crc; /* How do I assign these more simply? How do I print a string of 10 characters? How do I do the CRC for, say, an integer vector? */ buf[0] = 'D'; buf[1] = 'r'; buf[2] = '.'; buf[3] = ' '; buf[4] = 'C'; buf[5] = 'r'; buf[6] = 'y'; buf[7] = 'p'; buf[8] = 't'; buf[9] = 'o'; printf ( "\n" ); printf ( "TEST02\n" ); printf ( " CRC computes the CRC of a string of bytes.\n" ); printf ( "\n" ); my_crc = crc ( buf, len ); printf ( "\n" ); printf ( " Original CRC = %x (hex).\n", my_crc ); printf ( " = %d (dec).\n", my_crc ); c = buf[3]; buf[3] = buf[4]; buf[4] = c; my_crc = crc ( buf, len ); printf ( "\n" ); printf ( " CRC after swapping C[3] and C[4] = %x (hex).\n", my_crc ); printf ( " = %d (dec).\n", my_crc ); c = buf[3]; buf[3] = buf[4]; buf[4] = c; buf[5] = buf[5] + 1; my_crc = crc ( buf, len ); printf ( "\n" ); printf ( " CRC after incrementing C[5] by 1 = %x (hex).\n", my_crc ); printf ( " = %d (dec).\n", my_crc ); my_crc = crc ( buf, len-1 ); printf ( "\n" ); printf ( " CRC of first LEN-1 values = %x (hex).\n", my_crc ); printf ( " = %d (dec).\n", my_crc ); return; } void test03 ( void ) /**********************************************************************/ /* TEST03 tests UPDATE_CRC. */ { unsigned char buf[10]; int i; int len = 10; unsigned long my_crc; /* How do I assign these more simply? How do I print a string of 10 characters? How do I do the CRC for, say, an integer vector? */ buf[0] = 'D'; buf[1] = 'r'; buf[2] = '.'; buf[3] = ' '; buf[4] = 'C'; buf[5] = 'r'; buf[6] = 'y'; buf[7] = 'p'; buf[8] = 't'; buf[9] = 'o'; printf ( "\n" ); printf ( "TEST03\n" ); printf ( " UPDATE_CRC computes the running CRC of a string of bytes.\n" ); printf ( " This should be the same as computing the full CRC.\n" ); printf ( "\n" ); my_crc = crc ( buf, len ); printf ( "\n" ); printf ( " Full CRC = %x (hex).\n", my_crc ); printf ( " = %d (decimal).\n", my_crc ); my_crc = 0xffffffffL; for ( i = 0; i < len; i++ ) { my_crc = update_crc ( my_crc, &buf[i], 1 ); } my_crc = my_crc ^ 0xffffffffL; printf ( "\n" ); printf ( " Incremental CRC = %x (hex).\n", my_crc ); printf ( " = %d (decimal).\n", my_crc ); return; }