Skip to content

test(Widget): rewrite unit tests for 5 Widget table/delegate classes (108 cases) - #911

Merged
deepin-bot[bot] merged 5 commits into
linuxdeepin:masterfrom
add-uos:ut-t19
Oct 26, 2026
Merged

deepin-bot[bot] merged 5 commits into
linuxdeepin:masterfrom
add-uos:ut-t19

Conversation

@add-uos

@add-uos add-uos commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Rewrite/strengthen the unit tests for the 5 src/Widget/ classes selected by
function-importance analysis (task 19: Widget tables & delegates), replacing
hollow NO_FATAL smoke cases with 108 focused GTest cases:

Test suite Cases Notes
ut_tablewidget + ut_tablewidget_extra 6 + 27 slotShowMenu B1-B12 white-box branch map, wakeup 3-state TEST_P
ut_richtextdelegate 16 paint P1-P6 render assertions, sizeHint, addRow, getDocFromLst
ut_detailviewdelegate 18 first/middle/last/more-button rows, device-status 3-branch
ut_driverscanwidget 11 scan/failed/network UI states, slotReDetected -> redetected()
ut_driveritem (5 fixtures) 30 kept after review, 1 tautology fixed

What's included

  • 6 test sources under tests/src/Widget/ (test code only, one commit per
    class batch); no production code, no scripts, no framework tooling.
  • Copyright headers normalized to the standard
    // Copyright (C) 2019-2026 UnionTech Software Technology Co.,Ltd form
    (follow-up to f4d271c, which missed these files).

Testing

  • All external dependencies (network, file wakeup sources via temp files,
    CommonTools::feedback, DetailTreeView state) are stubbed; the suite runs
    offscreen with zero hardware dependency.
  • Rebased on upstream/master f4d271cb; the full test target builds and a
    filtered run of the touched suites passes 108/108 with exit code 0.
  • Tiered coverage over the 68 testable methods: 100% function, 97.0% line
    (high 95.5% / mid 97.1% / low 98.8%).

Note for reviewers

Two suspected source defects were found during test design and reported
separately (not fixed in this PR):

  • RichTextDelegate::paint (src/Widget/RichTextDelegate.cpp:165): unchecked
    dynamic_cast<PageSingleInfo*>(parent()) on the multi-line branch - nullptr
    deref when the delegate's parent is PageTableWidget.
  • DriverScanWidget::hideAll (src/Widget/DriverScanWidget.cpp:305): rebuilds
    6 layout members without deleting the old ones - leak on repeated
    scan/failed/network-error state switches.

Summary by Sourcery

Rewrite the Widget table and delegate unit tests to provide comprehensive, dependency-isolated behavioral coverage.

Enhancements:

  • Strengthen Widget table and delegate unit-test coverage with focused assertions for rendering, sizing, state transitions, signals, data handling, and menu branches.
  • Replace hollow smoke checks with isolated tests covering TableWidget, RichTextDelegate, DetailViewDelegate, DriverScanWidget, and DriverItem behavior.

Tests:

  • Expand the Widget test suite to 108 focused GoogleTest cases, including parameterized network-wakeup state coverage and rendering assertions.
  • Stub external UI, network, filesystem, and feedback dependencies so the updated tests run offscreen without hardware dependencies.

Chores:

  • Normalize copyright headers in the updated Widget test sources.

Generated by qt-autotest-generator skill.
Task 19 batch 1/5: TableWidget.

Rewrite ut_tablewidget_extra.cpp (6 hollow NO_FATAL cases -> 27):
slotShowMenu white-box branch map B1-B12 covering all menu-state
combinations (row selection, device enabled, driver flags), menu
item add/remove and enable/disable assertions; network wakeup
3-state (none/open/close) via TEST_P with real temp-file
/proc/acpi/wakeup sources; slotAction* verified with QSignalSpy
signal and argument assertions.

Strengthen ut_tablewidget.cpp (6 cases): data methods
setHeaderLabels/setItem/clear/updateCurItemEnable assert real
table state instead of smoke checks. Normalize the copyright
header to the standard 2019-2026 UnionTech form.

33 cases total (6 + 27), all passing under QT_QPA_PLATFORM=
offscreen. Baseline: upstream/master @ f2d46ee, rebased onto
f4d271c; TableWidget.cpp unchanged since baseline.

Log: rewrite TableWidget unit tests, task 19 batch 1/5
Influence: test code only, no production code change
Generated by qt-autotest-generator skill.
Task 19 batch 2/5: RichTextDelegate.

