libtinycrc/crctest.cpp

41 lines
952 B
C++
Raw Permalink Normal View History

2023-12-19 02:01:07 +00:00
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <cstring>
#include "src/tinycrc.h"
2023-12-19 02:14:16 +00:00
void test(const uint8_t* buffer)
2023-12-19 02:01:07 +00:00
{
2023-12-19 02:14:16 +00:00
uint32_t crc32 = tinycrc_crc32(buffer, strlen((char*)buffer));
uint16_t crc16 = tinycrc_crc16(buffer, strlen((char*)buffer));
uint8_t crc8 = tinycrc_crc8(buffer, strlen((char*)buffer));
2023-12-19 02:01:07 +00:00
2023-12-24 20:42:43 +00:00
printf("%-32s | %08x | %04x | %02x\n", (char*)buffer, crc32, crc16, crc8);
2023-12-19 02:14:16 +00:00
}
2023-12-19 02:01:07 +00:00
2023-12-19 02:14:16 +00:00
int main()
{
uint8_t* buffer = (uint8_t*)malloc(32);
2023-12-19 02:01:07 +00:00
2023-12-24 20:42:43 +00:00
printf("%-32s | %8d | %4d | %2d\n", (char*)buffer, 32, 16, 8);
memset((char*)buffer, 0, 32);
2023-12-19 02:14:16 +00:00
strcpy((char*)buffer, "Hello World\0");
test(buffer);
2023-12-19 02:01:07 +00:00
2023-12-24 20:42:43 +00:00
memset((char*)buffer, 0, 32);
2023-12-19 02:14:16 +00:00
strcpy((char*)buffer, "Hello World!\0");
test(buffer);
2023-12-19 02:01:07 +00:00
2023-12-24 20:42:43 +00:00
memset((char*)buffer, 0, 32);
2023-12-19 02:14:16 +00:00
strcpy((char*)buffer, "Hello Worlds\0");
test(buffer);
2023-12-19 02:01:07 +00:00
2023-12-24 20:42:43 +00:00
memset((char*)buffer, 0, 32);
2023-12-19 02:14:16 +00:00
strcpy((char*)buffer, "Testing\0");
test(buffer);
2023-12-19 02:01:07 +00:00
free(buffer);
}