Skip to content

test: add unit tests for PageDriverManager, PageDriverControl and PageDriverTableView - #912

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

deepin-bot[bot] merged 4 commits into
linuxdeepin:masterfrom
add-uos:ut-t11

Conversation

@add-uos

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

Copy link
Copy Markdown
Contributor

Summary

Rewrite Google Test unit tests for three Page-module classes, per function-importance inventory (82 methods) with a W(write) → R(review) → B(defect report) closed loop.

Class Files Cases Result
PageDriverManager 4 test files + ut_mock_thread.h 63 all pass
PageDriverControl 1 test file 26 all pass
PageDriverTableView 1 test file 14 all pass
Total 104 target suites exit 0, ~2s, stable across 10 repeated runs
  • Existing tests were reviewed first (Mode 6): 6 files failed review (hollow assertions, NO_FATAL-only, insufficient stubbing) and were rewritten; valid cases kept.
  • All external dependencies (DBus / network / file system / proc) are stubbed; no real device environment required (QT_QPA_PLATFORM=offscreen).
  • ASAN run (detect_leaks=0) of the target suites: 8/8 clean.

Coverage (target files only, lcov)

File Line Function
src/Page/PageDriverManager.cpp 76.1% 91.3%
src/Page/PageDriverControl.cpp 85.6% 86.4%
src/Page/PageDriverTableView.cpp 70.7% 100%

Inventory-weighted: line 76.4% / function 95.1% over 82 testable methods.

Suspected source defects found while testing (reported, not fixed)

7 items (5 high / 2 mid), including: networkIsOnline() Qt6 branch inverted condition (PageDriverManager.cpp:1071), removeAt(indexOf(...)) without -1 guard (PageDriverManager.cpp:371), null-pointer deref of mp_HeaderCb (drivertableview.cpp:518), 1000s blocking DBus setTimeout (DBusDriverInterface.cpp:37/71/101), layout use-after-free risk in ~DetectedStatusWidget, re-entrant refreshInfo on close, and a dead objectName check in isRunning. Details tracked in the task issue attachments.

Test plan

  • cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_COVERAGE_ARG=CMAKE_COVERAGE_ARG_ON -DQT_VERSION_MAJOR=6 -DDTK_VERSION_MAJOR=6
  • QT_QPA_PLATFORM=offscreen ctest/gtest binary, filter UT_PageDriverManager*:UT_PageDriverControl*:UT_PageDriverTableView* → 104 passed, 0 failed

Summary by Sourcery

Strengthen Page-module regression coverage with deterministic unit tests for driver management workflows, control dialogs, and table-view behavior.

Enhancements:

  • Expand and rewrite unit coverage for PageDriverManager, PageDriverControl, and PageDriverTableView behavior across initialization, state transitions, driver operations, UI updates, callbacks, and edge cases.
  • Isolate the tests from device, network, DBus, filesystem, and thread dependencies with controlled stubs and mocks.

Tests:

  • Replace weak or incomplete assertions with 104 behavior-focused Google Test cases covering the three Page-module classes.
  • Add mock dialog support and deterministic thread, network, backup, scanner, and DBus test doubles for reliable offscreen execution.

- Rewrite hollow-assertion cases: ctor/dtor, initWidgets layout,
  resizeEvent, installDriverLogical, closeEvent, slotClose, isRunning,
  slotBtnNext and more (26 cases)
- Stub all external deps (DBus/network/dialogs), no real device needed
- Normalize copyright header to the unified single form
- 63 cases in 4 files covering ctor/updateListView/addDriverInfo/
  isFirstScan/index ops/installNextDriver/backupNextDriver/
  slotScanFinished/slotBackupFinished/slotUndoInstall/
  slotDownloadProgressChanged/getDebBackupInfo/getDownloadInfo/
  scanDriverInfo/scanDevices/networkIsOnline
- Replace mock thread swap with QThread::start count stubs; virtual
  dialog exec via MockFailedDialog subclass (ut_mock_thread.h)
- Stub DetectedStatusWidget head-widget UI to avoid layout accumulation
  crash under offscreen
- 14 cases covering ctor/initWidgets/resizeEvent/resizeColumnWidth
- Drive resizeEvent via setGeometry + QApplication::sendEvent since
  hidden top-level widgets skip resize dispatch
- Build model columns before setColumnWidth (no-op without columns)
@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 2 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Oct 26, 2026

Copy link
Copy Markdown

Reviewer's Guide

