mirror of
https://github.com/gityf/crc.git
synced 2026-08-12 20:32:20 +08:00
+11
-6
@@ -18,14 +18,19 @@ TEST(CRC8Test, BasicTest)
|
||||
{
|
||||
const char* inData = "123456789";
|
||||
uint8_t expect = 0xa2;
|
||||
EXPECT_EQ(crc8_msb(inData, 9), expect);
|
||||
EXPECT_EQ(crc8_msb(reinterpret_cast<const unsigned char *>(inData), 9), expect);
|
||||
|
||||
const char* data = "Hello World!!!";
|
||||
expect = 0x68;
|
||||
EXPECT_EQ(crc8_msb(data, strlen(data)), expect);
|
||||
EXPECT_EQ(crc8_msb(reinterpret_cast<const unsigned char *>(data), strlen(data)), expect);
|
||||
|
||||
expect = 0x2c;
|
||||
EXPECT_EQ(crc8_lsb(data, strlen(data)), expect);
|
||||
EXPECT_EQ(crc8_lsb(reinterpret_cast<const unsigned char *>(data), strlen(data)), expect);
|
||||
|
||||
const uint8_t buffer[] = {0xb0, 0, 0, 0, 0, 0, 0};
|
||||
|
||||
expect = 0x1a;
|
||||
EXPECT_EQ(crc8_lsb(buffer, sizeof(buffer)), expect);
|
||||
}
|
||||
|
||||
TEST(CRC16Test, BasicTest)
|
||||
@@ -33,7 +38,7 @@ TEST(CRC16Test, BasicTest)
|
||||
const char* inData = "123456789";
|
||||
uint16_t expect = 0x31C3;
|
||||
|
||||
EXPECT_EQ(crc16(inData, 9), expect);
|
||||
EXPECT_EQ(crc16(reinterpret_cast<const unsigned char *>(inData), 9), expect);
|
||||
}
|
||||
|
||||
TEST(CRC32Test, BasicTest)
|
||||
@@ -41,7 +46,7 @@ TEST(CRC32Test, BasicTest)
|
||||
const char* inData = "123456789";
|
||||
uint32_t expect = 0xCBF43926;
|
||||
|
||||
EXPECT_EQ(crc32(inData, 9), expect);
|
||||
EXPECT_EQ(crc32(reinterpret_cast<const unsigned char *>(inData), 9), expect);
|
||||
}
|
||||
|
||||
TEST(CRC64Test, BasicTest)
|
||||
@@ -49,7 +54,7 @@ TEST(CRC64Test, BasicTest)
|
||||
const char* inData = "123456789";
|
||||
|
||||
uint64_t expect = 0xe9c6d914c4b8d9caL;
|
||||
EXPECT_EQ(crc64(inData, 9), expect);
|
||||
EXPECT_EQ(crc64(reinterpret_cast<const unsigned char *>(inData), 9), expect);
|
||||
}
|
||||
|
||||
TEST(CRC8PolyTest, BasicTest)
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
#include "test_harness.h"
|
||||
|
||||
#include <string>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
|
||||
namespace common {
|
||||
namespace test {
|
||||
@@ -80,9 +77,15 @@ namespace common {
|
||||
startMs_, endMs, endMs - startMs_);
|
||||
}
|
||||
long TestPerfomence::NowMs() {
|
||||
struct timeval timeNow;
|
||||
gettimeofday(&timeNow, NULL);
|
||||
return (timeNow.tv_sec) * 1000 + timeNow.tv_usec / 1000;
|
||||
timespec timeNow{};
|
||||
|
||||
if (timespec_get(&timeNow, TIME_UTC) != TIME_UTC)
|
||||
{
|
||||
fputs("timespec_get failed!", stderr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return static_cast<long>(timeNow.tv_sec * 1000 + timeNow.tv_nsec / 1000);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ class Tester {
|
||||
fname_, line_, ss_.str().c_str());
|
||||
fprintf(stderr, "\033[0m");
|
||||
errCount++;
|
||||
//exit(1);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ class Tester {
|
||||
template <class X, class Y> \
|
||||
Tester& name(const X& x, const Y& y) { \
|
||||
if (! (x op y)) { \
|
||||
ss_ << " failed: Expect:" << x << (" " #op " ") << "Actual:" << y; \
|
||||
ss_ << " failed: Expect:" << std::hex << uint64_t {x} << (" " #op " ") << "Actual:" << std::hex << uint64_t {y}; \
|
||||
ok_ = false; \
|
||||
} \
|
||||
return *this; \
|
||||
|
||||
Reference in New Issue
Block a user