libcruft-util/test/checksum.cpp
Danny Robson 6560353cb0 Add some simple checksum algorithms
* adler
* bsdsum
* crc
* fletcher
2011-11-04 17:04:42 +11:00

33 lines
667 B
C++

#include "adler.hpp"
#include "bsdsum.hpp"
#include "types.hpp"
#include <cstdlib>
#include <cstring>
using namespace std;
static const char *ALPHABET = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
static const struct {
uint32_t adler;
uint16_t bsd;
const char *data;
size_t size;
} TESTS[] = {
{ 0xDF5B150C, 0x52FB, ALPHABET, strlen (ALPHABET) }
};
int
main (int, char**) {
for (unsigned i = 0; i < elems (TESTS); ++i) {
check_eq (TESTS[i].adler, adler32 (TESTS[i].data, TESTS[i].size));
check_eq (TESTS[i].bsd, bsdsum (TESTS[i].data, TESTS[i].size));
}
return EXIT_SUCCESS;
}