Repository navigation
Conversation
… cases Rewrite UT_BtnLabel/UT_TipsLabel/UT_TitleLabel (8+3+3 cases) in value-driven AAA style: ctor state, linkActivated four branches via DDialog::exec virtual-table stub, paintEvent flag-driven rendering. Add tests/src/ut_stub_helper.h: ut_real_fn_addr resolves the real implementation address for GCC virtual-member-function pointers (vtable slot = (uintptr >> 3) when bit0 set), which allows StubExt to patch virtual functions such as DDialog::exec without SIGSEGV. UT_BtnLabel statics return configurable result and count invocations. All 14 cases pass (offscreen); self-check-structural 0 errors.
…riven cases Rewrite UT_HeaderInfoTableWidget in value-driven AAA style: ctor config (row height, delegate, no-scrollbar), updateData empty list, driver/printer rendering rows, refresh-merge path (second call keeps rows), resetTableContents clearing, paintEvent direct invoke. Drive real updateData with driver/printer info structures instead of implementation-detail peeking; height formula row*ROW_HEIGHT+2 asserted via constants.
… cases Rewrite UT_DriverIconWidget in value-driven AAA style: both ctor overloads (icon-only and title+desc), pixmap scaling and centering, title/desc label formatting (elide, tooltip, fixed width), palette adjustment mirroring palrtteTransparency (-10/-30), theme-change signal restoring adjusted colors, and repeated construct/destroy robustness. DWaterProgress::start stubbed to count invocations.
…ases Rewrite UT_UrlChooserEdit in value-driven AAA style: ctor UI state and home-path display, slotChooseUrl dialog-pick (local dir accepted via button click), cancel-restore, non-local device alert + signal, checkLocalFolder parameter-ignored reality (Q_UNUSED(path) validated as defect record, not patched), and text() accessor consistency. QFileDialog::getExistingDirectory stubbed via ADDR; QStorageInfo isValid/device via set_lamda; QDir::homePath stubbed in SetUp for determinism.
Rewrite UT_TipsWidget in value-driven AAA style: ctor tool-tip flag, fixed width 254 and margins 8/10, palette window==base, setText newline/tab stripping incl. repeated-set short circuit, setAlignment, adjustContent height formula mirrored via QFontMetricsF helper and second-call early-return, paintEvent direct invoke, theme-change restoration after background break.
…cases Rewrite UT_CmdButtonWidget in value-driven AAA style: ctor layout and button text, click-through signal cmdButtonClicked via QSignalSpy (covers initConnections connect), object naming and nested centered layout, paintEvent both active/inactive window branches via QApplication::activeWindow stub, and repeated-paint geometry stability.
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: add-uos 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 |
Reviewer's GuideRewrites six Widget unit-test files into AAA/value-driven suites totaling 53 cases, adding deterministic stubs for GUI, dialog, storage, theme, and window-state dependencies plus a GCC virtual-function address helper; the PR reports all targeted tests and full regression passing with 100% coverage for the six sources. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
| 🔍 详细分析1. 语法逻辑 ✅评价: 语法正确,逻辑清晰 ✅ 通过 潜在问题: 建议: [{'ut_stub_helper.h': '将 2. 代码质量 ✅评价: 代码结构清晰,注释完整 ✅ 通过 潜在问题: 建议: [{'ut_drivericonwidget.cpp': 'TearDown中添加 3. 代码性能 ✅评价: 性能良好,资源使用合理 ✅ 通过 潜在问题: 建议: ['将m_probeDialog改为仅在需要打桩DDialog::exec的测试用例中创建局部变量'] 4. 代码安全 🔒评价: 存在0个安全漏洞 ✅ 通过
安全漏洞详情: 建议: [] 💡 改进建议代码示例// ut_drivericonwidget.cpp — 修复TearDown内存泄漏
class UT_DriverIconWidget : public ::testing::Test
{
public:
void SetUp()
{
g_utWaterStartCount = 0;
}
void TearDown()
{
stub.clear();
delete m_widget; // 修复:添加遗漏的delete
m_widget = nullptr;
}
// ...
};
// ut_stub_helper.h — 修复未初始化__delta
template <typename MemFn>
inline MemFn ut_real_fn_addr(void *obj, MemFn pmf)
{
MemFn out = pmf; // 修复:先完整复制PMF,保留正确的__delta
unsigned long bits = 0;
std::memcpy(&bits, &pmf, sizeof(bits));
if (bits & 1UL) {
void **vptr = *reinterpret_cast<void ***>(obj);
const unsigned long slot = bits >> 3;
const unsigned long real = reinterpret_cast<unsigned long>(vptr[slot]);
std::memcpy(&out, &real, sizeof(real)); // 仅覆盖__pfn
}
return out;
}本报告由 AI 代码审查工具自动生成 |
1. Root cause: checkLocalFolder(const QString &path) discarded the parameter via Q_UNUSED(path) and used member mp_folderPath instead, making the API misleading; CmdButtonWidget::paintEvent called this->rect().setWidth(808) on a temporary QRect copy, which is dead code since the next line achieves the intent correctly 2. Fix: remove Q_UNUSED(path) and use the path parameter in QStorageInfo constructor; remove the dead code line in paintEvent; update UT_UrlChooserEdit_checkLocalFolder_001 to pass smb:// path matching mp_folderPath so the test validates fixed behavior 3. Impact: checkLocalFolder now validates the actual parameter passed by the caller; paintEvent behavior unchanged since the dead line had no effect; test case now correctly expects alert for non-local path; current callers pass the same value so no behavior change Influence: 1. Test checkLocalFolder with a local valid folder path 2. Test checkLocalFolder with a non-local or invalid path 3. Verify CmdButtonWidget paint rendering is unchanged fix: 修复checkLocalFolder忽略形参及更新测试用例 1. 根因:checkLocalFolder(const QString &path) 通过 Q_UNUSED(path) 丢弃形参,实际使用成员 mp_folderPath,导致 API 语义误导; CmdButtonWidget::paintEvent 中 this->rect().setWidth(808) 对 临时 QRect 副本调用,属于死代码,下一行已正确实现相同逻辑 2. 方案:移除 Q_UNUSED(path),将 QStorageInfo info(mp_folderPath) 改为 QStorageInfo info(path);移除 paintEvent 中的死代码行; 更新 UT_UrlChooserEdit_checkLocalFolder_001 传入 smb:// 路径 与 mp_folderPath 一致,使测试验证修复后的正确行为 3. 影响:checkLocalFolder 现在校验实际传入的形参;paintEvent 行为 不变(死代码行本就无效果);测试用例现在正确期望非本地路径 触发告警;当前调用点传入值与成员相同,实际无行为变化 Influence: 1. 测试 checkLocalFolder 传入本地有效文件夹路径 2. 测试 checkLocalFolder 传入非本地或无效路径 3. 验证 CmdButtonWidget 绘制效果无变化 Fixes: linuxdeepin#936 PMS: BUG-bug-fix-936-1
Summary
重写 Issue 指定 6 个 src/Widget 源文件的 Google Test 单元测试(t22 批次),全部按值驱动 + AAA 风格组织,并复用既有 GTest 目录与 CMake 挂接方式(仅 APPEND)。
tests/src/ut_stub_helper.h(新增):ut_real_fn_addr解决 GCC 虚函数成员指针打桩(vtable slot 解析),使DDialog::exec等虚函数可被 StubExt 安全替换(修复此前 SIGSEGV)ut_btnlabel.cpp— UT_BtnLabel/UT_TipsLabel/UT_TitleLabel 14 例(linkActivated 四分支经虚表打桩覆盖)ut_headerinfotablewidget.cpp— 9 例(updateData 空表/驱动/打印机/刷新合并、高度公式、reset、paint)ut_drivericonwidget.cpp— 8 例(双构造重载、缩放居中、标签格式化、调色 -10/-30、主题切换恢复、反复构造析构)ut_urlchooseredit.cpp— 7 例(对话框选择/取消/非本地告警、checkLocalFolder 形参被忽略实证、text 访问器)ut_tipswidget.cpp— 9 例(ToolTip 标志、固定宽/边距、换行制表剥离、高度公式镜像、二次调用短路、主题恢复)ut_cmdbuttonwidget.cpp— 6 例(点击信号 QSignalSpy、命名/嵌套布局、activeWindow 双分支、重复绘制几何稳定)Verification
deepin-devicemanager-test单体目标)Task
linuxdeepin/deepin-devicemanager#(对应任务 Issue 由 multica 平台跟踪)
Summary by Sourcery
Rewrite the six Widget test suites as comprehensive value-driven tests and add safe virtual-function stubbing support.
Enhancements:
Tests:
Chores: