test(unittest): add unit tests for driveritem, PageDriverBackupInfo and PageDriverRestoreInfo - #772
Conversation
Reviewer's GuideAdds 52 offscreen GTest cases covering driver item widgets plus backup and restore page initialization, UI state transitions, table population/clearing, and driver operations, with Qt-version-aware event tests and test-specific ignore configuration. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
…nd PageDriverRestoreInfo
|
[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 |
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 良好 ✅ 通过 潜在问题:
建议: 修复 EnterEvent 测试中冗余的条件编译分支,确保 Qt5/Qt6 路径执行不同的代码逻辑 2. 代码质量 ✅评价: 良好 ✅ 通过 潜在问题:
建议: 1.替换无意义断言为验证 item 实际状态的断言,如检查 item->name() 返回值 3. 代码性能 ✅评价: 优秀 ✅ 通过 潜在问题: 建议: 测试代码性能良好,SetUp/TearDown 模式规范,无不必要的资源消耗 4. 代码安全 🔒评价: 优秀 ✅ 通过
安全漏洞详情: 建议: 测试代码无安全风险,无用户输入处理、网络操作、加密操作或敏感信息 💡 改进建议代码示例// 修复1: SetName 测试应验证 item 实际状态
TEST_F(UT_DriverNameItem, SetName_ValidString_NameSetSuccessfully)
{
QString testName = "TestDriver";
m_item->setName(testName);
// 验证 item 实际设置的名称,而非局部变量
EXPECT_EQ(testName.toStdString(), m_item->name().toStdString());
}
// 修复2: 移除冗余条件编译
TEST_F(UT_DriverOperationItem, EnterEvent_Qt6_NoCrash)
{
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
QEnterEvent event(QPointF(0, 0), QPointF(0, 0), QPointF(0, 0));
#else
QEvent event(QEvent::Enter);
#endif
m_installItem->enterEvent(&event); // 只需调用一次
EXPECT_NE(nullptr, m_installItem);
}本报告由 AI 代码审查工具自动生成 |
|
/forcemerge |
|
This pr force merged! (status: unstable) |
Add 52 GTest cases covering 3 modules in deepin-devicemanager:
src/Widget/driveritem.cpp: DriverCheckItem, DriverNameItem, DriverLabelItem, DriverStatusItem, DriverOperationItem (30 cases)src/Page/PageDriverBackupInfo.cpp: PageDriverBackupInfo (14 cases)src/Page/PageDriverRestoreInfo.cpp: PageDriverRestoreInfo (8 cases)All tests pass with
QT_QPA_PLATFORM=offscreen.Summary by Sourcery
Tests: