parent
3d23724802
commit
100991e59e
@ -14,6 +14,10 @@
|
|||||||
|
|
||||||
#include "tests-checksum.h"
|
#include "tests-checksum.h"
|
||||||
|
|
||||||
|
/* String is longer than 20 so it checks the wrap-around property of
|
||||||
|
* fletcher16 */
|
||||||
|
static const unsigned char wrap_around_data[] = "u9k89rm88z58f3hGxTfgG3BnyKnyRP";
|
||||||
|
|
||||||
static int calc_and_compare_checksum(const unsigned char *buf, size_t len,
|
static int calc_and_compare_checksum(const unsigned char *buf, size_t len,
|
||||||
uint16_t expected)
|
uint16_t expected)
|
||||||
{
|
{
|
||||||
@ -59,12 +63,22 @@ static void test_checksum_fletcher16_atoe(void)
|
|||||||
TEST_ASSERT(calc_and_compare_checksum(buf, sizeof(buf) - 1, expect));
|
TEST_ASSERT(calc_and_compare_checksum(buf, sizeof(buf) - 1, expect));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_checksum_fletcher16_wrap_around(void)
|
||||||
|
{
|
||||||
|
/* verified with http://www.nitrxgen.net/hashgen/ */
|
||||||
|
uint16_t expect = 0xf122;
|
||||||
|
|
||||||
|
TEST_ASSERT(calc_and_compare_checksum(wrap_around_data,
|
||||||
|
sizeof(wrap_around_data) - 1, expect));
|
||||||
|
}
|
||||||
|
|
||||||
Test *tests_checksum_fletcher16_tests(void)
|
Test *tests_checksum_fletcher16_tests(void)
|
||||||
{
|
{
|
||||||
EMB_UNIT_TESTFIXTURES(fixtures) {
|
EMB_UNIT_TESTFIXTURES(fixtures) {
|
||||||
new_TestFixture(test_checksum_fletcher16_empty),
|
new_TestFixture(test_checksum_fletcher16_empty),
|
||||||
new_TestFixture(test_checksum_fletcher16_0to1_undetected),
|
new_TestFixture(test_checksum_fletcher16_0to1_undetected),
|
||||||
new_TestFixture(test_checksum_fletcher16_atoe),
|
new_TestFixture(test_checksum_fletcher16_atoe),
|
||||||
|
new_TestFixture(test_checksum_fletcher16_wrap_around),
|
||||||
};
|
};
|
||||||
|
|
||||||
EMB_UNIT_TESTCALLER(checksum_fletcher16_tests, NULL, NULL, fixtures);
|
EMB_UNIT_TESTCALLER(checksum_fletcher16_tests, NULL, NULL, fixtures);
|
||||||
|
|||||||
@ -14,6 +14,16 @@
|
|||||||
|
|
||||||
#include "tests-checksum.h"
|
#include "tests-checksum.h"
|
||||||
|
|
||||||
|
/* String is longer than 359 so it checks the wrap-around property of
|
||||||
|
* fletcher32 */
|
||||||
|
static const unsigned char wrap_around_data[] =
|
||||||
|
"AD3Awn4kb6FtcsyE0RU25U7f55Yncn3LP3oEx9Gl4qr7iDW7I8L6Pbw9jNnh0sE4DmCKuc"
|
||||||
|
"d1J8I34vn31W924y5GMS74vUrZQc08805aj4Tf66HgL1cO94os10V2s2GDQ825yNh9Yuq3"
|
||||||
|
"QHcA60xl31rdA7WskVtCXI7ruH1A4qaR6Uk454hm401lLmv2cGWt5KTJmr93d3JsGaRRPs"
|
||||||
|
"4HqYi4mFGowo8fWv48IcA3N89Z99nf0A0H2R6P0uI4Tir682Of3Rk78DUB2dIGQRRpdqVT"
|
||||||
|
"tLhgfET2gUGU65V3edSwADMqRttI9JPVz8JS37g5QZj4Ax56rU1u0m0K8YUs57UYG5645n"
|
||||||
|
"byNy4yqxu7";
|
||||||
|
|
||||||
static int calc_and_compare_checksum(const unsigned char *buf, size_t len,
|
static int calc_and_compare_checksum(const unsigned char *buf, size_t len,
|
||||||
uint32_t expected)
|
uint32_t expected)
|
||||||
{
|
{
|
||||||
@ -62,12 +72,22 @@ static void test_checksum_fletcher32_atof(void)
|
|||||||
TEST_ASSERT(calc_and_compare_checksum(buf, sizeof(buf) - 1, expect));
|
TEST_ASSERT(calc_and_compare_checksum(buf, sizeof(buf) - 1, expect));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_checksum_fletcher32_wrap_around(void)
|
||||||
|
{
|
||||||
|
/* XXX: not verified with external implementation yet */
|
||||||
|
uint32_t expect = 0x5bac8c3d;
|
||||||
|
|
||||||
|
TEST_ASSERT(calc_and_compare_checksum(wrap_around_data,
|
||||||
|
sizeof(wrap_around_data) - 1, expect));
|
||||||
|
}
|
||||||
|
|
||||||
Test *tests_checksum_fletcher32_tests(void)
|
Test *tests_checksum_fletcher32_tests(void)
|
||||||
{
|
{
|
||||||
EMB_UNIT_TESTFIXTURES(fixtures) {
|
EMB_UNIT_TESTFIXTURES(fixtures) {
|
||||||
new_TestFixture(test_checksum_fletcher32_empty),
|
new_TestFixture(test_checksum_fletcher32_empty),
|
||||||
new_TestFixture(test_checksum_fletcher32_0to1_undetected),
|
new_TestFixture(test_checksum_fletcher32_0to1_undetected),
|
||||||
new_TestFixture(test_checksum_fletcher32_atof),
|
new_TestFixture(test_checksum_fletcher32_atof),
|
||||||
|
new_TestFixture(test_checksum_fletcher32_wrap_around),
|
||||||
};
|
};
|
||||||
|
|
||||||
EMB_UNIT_TESTCALLER(checksum_fletcher32_tests, NULL, NULL, fixtures);
|
EMB_UNIT_TESTCALLER(checksum_fletcher32_tests, NULL, NULL, fixtures);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user