2011-11-04 16:56:25 +11:00
|
|
|
|
2013-07-13 14:40:13 +10:00
|
|
|
#include "hash/adler.hpp"
|
|
|
|
#include "hash/bsdsum.hpp"
|
2016-06-20 16:49:22 +10:00
|
|
|
#include "hash/simple.hpp"
|
|
|
|
|
2011-11-04 16:56:25 +11:00
|
|
|
#include "types.hpp"
|
2015-04-13 16:45:56 +10:00
|
|
|
#include "tap.hpp"
|
2012-05-26 18:01:54 +10:00
|
|
|
#include "debug.hpp"
|
2011-11-04 16:56:25 +11:00
|
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
|
2016-03-11 13:28:56 +11:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2011-11-04 16:56:25 +11:00
|
|
|
static const char *ALPHABET = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
|
|
|
|
2016-03-11 13:28:56 +11:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2011-11-04 16:56:25 +11:00
|
|
|
static const struct {
|
|
|
|
uint32_t adler;
|
|
|
|
uint16_t bsd;
|
2014-09-11 15:44:03 +10:00
|
|
|
|
2016-06-20 16:49:22 +10:00
|
|
|
std::string msg;
|
2011-11-04 16:56:25 +11:00
|
|
|
const char *data;
|
|
|
|
} TESTS[] = {
|
2016-06-20 16:49:22 +10:00
|
|
|
{ 0x00000001, 0x0000, "empty", "" },
|
|
|
|
{ 0xDF5B150C, 0x52FB, "alphabet", ALPHABET },
|
|
|
|
{ 0x11E60398, 0x3DC8, "wikipedia", "Wikipedia" },
|
|
|
|
{ 0x97B61069, 0x5555, "digits", "12345678901234567890123456789012345678901234567890123456789012345678901234567890" },
|
2011-11-04 16:56:25 +11:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-03-11 13:28:56 +11:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2011-11-04 16:56:25 +11:00
|
|
|
int
|
|
|
|
main (int, char**) {
|
2015-04-13 16:45:56 +10:00
|
|
|
util::TAP::logger tap;
|
|
|
|
|
2016-06-20 16:49:22 +10:00
|
|
|
for (const auto &t: TESTS) {
|
|
|
|
tap.expect_eq (
|
|
|
|
t.adler,
|
|
|
|
util::hash::simple<util::hash::adler32> (
|
|
|
|
(const void*)t.data,
|
|
|
|
(const void*)(t.data + strlen (t.data))
|
|
|
|
),
|
|
|
|
"adler checksum: %s", t.msg
|
|
|
|
);
|
|
|
|
|
|
|
|
tap.expect_eq (
|
|
|
|
t.bsd,
|
|
|
|
util::hash::simple<util::hash::bsdsum> (t.data, t.data + strlen (t.data)),
|
|
|
|
"bsdsum checksum: %s", t.msg);
|
2011-11-04 16:56:25 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|