Repository navigation
test(GenerateDevice): 重写设备生成模块单元测试补全覆盖率 - #909
Conversation
Reviewer's GuideThis test-only PR rewrites and completes GenerateDevice Google Tests with deterministic stubbing for Qt6 DBus, hardware commands, and filesystem access, covering all five target modules and reporting 100% line/function coverage; it also normalizes copyright headers across 45 test files. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Warning
详情 {
"dmidecode": {
"deepin-devicemanager/tests/src/GenerateDevice/ut_armgenerator.cpp": [
" static const QList<QMap<QString, QString>> dmidecode = {",
" if (key == QStringLiteral(\"dmidecode4\"))",
" return dmidecode;"
],
"deepin-devicemanager/tests/src/GenerateDevice/ut_x86generator.cpp": [
" static const QList<QMap<QString, QString>> dmidecode = {",
" if (key == QStringLiteral(\"dmidecode4\"))",
" return dmidecode;"
]
},
"lshw": {
"deepin-devicemanager/tests/src/GenerateDevice/ut_armgenerator.cpp": [
" static const QList<QMap<QString, QString>> lshwCpu = {",
" if (key == QStringLiteral(\"lshw_cpu\"))",
" return lshwCpu;",
"// generatorComputerDevice \u5168\u8def\u5f84\uff1a\u6253\u6869 cmdInfo \u63d0\u4f9b os-release \u4e0e lshw_system \u6570\u636e\uff0c",
" static const QList<QMap<QString, QString>> lshwSystem = {",
" if (key == QStringLiteral(\"lshw_system\"))",
" return lshwSystem;"
],
"deepin-devicemanager/tests/src/GenerateDevice/ut_dbusinterface.cpp": [
" const bool ok = iface->getInfo(QStringLiteral(\"lshw\"), info);"
],
"deepin-devicemanager/tests/src/GenerateDevice/ut_x86generator.cpp": [
" static const QList<QMap<QString, QString>> lshwCpu = {",
" if (key == QStringLiteral(\"lshw_cpu\"))",
" return lshwCpu;",
"// generatorComputerDevice \u5168\u8def\u5f84\uff1a\u6253\u6869 cmdInfo \u63d0\u4f9b os-release \u4e0e lshw_system \u6570\u636e\uff0c",
" static const QList<QMap<QString, QString>> lshwSystem = {",
" if (key == QStringLiteral(\"lshw_system\"))",
" return lshwSystem;"
]
}
} |
Generated by qt-autotest-generator skill. Rewrite ut_dbusinterface/ut_customgenerator/ut_devicefactory and patch ut_x86generator/ut_armgenerator: 46 cases, all passing. Stub QDBusAbstractInterface::doCall/doAsyncCall via addr_pri (Qt6 call/ asyncCall are inline forwarders, so the previous stubs on the inline entries never took effect), plus CommonTools/Common/DeviceManager:: cmdInfo and QProcess stubs; no real DBus, network or device environment is needed. Target files reach 100% line coverage (133/133) and 100% function coverage (11/11). Baseline: upstream/master @ f2d46ee; GenerateDevice is unchanged at current master 0f1d52e, all 46 cases pass on the rebased branch. Log: 重写设备生成模块单元测试, 46 条用例全部通过 Influence: 仅测试代码, 不影响业务逻辑
Unify every "Copyright (C)" header line under tests/ to the single
form "// Copyright (C) 2019-2026 UnionTech Software Technology
Co.,Ltd", fixing the broken variants left by earlier submissions
("2019-2026 ~ 2020", "2019-2026 ~ 2026", "2019 ~ 2026 Uniontech",
legacy "2019 ~ 2020"). Header comment lines only, no code change.
Log: 统一单元测试文件版权头格式, 仅头部注释变更
Influence: 仅测试代码, 不影响业务逻辑
|
Warning
详情 {
"dmidecode": {
"deepin-devicemanager/tests/src/GenerateDevice/ut_armgenerator.cpp": [
" static const QList<QMap<QString, QString>> dmidecode = {",
" if (key == QStringLiteral(\"dmidecode4\"))",
" return dmidecode;"
],
"deepin-devicemanager/tests/src/GenerateDevice/ut_x86generator.cpp": [
" static const QList<QMap<QString, QString>> dmidecode = {",
" if (key == QStringLiteral(\"dmidecode4\"))",
" return dmidecode;"
]
},
"lshw": {
"deepin-devicemanager/tests/src/GenerateDevice/ut_armgenerator.cpp": [
" static const QList<QMap<QString, QString>> lshwCpu = {",
" if (key == QStringLiteral(\"lshw_cpu\"))",
" return lshwCpu;",
"// generatorComputerDevice \u5168\u8def\u5f84\uff1a\u6253\u6869 cmdInfo \u63d0\u4f9b os-release \u4e0e lshw_system \u6570\u636e\uff0c",
" static const QList<QMap<QString, QString>> lshwSystem = {",
" if (key == QStringLiteral(\"lshw_system\"))",
" return lshwSystem;"
],
"deepin-devicemanager/tests/src/GenerateDevice/ut_dbusinterface.cpp": [
" const bool ok = iface->getInfo(QStringLiteral(\"lshw\"), info);"
],
"deepin-devicemanager/tests/src/GenerateDevice/ut_x86generator.cpp": [
" static const QList<QMap<QString, QString>> lshwCpu = {",
" if (key == QStringLiteral(\"lshw_cpu\"))",
" return lshwCpu;",
"// generatorComputerDevice \u5168\u8def\u5f84\uff1a\u6253\u6869 cmdInfo \u63d0\u4f9b os-release \u4e0e lshw_system \u6570\u636e\uff0c",
" static const QList<QMap<QString, QString>> lshwSystem = {",
" if (key == QStringLiteral(\"lshw_system\"))",
" return lshwSystem;"
]
}
} |
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 语法正确,逻辑清晰 ✅ 通过 潜在问题: 建议: [] 2. 代码质量 ✅评价: 代码结构清晰,注释完整 ✅ 通过 潜在问题: 建议: ['移除 SetUp() 中的 Stub 创建代码,或改为成员变量使其生命周期覆盖整个测试', '将 ut_cmdinfo_cpu/ut_cmdinfo_computer 提取到共享测试工具文件,消除重复', '移除不可达的三元表达式 nullptr 分支,直接调用 getDeviceGenerator()', '使用 std::unique_ptr 替代裸指针 + 手动 delete,利用 RAII 管理生命周期', '将 static 捕获变量改为测试夹具成员变量,消除并行执行风险', '在测试结束前手动 delete mp_Iface 或添加注释说明泄漏为已知限制'] 3. 代码性能 ✅评价: 性能良好,资源使用合理 ✅ 通过 潜在问题: 建议: [] 4. 代码安全 🔒评价: 存在0个安全漏洞 ✅ 通过
安全漏洞详情: 建议: [] 💡 改进建议代码示例// ut_devicefactory.cpp — 修复 SetUp 死代码 + 裸指针改 unique_ptr
class UT_DeviceFactory : public ::testing::Test
{
protected:
void SetUp() override
{
ut_arch_val = QStringLiteral("x86_64");
ut_type_val.clear();
// 移除 SetUp 中的 Stub — 每个测试自行创建,确保桩在测试体内生效
}
void TearDown() override { }
};
TEST_F(UT_DeviceFactory, GetDeviceGenerator_ArchX86_ReturnsX86Generator)
{
// Arrange
ut_arch_val = QStringLiteral("x86_64");
Stub stub;
stub.set(ADDR(Common, getArch), ut_Common_getArch);
stub.set(ADDR(Common, boardVendorType), ut_Common_boardVendorType);
// Act — 使用 unique_ptr 管理 returned generator 的生命周期
std::unique_ptr<DeviceGenerator> gen(DeviceFactory::getDeviceGenerator());
// Assert
EXPECT_NE(gen, nullptr);
EXPECT_NE(dynamic_cast<X86Generator *>(gen.get()), nullptr);
// 无需手动 delete,RAII 自动释放
}
// ut_devicefactory.cpp — 修复不可达三元表达式
TEST_F(UT_DeviceFactory, Constructor_CreateInstance_UsableAfterConstruction)
{
// Arrange
ut_arch_val = QStringLiteral("x86_64");
Stub stub;
stub.set(ADDR(Common, getArch), ut_Common_getArch);
stub.set(ADDR(Common, boardVendorType), ut_Common_boardVendorType);
// Act
std::unique_ptr<DeviceFactory> factory(new DeviceFactory());
std::unique_ptr<DeviceGenerator> gen(DeviceFactory::getDeviceGenerator());
// Assert
EXPECT_NE(factory, nullptr);
EXPECT_NE(gen, nullptr);
}本报告由 AI 代码审查工具自动生成 |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: add-uos, lzwind The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/forcemerge |
|
This pr force merged! (status: unstable) |
单元测试重写:GenerateDevice(Issue V-6209)
基于
upstream/master(7d060967)重写/补齐 GenerateDevice 模块的 Google Test 单元测试:src/GenerateDevice/DBusInterface.cppsrc/GenerateDevice/CustomGenerator.cppsrc/GenerateDevice/DeviceFactory.cppsrc/GenerateDevice/X86Generator.cppsrc/GenerateDevice/ArmGenerator.cpp变更内容(仅测试源码文件,共 46 个,tests/src/ 下)
ut_dbusinterface / ut_customgenerator / ut_devicefactory,补强ut_x86generator / ut_armgenerator:共 46 个用例全部通过QDBusInterface::call/asyncCall为内联转发,旧用例对内联入口打桩从未生效;改经 addr_pri 桩私有非内联实现doCall/doAsyncCall,并打桩CommonTools/Common/DeviceManager::cmdInfo/QProcess,无真实 DBus/网络/设备依赖// Copyright (C) 2019-2026 UnionTech Software Technology Co.,Ltd(修复2019-2026 ~ 2020、2019 ~ 2026 Uniontech、legacy2019 ~ 2020等历史变体,仅头注释变更,单独 commit)验证结果
deepin-devicemanager-test全量构建通过(Qt6/DTK6,Debug+覆盖率)