2017-01-25 16:12:12 +11:00
|
|
|
#include "tap.hpp"
|
|
|
|
#include "hash/crc.hpp"
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
static const
|
|
|
|
struct {
|
2017-02-14 19:47:12 +11:00
|
|
|
struct {
|
|
|
|
uint32_t crc32;
|
|
|
|
uint32_t crc32b;
|
|
|
|
uint32_t crc32c;
|
|
|
|
uint32_t crc32d;
|
|
|
|
uint64_t crc64;
|
|
|
|
} result;
|
2017-01-25 16:12:12 +11:00
|
|
|
const char *dat;
|
|
|
|
const char *msg;
|
|
|
|
} TESTS[] = {
|
2017-02-14 19:47:12 +11:00
|
|
|
{ { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0000000000000000 }, "", "empty" },
|
|
|
|
{ { 0xe8b7be43, 0x19939b6b, 0xc1d04330, 0x60819b69, 0x548f120162451c62 }, "a", "single letter" },
|
|
|
|
{ { 0xa684c7c6, 0x96b0e4e0, 0x280c069e, 0x95ed974e, 0x2a71ab4164c3bbe8 }, "0123456789", "10 digits" },
|
|
|
|
{ { 0x414fa339, 0x459dee61, 0x22620404, 0x9d251c62, 0x41e05242ffa9883b }, "The quick brown fox jumps over the lazy dog", "quick brown fox" },
|
2017-01-25 16:12:12 +11:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
int
|
|
|
|
main (int, char**)
|
|
|
|
{
|
|
|
|
util::TAP::logger tap;
|
|
|
|
|
|
|
|
for (const auto &t: TESTS) {
|
2018-01-13 13:48:58 +11:00
|
|
|
#define TEST(KLASS) do { \
|
2018-05-10 12:52:01 +10:00
|
|
|
auto computed = util::hash::KLASS{}(util::view {t.dat}.template cast<const uint8_t*> ()); \
|
2017-02-14 19:47:12 +11:00
|
|
|
tap.expect_eq (t.result.KLASS, computed, "%s: %s", #KLASS, t.msg); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
TEST(crc32);
|
|
|
|
TEST(crc32b);
|
|
|
|
TEST(crc32c);
|
|
|
|
TEST(crc32d);
|
|
|
|
TEST(crc64);
|
2017-01-25 16:12:12 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
return tap.status ();
|
|
|
|
}
|