From 84a7f45fc227df8de9465ed878b26e6d998bfc13 Mon Sep 17 00:00:00 2001 From: zhanghongyuan Date: Tue, 27 Oct 2026 00:33:10 +0800 Subject: [PATCH] fix: fix checkLocalFolder ignoring param and update test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: #936 PMS: BUG-bug-fix-936-1 --- deepin-devicemanager/src/Widget/CmdButtonWidget.cpp | 1 - deepin-devicemanager/src/Widget/UrlChooserEdit.cpp | 3 +-- deepin-devicemanager/tests/src/Widget/ut_urlchooseredit.cpp | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/deepin-devicemanager/src/Widget/CmdButtonWidget.cpp b/deepin-devicemanager/src/Widget/CmdButtonWidget.cpp index 5a628e9bb..a533c9189 100644 --- a/deepin-devicemanager/src/Widget/CmdButtonWidget.cpp +++ b/deepin-devicemanager/src/Widget/CmdButtonWidget.cpp @@ -58,7 +58,6 @@ void CmdButtonWidget::paintEvent(QPaintEvent *event) cg = DPalette::Inactive; } - this->rect().setWidth(808); QRect rect = this->rect(); rect.setWidth(808); // 开始绘制边框 ********************************************************* diff --git a/deepin-devicemanager/src/Widget/UrlChooserEdit.cpp b/deepin-devicemanager/src/Widget/UrlChooserEdit.cpp index c0f8b88ff..cc886a9fd 100644 --- a/deepin-devicemanager/src/Widget/UrlChooserEdit.cpp +++ b/deepin-devicemanager/src/Widget/UrlChooserEdit.cpp @@ -92,10 +92,9 @@ void UrlChooserEdit::checkLocalFolder(const QString &path) { qCDebug(appLog) << "Checking if folder is local:" << path; - Q_UNUSED(path); bool isLocal = true; mp_urlEdit->setAlert(false); - QStorageInfo info(mp_folderPath); //获取路径信息 + QStorageInfo info(path); //获取路径信息 qCInfo(appLog) << __func__ <mp_folderPath = "smb://10.4.10.4"; - m_UrlChooserEdit->checkLocalFolder("/home"); + m_UrlChooserEdit->checkLocalFolder("smb://10.4.10.4"); EXPECT_TRUE(m_UrlChooserEdit->mp_urlEdit->isAlert()); }