Go to the documentation of this file.00001 #include <check.h>
00002
00003 #include <edc.h>
00004
00005 const u8 *test_data = (u8*)"123456789";
00006
00007 START_TEST(test_crc16_ccitt)
00008 {
00009 u16 crc;
00010
00011 crc = crc16_ccitt(test_data, 0, 0);
00012 fail_unless(crc == 0,
00013 "CRC of empty buffer with starting value 0 should be 0, not %d", crc);
00014
00015 crc = crc16_ccitt(test_data, 0, 22);
00016 fail_unless(crc == 22,
00017 "CRC of empty buffer with starting value 22 should be 22, not %d", crc);
00018
00019
00020
00021 crc = crc16_ccitt(test_data, 9, 0);
00022 fail_unless(crc == 0x31C3,
00023 "CRC of \"123456789\" should be 0x31C3, not 0x%04X", crc);
00024 }
00025 END_TEST
00026
00027 START_TEST(test_crc24q)
00028 {
00029 u32 crc;
00030
00031 crc = crc24q(test_data, 0, 0);
00032 fail_unless(crc == 0,
00033 "CRC of empty buffer with starting value 0 should be 0, not %d", crc);
00034
00035 crc = crc24q(test_data, 0, 22);
00036 fail_unless(crc == 22,
00037 "CRC of empty buffer with starting value 22 should be 22, not %d", crc);
00038
00039
00040
00041 crc = crc24q(test_data, 9, 0xB704CE);
00042 fail_unless(crc == 0x21CF02,
00043 "CRC of \"123456789\" with init value 0xB704CE should be 0x21CF02, "
00044 "not 0x%06X", crc);
00045 }
00046 END_TEST
00047
00048 Suite* edc_suite(void)
00049 {
00050 Suite *s = suite_create("Error Detection and Correction");
00051
00052 TCase *tc_crc = tcase_create("CRC");
00053 tcase_add_test(tc_crc, test_crc16_ccitt);
00054 tcase_add_test(tc_crc, test_crc24q);
00055 suite_add_tcase(s, tc_crc);
00056
00057 return s;
00058 }
00059