Rewrite ut_richtextdelegate.cpp (5 -> 16 cases): paint branch map
P1-P6 (invalid index falls back to base painter, palette group,
alternate row, first/middle/bottom row rounded-rect corner fill,
multi-line text via getDocFromLst + setRowHeight counter stub)
rendered to QImage with non-white-pixel assertions; sizeHint
minimum height 40 / width 150 branches; addRow recursive
"a/b/c" segment split; getDocFromLst invalid-pair early return;
QDomDocument table structure assertions. Normalize the copyright
header to the standard 2019-2026 UnionTech form.

16 cases, all passing. Baseline: upstream/master @ f2d46ee,
rebased onto f4d271c; RichTextDelegate.cpp unchanged.

Log: strengthen RichTextDelegate unit tests, task 19 batch 2/5
Influence: test code only, no production code change
Generated by qt-autotest-generator skill.
Task 19 batch 3/5: DetailViewDelegate.

Append 12 cases to ut_detailviewdelegate.cpp (6 -> 18): paint
branches for first/middle/last visual rows, more-button row
(index.row()==rowCount()-1 gated by hasExpendInfo stub), device
status text 3-branch matrix (enabled/unavailable/disabled) with
#FF5736 red-pixel scan for disabled devices, sizeHint branches
with/without index data, createEditor returning nullptr.
Normalize the copyright header to the standard 2019-2026
UnionTech form.

18 cases, all passing. Baseline: upstream/master @ f2d46ee,
rebased onto f4d271c; DetailViewDelegate.cpp unchanged.

Log: strengthen DetailViewDelegate unit tests, task 19 batch 3/5
Influence: test code only, no production code change
Generated by qt-autotest-generator skill.
Task 19 batch 4/5: DriverScanWidget.

Rewrite ut_driverscanwidget.cpp (6 hollow NO_FATAL cases -> 11):
constructor scrollbar policy and objectName state, setScanningUI
progress value and label updates, setScanFailedUI/setNetworkErr
control visibility, setProgressFinish clamps to 100, RefreshProgress
delta semantics, hideAll hides every control, slotFeedBack stubbed
CommonTools::feedback counter, slotReDetected re-enters scan UI and
emits redetected() (QSignalSpy) plus progress reset, paintEvent,
resizeEvent hides scrollbar.

11 cases, all passing. Baseline: upstream/master @ f2d46ee,
rebased onto f4d271c; DriverScanWidget.cpp unchanged.

Log: rewrite DriverScanWidget unit tests, task 19 batch 4/5
Influence: test code only, no production code change
Generated by qt-autotest-generator skill.
Task 19 batch 5/5: driveritem family.

Mode 6 review kept the existing 30 cases across DriverCheckItem,
DriverNameItem, DriverLabelItem, DriverOperationItem and
DriverStatusItem (checked/isEnabled/setName/setStatus assertions
are real state checks, not hollow). Fix the single tautology
EXPECT_EQ(rect().width(), rect().width()) in the DriverCheckItem
paintEvent case, replaced with grab() render validity plus rect
validity assertions. Normalize the copyright header to the
standard 2019-2026 UnionTech form.

30 cases, all passing. Baseline: upstream/master @ f2d46ee,
rebased onto f4d271c; driveritem.cpp unchanged.

Log: fix tautological assertion in driveritem tests, batch 5/5
Influence: test code only, no production code change
@sourcery-ai

sourcery-ai Bot commented Oct 26, 2026

Copy link
Copy Markdown

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 3 days and 3 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@github-actions

Copy link
Copy Markdown
  • 检测到敏感词export变动
详情
    {
    "export": {
        "deepin-devicemanager/tests/src/Widget/ut_tablewidget.cpp": {
            "b": [
                "    QSignalSpy spyExport(m_tableWidget, &TableWidget::exportInfo);"
            ]
        },
        "deepin-devicemanager/tests/src/Widget/ut_tablewidget_extra.cpp": {
            "b": [
                "    QSignalSpy spy(t, &TableWidget::exportInfo);"
            ]
        }
    }
}

@sourcery-ai

sourcery-ai Bot commented Oct 26, 2026

Copy link
Copy Markdown

Reviewer's Guide

The PR rewrites six Widget test sources from largely non-fatal smoke checks into 108 focused, dependency-isolated GTest cases covering state transitions, signals, rendering paths, data transformations, and white-box branches across five Widget table/delegate classes; it changes no production code.

File-Level Changes

Change Details Files
Replaced smoke tests with focused behavioral, branch-oriented coverage for TableWidget data operations, actions, signals, and context-menu logic.
  • Added state and signal assertions for existing actions and item handling.
  • Added white-box coverage for slotShowMenu availability, driver, printer, and wakeup branches.
  • Added parameterized tests for the three network-wakeup states and temporary-file coverage for wakeup status parsing.
  • Normalized the test copyright headers.
tests/src/Widget/ut_tablewidget.cpp
tests/src/Widget/ut_tablewidget_extra.cpp
Expanded RichTextDelegate tests to validate rendering paths, sizing, document construction, and row-height reporting.
  • Added offscreen image-rendering checks for invalid, first, middle, bottom-overflow, alternate, single-line, and multi-line paths.
  • Covered column-dependent sizeHint behavior and the null editor contract.
  • Added structural assertions for addRow splitting and getDocFromLst valid/invalid input handling.
  • Stubbed style and PageSingleInfo dependencies.
tests/src/Widget/ut_richtextdelegate.cpp
Expanded DetailViewDelegate tests across paint geometry, device-status presentation, sizing, and editor behavior.
  • Added rendering checks for first, middle, last, and more-information rows.
  • Covered enabled/available, enabled/unavailable, and disabled device-status branches, including red text detection.
  • Added sizeHint minimums and createEditor null-result assertions.
  • Stubbed DetailTreeView and application-style dependencies.
tests/src/Widget/ut_detailviewdelegate.cpp
Reworked DriverScanWidget tests around observable UI state, progress semantics, signals, and event handlers.
  • Asserted scanning, failure, network-error, completion, reset, and hide-all states.
  • Verified cumulative progress updates and redetected signal emission.
  • Stubbed feedback launching and added paint/resize behavior checks.
  • Normalized the copyright header.
tests/src/Widget/ut_driverscanwidget.cpp
Strengthened DriverCheckItem painting validation and corrected its copyright metadata.
  • Replaced a tautological self-comparison with a non-null rendered-widget assertion while retaining the valid-rectangle check.
tests/src/Widget/ut_driveritem.cpp

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

deepin pr auto review

🤖 AI 代码审查报告

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

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交为纯测试代码重写,针对 5 个 Widget 表格/委托类(DetailViewDelegate、 DriverItem、DriverScanWidget、RichTextDelegate、TableWidget/Extra)将原有 EXPECT_NO_FATAL_FAILURE 空洞断言全面替换为状态断言、QSignalSpy 信号验证与像素级 渲染断言,覆盖 paint 分支映射、sizeHint 列宽分支、slotShowMenu 全分支白盒覆盖等, 共 108 个用例。代码语法正确、逻辑清晰,注释详尽(含分支清单映射),安全维度无漏洞。 仅有少量测试 setup 重复代码,整体质量优秀。

🔍 详细分析

1. 语法逻辑 ✅

评价: 语法正确,逻辑清晰 ✅ 通过

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

建议: ['无需修改,语法逻辑完全正确。']


2. 代码质量 ✅

评价: 代码结构清晰,注释完整 ✅ 通过

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

建议: ['建议在 ut_detailviewdelegate.cpp 中抽取类似 preparePaintDelegate(columnCount, items) 的辅助方法,减少 paint 测试中的重复 setup 代码。', 'slotShowMenu 用例可统一在辅助方法中返回 Stub 指针,减少 Q_UNUSED 样板。']


3. 代码性能 ✅

评价: 性能良好,资源使用合理 ✅ 通过

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

建议: ['无需修改,性能表现良好。']


4. 代码安全 🔒

评价: 存在0个安全漏洞 ✅ 通过

🔐 发现 0 个安全漏洞

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

建议: ['无需修改,安全合规。']


💡 改进建议代码示例

// 建议优化:ut_detailviewdelegate.cpp 抽取 paint 测试 setup 辅助方法
// 减少重复样板代码
void preparePaintDelegate(int columnCount, const QStringList &items)
{
    m_stub.set(ADDR(DApplication, style), DetailViewDelegate_UT_style_fun);
    m_treeView->setColumnCount(columnCount);
    m_treeView->insertRow(0);
    for (int col = 0; col < items.size() && col < columnCount; ++col) {
        m_treeView->setItem(0, col, new QTableWidgetItem(items[col]));
    }
}

// 使用示例:
// TEST_F(UT_DetailViewDelegate, Paint_FirstRowColumn0_CornerFill)
// {
//     preparePaintDelegate(2, {"key", ""});
//     QImage img = ut_detailRender(this, m_treeView->model()->index(0, 0), QRect(0, 0, 220, 50));
//     EXPECT_GT(ut_nonWhitePixels(img), 0);
// }

本报告由 AI 代码审查工具自动生成

@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

@add-uos

add-uos commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

This pr force merged! (status: unstable)

@deepin-bot
deepin-bot Bot merged commit 0ba8558 into linuxdeepin:master Oct 26, 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