mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-25 22:43:50 +01:00
tests/checksum: fix style in fletcher16
This commit is contained in:
parent
4d9ac9eebd
commit
018b3b4660
@ -22,47 +22,49 @@ static int calc_and_compare_checksum(const unsigned char *buf, size_t len,
|
||||
return result == expected;
|
||||
}
|
||||
|
||||
static void test_checksum_fletcher16(void)
|
||||
static void test_checksum_fletcher16_empty(void)
|
||||
{
|
||||
{
|
||||
unsigned char buf[] = "";
|
||||
uint16_t expect = 0xFFFF;
|
||||
unsigned char buf[] = "";
|
||||
uint16_t expect = 0xFFFF;
|
||||
|
||||
TEST_ASSERT(calc_and_compare_checksum(buf, sizeof(buf) - 1, expect));
|
||||
}
|
||||
TEST_ASSERT(calc_and_compare_checksum(buf, sizeof(buf) - 1, expect));
|
||||
}
|
||||
|
||||
{
|
||||
/* fletcher cannot distinguish between all 0 and all 1 segments */
|
||||
unsigned char buf0[16] = {
|
||||
0xA1, 0xA1, 0xA1, 0xA1,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x1A, 0x1A, 0x1A, 0x1A,
|
||||
};
|
||||
uint32_t expect = fletcher16(buf0, sizeof(buf0));
|
||||
unsigned char buf1[16] = {
|
||||
0xA1, 0xA1, 0xA1, 0xA1,
|
||||
0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0x1A, 0x1A, 0x1A, 0x1A,
|
||||
};
|
||||
static void test_checksum_fletcher16_0to1_undetected(void)
|
||||
{
|
||||
/* fletcher cannot distinguish between all 0 and all 1 segments */
|
||||
unsigned char buf0[16] = {
|
||||
0xA1, 0xA1, 0xA1, 0xA1,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00,
|
||||
0x1A, 0x1A, 0x1A, 0x1A,
|
||||
};
|
||||
uint32_t expect = fletcher16(buf0, sizeof(buf0));
|
||||
unsigned char buf1[16] = {
|
||||
0xA1, 0xA1, 0xA1, 0xA1,
|
||||
0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0x1A, 0x1A, 0x1A, 0x1A,
|
||||
};
|
||||
|
||||
TEST_ASSERT(calc_and_compare_checksum(buf1, sizeof(buf1), expect));
|
||||
}
|
||||
TEST_ASSERT(calc_and_compare_checksum(buf1, sizeof(buf1), expect));
|
||||
}
|
||||
|
||||
{
|
||||
/* verified with http://www.nitrxgen.net/hashgen/ */
|
||||
unsigned char buf[] = "abcde";
|
||||
uint16_t expect = 0xc8f0;
|
||||
static void test_checksum_fletcher16_atoe(void)
|
||||
{
|
||||
/* verified with http://www.nitrxgen.net/hashgen/ */
|
||||
unsigned char buf[] = "abcde";
|
||||
uint16_t expect = 0xc8f0;
|
||||
|
||||
TEST_ASSERT(calc_and_compare_checksum(buf, sizeof(buf) - 1, expect));
|
||||
}
|
||||
TEST_ASSERT(calc_and_compare_checksum(buf, sizeof(buf) - 1, expect));
|
||||
}
|
||||
|
||||
Test *tests_checksum_fletcher16_tests(void)
|
||||
{
|
||||
EMB_UNIT_TESTFIXTURES(fixtures) {
|
||||
new_TestFixture(test_checksum_fletcher16),
|
||||
new_TestFixture(test_checksum_fletcher16_empty),
|
||||
new_TestFixture(test_checksum_fletcher16_0to1_undetected),
|
||||
new_TestFixture(test_checksum_fletcher16_atoe),
|
||||
};
|
||||
|
||||
EMB_UNIT_TESTCALLER(checksum_fletcher16_tests, NULL, NULL, fixtures);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user