google test
This commit is contained in:
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
std::vector<std::uint8_t> BuildMinimalFrame(std::uint8_t channel_count)
|
std::vector<std::uint8_t> BuildMinimalFrame(std::uint8_t channel_count, std::uint32_t frame_index)
|
||||||
{
|
{
|
||||||
constexpr std::size_t kSamplesPerFrame = 5;
|
constexpr std::size_t kSamplesPerFrame = 5;
|
||||||
constexpr std::uint8_t kHeader = 0xAA;
|
constexpr std::uint8_t kHeader = 0xAA;
|
||||||
@@ -24,10 +24,10 @@ std::vector<std::uint8_t> BuildMinimalFrame(std::uint8_t channel_count)
|
|||||||
frame[offset++] = kHeader;
|
frame[offset++] = kHeader;
|
||||||
|
|
||||||
// index, little endian
|
// index, little endian
|
||||||
frame[offset++] = 0x01;
|
frame[offset++] = static_cast<std::uint8_t>(frame_index & 0xFF);
|
||||||
frame[offset++] = 0x00;
|
frame[offset++] = static_cast<std::uint8_t>((frame_index >> 8) & 0xFF);
|
||||||
frame[offset++] = 0x00;
|
frame[offset++] = static_cast<std::uint8_t>((frame_index >> 16) & 0xFF);
|
||||||
frame[offset++] = 0x00;
|
frame[offset++] = static_cast<std::uint8_t>((frame_index >> 24) & 0xFF);
|
||||||
|
|
||||||
// payload length, big endian
|
// payload length, big endian
|
||||||
frame[offset++] = static_cast<std::uint8_t>((payload_length >> 8) & 0xFF);
|
frame[offset++] = static_cast<std::uint8_t>((payload_length >> 8) & 0xFF);
|
||||||
@@ -57,6 +57,11 @@ std::vector<std::uint8_t> BuildMinimalFrame(std::uint8_t channel_count)
|
|||||||
return frame;
|
return frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<std::uint8_t> BuildMinimalFrame(std::uint8_t channel_count)
|
||||||
|
{
|
||||||
|
return BuildMinimalFrame(channel_count, 1U);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
void MinimalExampleFor8ChParser()
|
void MinimalExampleFor8ChParser()
|
||||||
|
|||||||
@@ -43,8 +43,9 @@ private:
|
|||||||
/// 构建最小帧数据的辅助函数
|
/// 构建最小帧数据的辅助函数
|
||||||
/// 生成符合 XYParser 协议格式的测试帧数据
|
/// 生成符合 XYParser 协议格式的测试帧数据
|
||||||
/// @param channel_count 通道数量
|
/// @param channel_count 通道数量
|
||||||
|
/// @param frame_index 帧索引,小端写入标签区前 4 字节
|
||||||
/// @return 包含完整帧数据的字节向量
|
/// @return 包含完整帧数据的字节向量
|
||||||
std::vector<std::uint8_t> BuildMinimalFrame(std::uint8_t channel_count)
|
std::vector<std::uint8_t> BuildMinimalFrame(std::uint8_t channel_count, std::uint32_t frame_index)
|
||||||
{
|
{
|
||||||
constexpr std::size_t kSamplesPerFrame = 5; ///< 每帧采样数
|
constexpr std::size_t kSamplesPerFrame = 5; ///< 每帧采样数
|
||||||
constexpr std::uint8_t kHeader = 0xAA; ///< 帧头标记
|
constexpr std::uint8_t kHeader = 0xAA; ///< 帧头标记
|
||||||
@@ -62,11 +63,11 @@ std::vector<std::uint8_t> BuildMinimalFrame(std::uint8_t channel_count)
|
|||||||
// 写入帧头
|
// 写入帧头
|
||||||
frame[offset++] = kHeader;
|
frame[offset++] = kHeader;
|
||||||
|
|
||||||
// 写入标签数据(版本号等)
|
// 写入标签数据中的帧索引(小端序)
|
||||||
frame[offset++] = 0x01;
|
frame[offset++] = static_cast<std::uint8_t>(frame_index & 0xFF);
|
||||||
frame[offset++] = 0x00;
|
frame[offset++] = static_cast<std::uint8_t>((frame_index >> 8) & 0xFF);
|
||||||
frame[offset++] = 0x00;
|
frame[offset++] = static_cast<std::uint8_t>((frame_index >> 16) & 0xFF);
|
||||||
frame[offset++] = 0x00;
|
frame[offset++] = static_cast<std::uint8_t>((frame_index >> 24) & 0xFF);
|
||||||
|
|
||||||
// 写入负载长度(大端序)
|
// 写入负载长度(大端序)
|
||||||
frame[offset++] = static_cast<std::uint8_t>((payload_length >> 8) & 0xFF);
|
frame[offset++] = static_cast<std::uint8_t>((payload_length >> 8) & 0xFF);
|
||||||
@@ -99,6 +100,12 @@ std::vector<std::uint8_t> BuildMinimalFrame(std::uint8_t channel_count)
|
|||||||
return frame;
|
return frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 为现有调用点保留默认 frame_index=1 的便捷重载
|
||||||
|
std::vector<std::uint8_t> BuildMinimalFrame(std::uint8_t channel_count)
|
||||||
|
{
|
||||||
|
return BuildMinimalFrame(channel_count, 1U);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
/// 测试:创建解析器时拒绝不支持的通道数
|
/// 测试:创建解析器时拒绝不支持的通道数
|
||||||
@@ -336,8 +343,8 @@ TEST(XYParserApiTests, FeedParsesMultipleFrames)
|
|||||||
XYParser_SetBypassChecksum(parser.get(), 1);
|
XYParser_SetBypassChecksum(parser.get(), 1);
|
||||||
|
|
||||||
// 构建两个连续的帧
|
// 构建两个连续的帧
|
||||||
const std::vector<std::uint8_t> frame1 = BuildMinimalFrame(8);
|
const std::vector<std::uint8_t> frame1 = BuildMinimalFrame(8, 1U);
|
||||||
const std::vector<std::uint8_t> frame2 = BuildMinimalFrame(8);
|
const std::vector<std::uint8_t> frame2 = BuildMinimalFrame(8, 2U);
|
||||||
|
|
||||||
std::vector<std::uint8_t> combined(frame1);
|
std::vector<std::uint8_t> combined(frame1);
|
||||||
combined.insert(combined.end(), frame2.begin(), frame2.end());
|
combined.insert(combined.end(), frame2.begin(), frame2.end());
|
||||||
@@ -368,7 +375,7 @@ TEST(XYParserApiTests, FeedIncrementsFrameIndex)
|
|||||||
int total_frames = 0;
|
int total_frames = 0;
|
||||||
|
|
||||||
for (int i = 0; i < 3; ++i) {
|
for (int i = 0; i < 3; ++i) {
|
||||||
const std::vector<std::uint8_t> frame = BuildMinimalFrame(8);
|
const std::vector<std::uint8_t> frame = BuildMinimalFrame(8, static_cast<std::uint32_t>(i + 1));
|
||||||
const int count = XYParser_Feed(
|
const int count = XYParser_Feed(
|
||||||
parser.get(),
|
parser.get(),
|
||||||
frame.data(),
|
frame.data(),
|
||||||
@@ -477,4 +484,4 @@ TEST(XYParserApiTests, GetLastErrorReturnsMessageForNullParser)
|
|||||||
{
|
{
|
||||||
EXPECT_EQ(std::string(XYParser_GetLastError(nullptr)), std::string("invalid parser handle"));
|
EXPECT_EQ(std::string(XYParser_GetLastError(nullptr)), std::string("invalid parser handle"));
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user