-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests/unittests: add test for CRC-32 checksum
- Loading branch information
Showing
3 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright 2022 Benjamin Valentin <benpicco@googlemail.com> | ||
* | ||
* This file is subject to the terms and conditions of the GNU Lesser | ||
* General Public License v2.1. See the file LICENSE in the top level | ||
* directory for more details. | ||
*/ | ||
|
||
|
||
#include "checksum/crc32.h" | ||
#include "tests-checksum.h" | ||
|
||
static void test_checksum_crc32_sequence_empty(void) | ||
{ | ||
unsigned char buf[] = ""; | ||
uint32_t expect = 0x0; | ||
|
||
TEST_ASSERT_EQUAL_INT(expect, crc32(buf, sizeof(buf) - 1)); | ||
} | ||
|
||
static void test_checksum_crc32_sequence_1a(void) | ||
{ | ||
unsigned char buf[] = "A"; | ||
uint32_t expect = 0xd3d99e8b; | ||
|
||
TEST_ASSERT_EQUAL_INT(expect, crc32(buf, sizeof(buf) - 1)); | ||
} | ||
|
||
static void test_checksum_crc32_sequence_256a(void) | ||
{ | ||
unsigned char buf[] = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" | ||
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" | ||
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" | ||
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" | ||
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" | ||
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" | ||
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" | ||
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"; | ||
uint32_t expect = 0x49975b13; | ||
|
||
TEST_ASSERT_EQUAL_INT(expect, crc32(buf, sizeof(buf) - 1)); | ||
} | ||
|
||
static void test_checksum_crc32_sequence_1to9(void) | ||
{ | ||
unsigned char buf[] = "123456789"; | ||
uint32_t expect = 0xcbf43926; | ||
|
||
TEST_ASSERT_EQUAL_INT(expect, crc32(buf, sizeof(buf) - 1)); | ||
} | ||
|
||
static void test_checksum_crc32_sequence_4bytes(void) | ||
{ | ||
unsigned char buf[] = { 0x12, 0x34, 0x56, 0x78 }; | ||
uint32_t expect = 0x4a090e98; | ||
|
||
TEST_ASSERT_EQUAL_INT(expect, crc32(buf, sizeof(buf))); | ||
} | ||
|
||
Test *tests_checksum_crc32_tests(void) | ||
{ | ||
EMB_UNIT_TESTFIXTURES(fixtures) { | ||
new_TestFixture(test_checksum_crc32_sequence_empty), | ||
new_TestFixture(test_checksum_crc32_sequence_1a), | ||
new_TestFixture(test_checksum_crc32_sequence_256a), | ||
new_TestFixture(test_checksum_crc32_sequence_1to9), | ||
new_TestFixture(test_checksum_crc32_sequence_4bytes), | ||
}; | ||
|
||
EMB_UNIT_TESTCALLER(checksum_crc32_tests, NULL, NULL, fixtures); | ||
|
||
return (Test *)&checksum_crc32_tests; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters