12345678910111213141516171819202122232425262728293031 |
- #include "limbo/details/crc32.h"
- #include "test-utils.h"
- using namespace limbo;
- TEST_CASE("crc", "[details]") {
- SECTION("1 byte") {
- char payload[] = "1";
- auto value = details::crc32((uint8_t *)payload, sizeof(payload) - 1);
- CHECK(value == 0x83DCEFB7);
- }
- SECTION("2 bytes") {
- char payload[] = "19";
- auto value = details::crc32((uint8_t *)payload, sizeof(payload) - 1);
- CHECK(value == 0xD8819D45);
- }
- SECTION("net sample") {
- uint8_t payload[] = {
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x48, 0xba, 0x4e, 0x51, 0x39, 0xbb,
- 0x08, 0x06, 0x00, 0x01, 0x08, 0x00, 0x06, 0x04, 0x00, 0x01, 0x48, 0xba,
- 0x4e, 0x51, 0x39, 0xbb, 0xc0, 0xa8, 0x65, 0x01, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0xc0, 0xa8, 0x65, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- };
- auto value = details::crc32(payload, sizeof(payload));
- CHECK(value == 0x02394A00);
- }
- }
|