Rewrites the Page-module unit tests into 104 deterministic, assertion-driven Google Test cases for PageDriverManager, PageDriverControl, and PageDriverTableView, using extensive dependency stubbing and Qt offscreen fixtures to cover normal, boundary, error, UI, signal, and asynchronous-operation paths without changing production code.

File-Level Changes

Change Details Files
Replaced shallow or non-assertive tests with behavior-focused Google Test coverage for PageDriverManager, including state transitions, queue management, scan/install/backup/restore flows, progress callbacks, error paths, and signal emissions.
  • Expanded manager coverage across constructor/state helpers, list operations, scans, driver operations, progress handlers, completion handlers, and undo flows.
  • Added controlled stubs for DBus, network, filesystem, device enumeration, UI updates, and worker-thread starts to keep tests deterministic and environment-independent.
  • Added temporary-directory fixtures, driver-info builders, signal spies, and teardown synchronization for resource-safe tests.
deepin-devicemanager/tests/src/Page/ut_pagedrivermanager.cpp
deepin-devicemanager/tests/src/Page/ut_pagedrivermanager_misc.cpp
deepin-devicemanager/tests/src/Page/ut_pagedrivermanager_slot.cpp
deepin-devicemanager/tests/src/Page/ut_pagedrivermanager_slot2.cpp
Expanded PageDriverControl tests to validate close behavior, UI controls, error-message mapping, install/uninstall transitions, process completion, path validation, and running-window detection.
  • Covered accepted, rejected, and refresh-emitting close-event paths.
  • Asserted button state, stack-page changes, process-status properties, known/unknown error text, and printer-specific uninstall behavior.
  • Used Qt signal/event utilities and child-widget lookup to exercise user-facing behavior.
deepin-devicemanager/tests/src/Page/ut_pagedrivercontrol.cpp
Reworked PageDriverTableView tests around its model, embedded widgets, selection/status behavior, header controls, resizing, painting, and delegation methods.
  • Asserted row/column counts, height changes, header content, checked indexes, item status, disabled-item detection, and widget removal.
  • Exercised resize thresholds and offscreen paint behavior instead of relying on no-failure assertions.
deepin-devicemanager/tests/src/Page/ut_pagedrivertableview.cpp
Added a dialog test double to safely replace the virtual modal dialog execution path during manager failure-flow tests.
  • Overrides QDialog execution to count invocations and return controlled results.
  • Documents why virtual member functions are replaced through subclassing rather than direct function-address stubbing.
deepin-devicemanager/tests/src/Page/ut_mock_thread.h

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

- ut_pagedrivermanager.cpp: 2019-2026 (base header year 2019)
- misc/slot/slot2/tableview: 2026 (single year for this-year files)
- Matches zccrs/github-actions-spdx-checker expectations on CI
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

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

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交为 PageDriverManager、PageDriverControl 和 PageDriverTableView 三个页面类 新增/重写单元测试,commit 目的明确为"添加单元测试"。测试覆盖了构造函数、状态转换、 slot 回调、UI 事件处理等多条路径,桩/mock 策略合理(QThread::start 计数桩、 MockFailedDialog 虚函数重写、QTemporaryDir 隔离文件系统)。四维度均通过,仅代码质量 维度存在 makeInfo 辅助函数跨 4 个文件重复定义的轻微问题,不影响测试正确性。

🔍 详细分析

1. 语法逻辑 ✅

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

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

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


2. 代码质量 ✅

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

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

建议: ['建议将 makeInfo 抽取到共享头文件(如 ut_driverinfo_helper.h)中,供所有 PageDriverManager 测试文件复用,减少维护成本']


3. 代码性能 ✅

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

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

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


4. 代码安全 🔒

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

🔐 发现 0 个安全漏洞

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

建议: ['无需修改,无安全风险。']


💡 改进建议代码示例

// 建议将重复的 makeInfo 抽取为共享工具函数 // 文件: tests/src/Page/ut_driverinfo_helper.h // // SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-or-later // #ifndef UT_DRIVERINFO_HELPER_H #define UT_DRIVERINFO_HELPER_H #include "DriverInfo.h" static DriverInfo *ut_makeInfo(const QString &name, const QString &packages,
                               const QString &debVersion, const QString &version,
                               Status status)
{
    DriverInfo *info = new DriverInfo();
    info->m_Name = name;
    info->m_Packages = packages;
    info->m_DebVersion = debVersion;
    info->m_Version = version;
    info->m_Size = "23.2";
    info->m_Byte = 1048576;
    info->m_Status = status;
    return info;
} #endif // UT_DRIVERINFO_HELPER_H

本报告由 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 ed4992c into linuxdeepin:master Oct 26, 2026
14 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