Repository navigation
test: add unit tests for Widget driver-list module (6 classes, 91 cases) - #925
Conversation
Reviewer's GuideReplaces the existing Widget driver-list unit tests with 91 active Google Test cases across six production classes, using targeted stubs, temporary filesystem fixtures, Qt signal/message observation, and offscreen-safe painting checks; the test target also embeds app icon resources needed by camera-icon tests. The PR reports clean builds, three stable filtered runs, full-suite green status, coverage gates passing, and two explicitly disabled drawRow cases due to the Qt6 offscreen backend limitation. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 语法正确,逻辑清晰 ✅ 通过 潜在问题: 建议: ['保持现有 AAA 结构与分支注释表格,后续新增用例延续该规范。'] 2. 代码质量 ✅评价: 代码结构清晰,注释完整 ✅ 通过 潜在问题: 建议: ['删除 3. 代码性能 ✅评价: 性能良好,资源使用合理 ✅ 通过 潜在问题: 建议: [] 4. 代码安全 🔒评价: 存在0个安全漏洞 ✅ 通过
安全漏洞详情: 建议: [] 💡 改进建议代码示例// 修复 ut_devicelistview.cpp 中无意义的永真断言
// 修改前:
// EXPECT_TRUE(m_view->isVisible() || true); // offscreen 下可见性不作为强断言
//
// 修改后(直接删除该行,保留注释说明 offscreen 限制):
// mouseMoveEvent_NoCtrl_DelegatesToBase
TEST_F(UT_DeviceListView, mouseMoveEvent_NoCtrl_DelegatesToBase)
{
Stub stub;
// Arrange
g_utKbMods = Qt::NoModifier;
stub.set(ADDR(QApplication, keyboardModifiers), ut_kbMods);
m_view->addItem("cpu", "a##b");
m_view->setCurItem("cpu");
QMouseEvent move(QEvent::MouseMove, QPoint(10, 10), Qt::NoButton,
Qt::NoButton, Qt::NoModifier, QPointingDevice::primaryPointingDevice());
// Act
m_view->mouseMoveEvent(&move);
// Assert:委托基类后视图状态未被破坏(offscreen 下可见性不可靠,仅校验当前行)
EXPECT_EQ(0, m_view->currentIndex().row());
g_utKbMods = Qt::NoModifier;
}本报告由 AI 代码审查工具自动生成 |
…h-driven cases - Rewrite ut_driverlistviewdelegate.cpp: 10 paint + 2 sizeHint cases - Cover all paint branches: invalid index, Disabled/Inactive/Active color groups, viewItemPosition(Beginning/Middle/End/OnlyOne/Invalid), icon drawing path, widget style lookup and fixed row height 36 - Stub DApplication::style/activeWindow and non-virtual QPainter drawText/drawPixmap to avoid real device environment dependency - All 12 cases pass under offscreen platform; structural self-check clean
…iven cases - Rewrite ut_getdrivernamewidget.cpp: 13 cases across loadAllDrivers, selectName(3), updateTipLabelText(2), stopLoadingDrivers, reloadDriversListPages(2), slotSelectedDriver(2), slotFinishLoadDrivers, onUpdateTheme - Stub GetDriverNameModel::startLoadDrivers to avoid real filesystem traversal and stopLoadingDrivers call counting for delegation check - Assert stack page switching, UserRole data return, check-state toggling on reselect, out-of-range row handling and palette sync on theme change - All 13 cases pass under offscreen platform; structural self-check clean
…driven cases - Rewrite ut_devicelistview.cpp: DeviceListView(18) / DeviceListviewDelegate(6) / CameraIconEngine(7) via QIcon public API - Append appimage.qrc to test target so CameraIconEngine loads real builtin light/dark camera svg resources in tests - Stub QApplication::keyboardModifiers for Ctrl-skip branches and DApplication::activeWindow for separator color-group branches - Verify addItem data/flags/camera-engine selection, separator skip on Up/Down keys with QSignalSpy, mouse Ctrl suppression, separator 2px FrameBorder line via transparent-background rendering and sizeHint rules - All 31 cases pass under offscreen platform; structural self-check clean
…iven cases - Cover ctor default state, path forwarding (default homePath + stubbed UrlChooserEdit::text), includeSubdir checked/unchecked/partially-checked, tip label text/tooltip update and clear, signalNotLocalFolder forward plus tip-clear on both values, onUpdateTheme Window-follows-Base palette - All 11 cases pass under offscreen platform; structural self-check clean
…cases - keyPressEvent 全分支: Ctrl/Shift 修饰键拦截不 emit clicked; 无修饰键 Down/Up/Home/End 基类移动后 emit clicked(row,1); 其他键不 emit - paintEvent 激活状态分支: 经 QtMessageHandler 捕获 qCDebug 分支日志, offscreen 无真实绘制后端, 绘制结果不可观察, 不做 QPainter 层打桩 - drawRow 圆角填充绘制: Qt6 offscreen 下 QTreeView::drawBranches 基类 绘制必现段错误, 沿用原文件 DISABLED 标注保留用例待环境修复 - 构造/initUI: header 隐藏/NoFrame/NoEditTriggers/Expanding/委托就绪
…ven cases - traverseFolders 五分支: 目录不存在/平铺收集 .deb .ko 忽略干扰文件/ 不递归跳过子目录/递归收集子目录/停止标志跳过遍历 - startLoadDrivers 四分支: 不含子目录本地遍历填 model 两列并发射完成 信号; 含子目录 DBus 成功用返回结果、失败回退递归遍历、查询期间置 停止中止填充不发射 - DBusAnythingInterface::searchDriver 桩化, 不依赖 com.deepin.anything 真实服务; 目录数据用 QTemporaryDir 临时目录自动清理
…ate no-icon branch - CameraIconEngine: QIcon 副本 addPixmap 触发 detach 克隆引擎, 克隆后仍可 正常绘制; key() 在 Qt6 中对自定义引擎无公开 API 触达路径, 如实标注未覆盖 - DriverListViewDelegate: Beginning 位置但 DecorationRole 无效 → 源码图标 矩形未计算(非 24x24), 文本绘制不受影响
|
[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 |
Summary
Rewrite and extend the Google Test suites for the Widget driver-list module (6 source files, 6 test files), 91 active cases all passing:
ut_devicelistview.cpput_getdrivernamewidget.cpput_driverlistview.cpput_driverlistviewdelegate.cpput_getdriverpathwidget.cpput_getdrivernamemodel.cppCoverage scope:
src/Widget/{DeviceListView, GetDriverNameWidget, DriverListView, DriverListViewDelegate, GetDriverPathWidget, GetDriverNameModel}.cpp(55 methods from the Mode-1 inventory: 1 high / 13 mid / 39 low testable).DBusAnythingInterface::searchDriver/searchDriverStop),DApplication::style/activeWindow,QIcon::paint,QPainter::drawText/drawPixmap,UrlChooserEditsignals; real directory trees built withQTemporaryDir. Tests run headless withQT_QPA_PLATFORM=offscreenand never touch real device environments.QSignalSpyonclicked(QModelIndex);paintEventverified via QtMessageHandler log capture (Window is active/inactive).UT_HEADinheritance false positiveE1 structure line 1).Copyright (C) 2019-2026 UnionTech Software Technology Co.,Ltd), SPDX gateFailed: 0.Verification
deepin-devicemanager-testtarget compiles clean.DISABLED_cases forDriverListView::drawRow), 3 consecutive stable runs.Coverage (per-level; throw-edges excluded from the branch denominator as untestable)
DriverListViewDelegate::paint)Environment-limited exemptions (documented in
inventory exempt_reason):CameraIconEngine::key— Qt6 removedQIcon::operator==and never invokeskey()for custom engines via public API; unreachable without patching Qt itself.DriverListView::drawRow—QTreeView::drawBranchesbase painting segfaults under offscreen (no real paint backend); the 2 driving cases are kept in code asDISABLED_for future enablement.Toolchain note:
lcov/genhtmlare not installable in this environment (absent from Debian deps); coverage was computed viagcov -iJSON intermediate format converted to an lcov tracefile, matching the gcovr dialect the skill's parser expects (mangledFN/FNDA).1 suspected source defect reported (not fixed in this PR, reported to the bug-fix squad)
src/Widget/DriverListViewDelegate.cpp:79—dynamic_cast<DStyle *>(DApplication::style())result is dereferenced without a null check (style->pixelMetric(...)). Under any non-DStyle application style (e.g. embedding with plainQApplication, third-party style), every item paint segfaults. Latent today because the app runsDApplication; suggested fix: null-guard with a default margin fallback (same unchecked pattern exists inlogviewitemdelegate/logviewheaderview).Test plan
make deepin-devicemanager-testbuilds with 0 errors from new test filesQT_QPA_PLATFORM=offscreen ./deepin-devicemanager-test --gtest_filter='UT_DeviceListView.*:UT_DeviceListviewDelegate.*:UT_CameraIconEngine.*:UT_GetDriverNameWidget.*:UT_DriverListView.*:UT_DriverListViewDelegate.*:UT_GetDriverPathWidget.*:UT_GetDriverNameModel.*'→ 91/91 PASSEDSummary by Sourcery
Strengthen automated coverage and isolation for the Widget driver-list module with comprehensive headless unit tests.
Enhancements:
Build:
Tests:
Chores: