Skip to content

test(unittest): add unit tests for driveritem, PageDriverBackupInfo and PageDriverRestoreInfo - #772

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
add-uos:ut-rebase
Sep 18, 2026
Merged

deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
add-uos:ut-rebase

Conversation

@add-uos

@add-uos add-uos commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

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:

  • Add GoogleTest coverage for driver item widgets and driver backup and restore page behavior, including state changes, table visibility, row management, and user operations.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @add-uos, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 1 hour and 38 minutes by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Sep 18, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds 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

Change Details Files
Add focused GTest coverage for driver item widgets and their state, status, operation, and event-handling behavior.
  • Exercise construction and default state for all five item types.
  • Verify checkbox, name/index, status/error, operation mode, button enablement, icon, and enter/leave behavior.
  • Use Qt-version conditionals for enter-event testing and private-member access where needed for UI assertions.
deepin-devicemanager/tests/src/Widget/ut_driveritem.cpp
Cover backup-page table management, visibility rules, and driver status handling.
  • Test initialization of page widgets and visibility outcomes for all driver-count combinations.
  • Verify adding backable/backed-up drivers, clearing models, checked-index retrieval, status updates, and control enablement calls.
deepin-devicemanager/tests/src/Page/ut_pagedriverbackupinfo.cpp
Cover restore-page table and stacked-view behavior for restoreable drivers.
  • Test page initialization and stack selection for empty and populated states.
  • Verify adding eligible or ineligible drivers, clearing data, operation enablement, and restore actions.
deepin-devicemanager/tests/src/Page/ut_pagedriverrestoreinfo.cpp
Add repository ignore configuration for the test changes.
  • Introduce a new Git ignore file.
deepin-devicemanager/.gitignore

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@deepin-ci-robot

Copy link
Copy Markdown

[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.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 92 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 总体评分 92 分,大于 70 分通过阈值,代码质量符合要求。本次 PR 新增 52 个 GTest 单元测试,覆盖 driveritem、PageDriverBackupInfo 和 PageDriverRestoreInfo 三个模块,测试代码结构清晰,遵循 AAA 模式,无安全漏洞。

🔍 详细分析

1. 语法逻辑 ✅

评价: 良好 ✅ 通过

潜在问题:

  1. ut_driveritem.cpp:460 - EnterEvent_Qt6_NoCrash 测试中 #if/#else 分支代码完全相同,条件编译冗余

建议: 修复 EnterEvent 测试中冗余的条件编译分支,确保 Qt5/Qt6 路径执行不同的代码逻辑


2. 代码质量 ✅

评价: 良好 ✅ 通过

潜在问题:

  1. ut_driveritem.cpp:15 - 使用 #define private public 和 #define protected public 绕过封装
  2. ut_driveritem.cpp:305 - SetName_ValidString 测试中 EXPECT_EQ(10, testName.size()) 仅验证局部变量,未验证 item 实际状态
  3. ut_driveritem.cpp:250 - PaintEvent 测试中 EXPECT_EQ(width, width) 为自比较恒真断言
  4. ut_driveritem.cpp:225 - DriverLabelItem_Constructor_EmptyText 测试中 EXPECT_NE(nullptr, &item) 检查栈地址恒不为 null

建议: 1.替换无意义断言为验证 item 实际状态的断言,如检查 item->name() 返回值
2.对于自比较断言,改为验证 paintEvent 调用后 item 的可见性或状态变化
3.对于恒真断言,改为验证实际的业务逻辑结果


3. 代码性能 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 测试代码性能良好,SetUp/TearDown 模式规范,无不必要的资源消耗


4. 代码安全 🔒

评价: 优秀 ✅ 通过

🔐 发现 0 个安全漏洞

安全漏洞详情:
✅ 未发现安全漏洞

建议: 测试代码无安全风险,无用户输入处理、网络操作、加密操作或敏感信息


💡 改进建议代码示例

// 修复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 代码审查工具自动生成

@add-uos

add-uos commented Sep 18, 2026

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

This pr force merged! (status: unstable)

@deepin-bot
deepin-bot Bot merged commit 12f672c into linuxdeepin:master Sep 18, 2026
16 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants