Added CRC initializing constructor

This commit is contained in:
Pavel Kirienko 2014-02-11 12:36:54 +04:00
parent 78ff31f9ad
commit d4e4f1a416
2 changed files with 10 additions and 3 deletions

View File

@ -24,6 +24,12 @@ public:
: value_(0x0000)
{ }
Crc16(const uint8_t* bytes, int len)
: value_(0x0000)
{
add(bytes, len);
}
uint16_t add(uint8_t byte);
uint16_t add(const uint8_t* bytes, int len);

View File

@ -9,9 +9,7 @@
TEST(Crc16, Correctness)
{
using uavcan::Crc16;
Crc16 crc;
uavcan::Crc16 crc;
ASSERT_EQ(0x0000, crc.get());
@ -22,4 +20,7 @@ TEST(Crc16, Correctness)
crc.add(reinterpret_cast<const uint8_t*>("Foobar"), 6);
ASSERT_EQ(53881, crc.get());
// Initializing constructor
ASSERT_EQ(crc.get(), uavcan::Crc16(reinterpret_cast<const uint8_t*>("123Foobar"), 9).get());
}