#include "crc.h" #include #include class TCrcTest: public TTestBase { UNIT_TEST_SUITE(TCrcTest); UNIT_TEST(TestCrc16) UNIT_TEST(TestCrc32) UNIT_TEST(TestCrc64) UNIT_TEST_SUITE_END(); private: inline void TestCrc16() { const ui16 expected[] = { 41719, 57001, 53722, 3276}; Run(expected); } inline void TestCrc32() { const ui32 expected[] = { 688229491UL, 3543112608UL, 4127534015UL, 3009909774UL}; Run(expected); } inline void TestCrc64() { const ui64 expected[] = { 12116107829328640258ULL, 18186277744016380552ULL, 249923753044811734ULL, 7852471725963920356ULL}; Run(expected); } private: template inline void Run(const T* expected) { ui8 buf[256]; for (size_t i = 0; i < 256; ++i) { buf[i] = i; } Test(buf, 256, expected[0]); Test(buf, 255, expected[1]); Test(buf, 254, expected[2]); Test(buf, 253, expected[3]); } template inline void Test(const void* data, size_t len, T expected) { const T res = Crc(data, len); try { UNIT_ASSERT_EQUAL(res, expected); } catch (...) { Cerr << res << Endl; throw; } } }; UNIT_TEST_SUITE_REGISTRATION(TCrcTest);