2021-08-03 19:05:01 -07:00
|
|
|
#include "pch.h"
|
2020-11-15 09:27:47 -08:00
|
|
|
#include "tunerstudio_io.h"
|
|
|
|
|
2021-03-28 06:06:36 -07:00
|
|
|
static uint8_t st5TestBuffer[16000];
|
|
|
|
|
|
|
|
class MockTsChannel : public TsChannelBase {
|
|
|
|
public:
|
2021-09-18 12:33:14 -07:00
|
|
|
MockTsChannel() : TsChannelBase("Test") { }
|
|
|
|
|
2021-03-28 06:06:36 -07:00
|
|
|
void write(const uint8_t* buffer, size_t size) override {
|
|
|
|
memcpy(&st5TestBuffer[writeIdx], buffer, size);
|
|
|
|
writeIdx += size;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t readTimeout(uint8_t* buffer, size_t size, int timeout) override {
|
|
|
|
// nothing to do here
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
void reset() {
|
|
|
|
writeIdx = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t writeIdx = 0;
|
|
|
|
};
|
2020-11-15 09:27:47 -08:00
|
|
|
|
|
|
|
#define CODE 2
|
|
|
|
#define PAYLOAD "123"
|
|
|
|
#define SIZE strlen(PAYLOAD)
|
|
|
|
|
2021-03-28 06:06:36 -07:00
|
|
|
static void assertCrcPacket(MockTsChannel& dut) {
|
|
|
|
ASSERT_EQ(dut.writeIdx, SIZE + 7);
|
2020-11-15 09:27:47 -08:00
|
|
|
|
|
|
|
// todo: proper uint16 comparison
|
|
|
|
ASSERT_EQ(st5TestBuffer[0], 0);
|
|
|
|
ASSERT_EQ(st5TestBuffer[1], SIZE + 1);
|
|
|
|
|
|
|
|
ASSERT_EQ(st5TestBuffer[2], CODE);
|
|
|
|
|
|
|
|
ASSERT_EQ(memcmp(&st5TestBuffer[3], PAYLOAD, SIZE), 0);
|
|
|
|
|
|
|
|
|
|
|
|
// todo: proper uint32 comparison
|
|
|
|
ASSERT_EQ(st5TestBuffer[6], 252);
|
|
|
|
ASSERT_EQ(st5TestBuffer[7], 68);
|
|
|
|
ASSERT_EQ(st5TestBuffer[8], 173);
|
|
|
|
ASSERT_EQ(st5TestBuffer[9], 87);
|
2020-11-15 09:36:07 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(binary, testWriteCrc) {
|
2021-03-28 06:06:36 -07:00
|
|
|
MockTsChannel test;
|
2020-11-15 09:27:47 -08:00
|
|
|
|
2020-11-15 13:59:02 -08:00
|
|
|
// Let it pick which impl (small vs large) to use
|
2021-03-28 06:06:36 -07:00
|
|
|
test.reset();
|
2021-02-19 17:48:21 -08:00
|
|
|
test.writeCrcPacket(CODE, (const uint8_t*)PAYLOAD, SIZE);
|
2021-03-28 06:06:36 -07:00
|
|
|
assertCrcPacket(test);
|
2020-11-15 09:36:07 -08:00
|
|
|
|
2020-11-15 13:59:02 -08:00
|
|
|
// Force the large impl
|
2021-03-28 06:06:36 -07:00
|
|
|
test.reset();
|
2021-02-19 17:48:21 -08:00
|
|
|
test.writeCrcPacket(CODE, (const uint8_t*)PAYLOAD, SIZE);
|
2021-03-28 06:06:36 -07:00
|
|
|
assertCrcPacket(test);
|
2020-11-15 09:36:07 -08:00
|
|
|
|
2020-11-15 13:59:02 -08:00
|
|
|
// Force the small impl
|
2021-03-28 06:06:36 -07:00
|
|
|
test.reset();
|
2021-02-19 17:48:21 -08:00
|
|
|
test.writeCrcPacket(CODE, (const uint8_t*)PAYLOAD, SIZE);
|
2021-03-28 06:06:36 -07:00
|
|
|
assertCrcPacket(test);
|
2020-11-15 09:27:47 -08:00
|
|
|
}
|