00-details.cpp 990 B

12345678910111213141516171819202122232425262728293031
  1. #include "limbo/details/crc32.h"
  2. #include "test-utils.h"
  3. using namespace limbo;
  4. TEST_CASE("crc", "[details]") {
  5. SECTION("1 byte") {
  6. char payload[] = "1";
  7. auto value = details::crc32((uint8_t *)payload, sizeof(payload) - 1);
  8. CHECK(value == 0x83DCEFB7);
  9. }
  10. SECTION("2 bytes") {
  11. char payload[] = "19";
  12. auto value = details::crc32((uint8_t *)payload, sizeof(payload) - 1);
  13. CHECK(value == 0xD8819D45);
  14. }
  15. SECTION("net sample") {
  16. uint8_t payload[] = {
  17. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x48, 0xba, 0x4e, 0x51, 0x39, 0xbb,
  18. 0x08, 0x06, 0x00, 0x01, 0x08, 0x00, 0x06, 0x04, 0x00, 0x01, 0x48, 0xba,
  19. 0x4e, 0x51, 0x39, 0xbb, 0xc0, 0xa8, 0x65, 0x01, 0x00, 0x00, 0x00, 0x00,
  20. 0x00, 0x00, 0xc0, 0xa8, 0x65, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  21. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  22. };
  23. auto value = details::crc32(payload, sizeof(payload));
  24. CHECK(value == 0x02394A00);
  25. }
  26. }