libcruft-util/test/checksum.cpp

38 lines
852 B
C++
Raw Normal View History

#include "hash/adler.hpp"
#include "hash/bsdsum.hpp"
#include "types.hpp"
2015-04-13 16:45:56 +10:00
#include "tap.hpp"
#include "debug.hpp"
#include <cstdlib>
#include <cstring>
using namespace std;
static const char *ALPHABET = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
static const struct {
uint32_t adler;
uint16_t bsd;
2014-09-11 15:44:03 +10:00
const char *data;
size_t size;
} TESTS[] = {
2014-09-11 15:44:03 +10:00
{ 0xDF5B150C, 0x52FB, ALPHABET, strlen (ALPHABET) },
{ 0x11E60398, 0x3DC8, "Wikipedia", strlen ("Wikipedia") }
};
int
main (int, char**) {
2015-04-13 16:45:56 +10:00
util::TAP::logger tap;
for (unsigned i = 0; i < elems (TESTS); ++i) {
2015-04-13 16:45:56 +10:00
tap.expect_eq (TESTS[i].adler, adler32 (TESTS[i].data, TESTS[i].size), "adler checksum");
tap.expect_eq (TESTS[i].bsd, bsdsum (TESTS[i].data, TESTS[i].size), "bsdsum checksum");
}
return EXIT_SUCCESS;
}