2024-05-29 16:29:08 +10:00
|
|
|
#include <cruft/util/hash/adler.hpp>
|
|
|
|
#include <cruft/util/hash/bsdsum.hpp>
|
2011-11-04 16:56:25 +11:00
|
|
|
|
2024-05-29 16:29:08 +10:00
|
|
|
#include <cruft/util/types.hpp>
|
|
|
|
#include <cruft/util/tap.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**) {
|
2018-08-05 14:42:02 +10:00
|
|
|
cruft::TAP::logger tap;
|
2015-04-13 16:45:56 +10:00
|
|
|
|
2018-08-05 14:42:02 +10:00
|
|
|
cruft::hash::adler32 a;
|
|
|
|
cruft::hash::bsdsum b;
|
2018-01-13 13:48:58 +11:00
|
|
|
|
2016-06-20 16:49:22 +10:00
|
|
|
for (const auto &t: TESTS) {
|
|
|
|
tap.expect_eq (
|
|
|
|
t.adler,
|
2018-08-05 14:42:02 +10:00
|
|
|
a (cruft::view {t.data}.template cast<const uint8_t*> ()),
|
2021-04-13 16:05:08 +10:00
|
|
|
"adler checksum: {:s}", t.msg
|
2016-06-20 16:49:22 +10:00
|
|
|
);
|
|
|
|
|
|
|
|
tap.expect_eq (
|
|
|
|
t.bsd,
|
2018-08-05 14:42:02 +10:00
|
|
|
b (cruft::view {t.data}.template cast<const uint8_t*> ()),
|
2021-04-13 16:05:08 +10:00
|
|
|
"bsdsum checksum: {:s}", t.msg);
|
2011-11-04 16:56:25 +11:00
|
|
|
}
|
|
|
|
|
2017-05-22 13:55:21 +10:00
|
|
|
return tap.status ();
|
2011-11-04 16:56:25 +11:00
|
|
|
}
|