mirror of
https://github.com/rtbrick/bngblaster.git
synced 2024-05-06 15:54:57 +00:00
42 lines
1.5 KiB
C
42 lines
1.5 KiB
C
/*
|
|
* Common Utils Tests
|
|
*
|
|
* Christian Giese, June 2021
|
|
*
|
|
* Copyright (C) 2020-2024, RtBrick, Inc.
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
*/
|
|
#include <stddef.h>
|
|
#include <stdarg.h>
|
|
#include <setjmp.h>
|
|
#include <cmocka.h>
|
|
#include <checksum.h>
|
|
|
|
static void
|
|
test_calculate_fletcher_checksum(void **unused) {
|
|
(void) unused;
|
|
|
|
uint8_t pdu1[] = {
|
|
0x02, 0x08, 0x50, 0x9c, 0x89, 0xe4, 0x00, 0x01, 0x00, 0x0e, 0x3f, 0x5a,
|
|
0xff, 0xff, 0x03, 0x0a, 0x07, 0x01, 0x44, 0x75, 0x67, 0x6c, 0x61, 0x73,
|
|
0x16, 0x2e, 0x02, 0x08, 0x3e, 0x9d, 0xde, 0xc5, 0x00, 0x00, 0x00, 0x14,
|
|
0x23, 0x04, 0x08, 0x00, 0x00, 0x00, 0x87, 0x00, 0x00, 0x00, 0x4c, 0x06,
|
|
0x04, 0x3e, 0x9d, 0xdf, 0x9d, 0x08, 0x04, 0x3e, 0x9d, 0xdf, 0x9e, 0x09,
|
|
0x04, 0x50, 0x3a, 0x43, 0xb7, 0x1f, 0x05, 0x30, 0x00, 0x00, 0x73, 0xa0,
|
|
0x16, 0x2e, 0x02, 0x08, 0x50, 0x9c, 0x6c, 0xf0, 0x00, 0x00, 0x00, 0x14,
|
|
0x23, 0x04, 0x08, 0x00, 0x00, 0x00, 0x85, 0x00, 0x00, 0x00, 0x8b, 0x06,
|
|
0x04, 0x50, 0x9c, 0x9c, 0xd1, 0x08, 0x04, 0x50, 0x9c, 0x9c, 0xd2, 0x09,
|
|
0x04, 0x50, 0x3a, 0x43, 0xb7, 0x1f, 0x05, 0x30, 0x00, 0x00, 0x73, 0xaa
|
|
};
|
|
uint16_t pdu1_checksum = 0x3bd4;
|
|
|
|
uint16_t checksum = calculate_fletcher_checksum((void*)pdu1, 12, sizeof(pdu1));
|
|
assert_int_equal(checksum, pdu1_checksum);
|
|
}
|
|
|
|
int main() {
|
|
const struct CMUnitTest tests[] = {
|
|
cmocka_unit_test(test_calculate_fletcher_checksum),
|
|
};
|
|
return cmocka_run_group_tests(tests, NULL, NULL);
|
|
} |