测试:GoogleTest 全面单测(10工况设备表/故障检测/协议/消息/SQLite读回)+ UDP→SQLite 集成测试,src 零改动
build-test-deploy / ci (push) Failing after 11m45s

This commit is contained in:
zjk
2026-08-14 21:29:57 +08:00
parent f51a3ac750
commit de298414ff
14 changed files with 1286 additions and 13 deletions
+45
View File
@@ -0,0 +1,45 @@
//=======================================================================
// FaultMapTest: 锂电池/配电故障码表的完整性(码值唯一、级别正确)
// 不改动生产代码;仅验证 faultCode.h 中的静态表。
//=======================================================================
#include <gtest/gtest.h>
#include <set>
#include "faultCode.h"
TEST(FaultMapTest, BatteryFaultMap)
{
const size_t n = sizeof(batfaultMap) / sizeof(batfaultMap[0]);
ASSERT_EQ(n, 54u) << "batfaultMap 应有 54 条";
std::set<uint8_t> codes;
for (size_t i = 0; i < n; ++i) {
EXPECT_EQ(batfaultMap[i].id, (int)i + 1) << "id 必须从 1 连续";
EXPECT_GE(batfaultMap[i].level, 1);
EXPECT_LE(batfaultMap[i].level, 4);
EXPECT_TRUE(batfaultMap[i].desc != nullptr && batfaultMap[i].desc[0] != '\0')
<< "desc 不能为空, id=" << i + 1;
EXPECT_TRUE(codes.insert(batfaultMap[i].code).second)
<< "重复故障码 0x" << std::hex << (int)batfaultMap[i].code;
}
// 抽样:4级故障码在 0xCx,3级在 0x8x,1级在 0x0x-0x1x
EXPECT_EQ(batfaultMap[0].code, 0xC1); // id1 四级 MBMS绝缘故障
EXPECT_EQ(batfaultMap[9].code, 0x81); // id10 三级
EXPECT_EQ(batfaultMap[40].code, 0x01); // id41 一级
}
TEST(FaultMapTest, DistributionFaultMap)
{
const size_t n = sizeof(disfaultMap) / sizeof(disfaultMap[0]);
ASSERT_EQ(n, 45u) << "disfaultMap 应有 45 条";
std::set<int> codes;
for (size_t i = 0; i < n; ++i) {
EXPECT_EQ(disfaultMap[i].id, (int)i + 1) << "id 必须从 1 连续";
EXPECT_GE(disfaultMap[i].level, 1);
EXPECT_LE(disfaultMap[i].level, 4);
EXPECT_TRUE(disfaultMap[i].desc != nullptr && disfaultMap[i].desc[0] != '\0');
EXPECT_TRUE(codes.insert(disfaultMap[i].code).second)
<< "重复故障码 " << disfaultMap[i].code;
}
// 断路器脱扣基本是 4 级故障
EXPECT_EQ(disfaultMap[0].level, 3); // id1 燃料电池断路器 3级
EXPECT_EQ(disfaultMap[1].level, 4); // id2 动力锂电池断路器 4级
}