00-details.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  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. value = details::crc32_finalize(value);
  9. CHECK(value == 0x83DCEFB7);
  10. }
  11. SECTION("2 bytes") {
  12. char payload[] = "19";
  13. auto value = details::crc32((uint8_t *)payload, sizeof(payload) - 1);
  14. value = details::crc32_finalize(value);
  15. CHECK(value == 0xD8819D45);
  16. }
  17. SECTION("net sample") {
  18. uint8_t payload[] = {
  19. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x48, 0xba, 0x4e, 0x51, 0x39, 0xbb,
  20. 0x08, 0x06, 0x00, 0x01, 0x08, 0x00, 0x06, 0x04, 0x00, 0x01, 0x48, 0xba,
  21. 0x4e, 0x51, 0x39, 0xbb, 0xc0, 0xa8, 0x65, 0x01, 0x00, 0x00, 0x00, 0x00,
  22. 0x00, 0x00, 0xc0, 0xa8, 0x65, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  23. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  24. };
  25. auto value = details::crc32(payload, sizeof(payload));
  26. value = details::crc32_finalize(value);
  27. CHECK(value == 0x02394A00);
  28. }
  29. }