Skip to content

test: add unit tests for widgets remaining classes - #258

Merged
wyu71 merged 1 commit into
linuxdeepin:masterfrom
wyu71:agent/codebase/15f4781f96aa
Oct 26, 2026
Merged

wyu71 merged 1 commit into
linuxdeepin:masterfrom
wyu71:agent/codebase/15f4781f96aa

Conversation

@wyu71

@wyu71 wyu71 commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Add GTest unit tests for CMenu, CSvgLabel, SeperatorLine,
EditLabel, ProgressLayout, CSideWidthWidget, DrawThemeManager
in src/widgets/. Covers constructors, key methods, signals,
and boundary conditions. DMenuComboBox is dead code (#if 0)
and excluded from testing.

为 src/widgets 下剩余组件类添加 GTest 单元测试,
覆盖构造函数、关键方法、信号及边界条件。
DMenuComboBox 为死代码(#if 0),排除测试。

multica: V-6403
Log: 添加 widgets 组件单元测试

Summary by Sourcery

Tests:

  • Add GTest coverage for the remaining widget classes, including constructors, core behavior, signals, rendering, and boundary conditions.

@sourcery-ai

sourcery-ai Bot commented Oct 26, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds 63 unit tests across seven remaining widget test files, covering construction, key methods, signals, rendering, state transitions, and boundary conditions; the suite reportedly compiles and runs with 62 passes, one intentional skip, and no production-code changes.

File-Level Changes

Change Details Files
Adds GTest coverage for the remaining widget classes without changing production code.
  • Adds constructor, hide-event, recursive action-state, and submenu tests for CMenu.
  • Adds rendering and construction tests for CSvgLabel, including valid and empty SVG cases.
  • Adds lifecycle, theme/pixmap, fixed-property, and singleton/signal tests for SeperatorLine, EditLabel, and DrawThemeManager.
  • Adds ProgressLayout tests for ranges, out-of-range values, text modes, reset, delayed close, centering, and the documented skipped nullptr case.
  • Adds CSideWidthWidget tests for combo-box contents, text/spacing/width/validity behavior, signal emission, and size hints.
  • Uses private/protected access overrides and offscreen-compatible widget interactions to inspect internal state and exercise GUI code.
tests/test_cmenu.cpp
tests/test_csvglabel.cpp
tests/test_seperatorline.cpp
tests/test_editlabel.cpp
tests/test_progresslayout.cpp
tests/test_csidewidthwidget.cpp
tests/test_drawthememanager.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

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="tests/test_csvglabel.cpp" line_range="38-41" />
<code_context>
+
+TEST(CSvgLabelTest, ConstructorWithText)
+{
+    CSvgLabel label(QStringLiteral("hello.svg"));
+    // DLabel::text() is empty because the str parameter initialises
+    // QSvgRenderer, not the label text.
+    SUCCEED();
+}
+
</code_context>
<issue_to_address>
**SVG loading goes unverified**

When the constructor fails to load its supplied SVG or the SVG renders blank, `ConstructorWithText` ends with `SUCCEED()` and the paint test accepts any non-null `grab()` pixmap, so failed SVG loading or blank output passes without verifying the constructor input or rendered content.

Assert that the constructor loads the supplied SVG and that the paint test captures rendered SVG content.

Also at `tests/test_csvglabel.cpp:80-82`, `tests/test_seperatorline.cpp:65-70`.
</issue_to_address>

### Comment 2
<location path="tests/test_editlabel.cpp" line_range="14" />
<code_context>
+ *   EditLabel(DWidget*), ~EditLabel()
+ *
+ * Verifies DLineEdit default properties set by the constructor:
+ *   fixed size 55x36, clearButton disabled, readOnly, font 14px.
+ */
+
</code_context>
<issue_to_address>
**Clear-button setting is unverified**

The test file claims to verify that the clear button is disabled, but none of its tests checks that property. A constructor regression that enables the clear button therefore passes the suite unnoticed.

Add an assertion that the line edit's clear button is disabled after construction.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread tests/test_csvglabel.cpp Outdated
Comment thread tests/test_editlabel.cpp
@wyu71
wyu71 force-pushed the agent/codebase/15f4781f96aa branch from bfef120 to 1e5e616 Compare October 26, 2026 06:02
Add GTest unit tests for CMenu, CSvgLabel, SeperatorLine,
EditLabel, ProgressLayout, CSideWidthWidget, DrawThemeManager
in src/widgets/. Covers constructors, key methods, signals,
and boundary conditions. DMenuComboBox is dead code (#if 0)
and excluded from testing.

为 src/widgets 下剩余组件类添加 GTest 单元测试,
覆盖构造函数、关键方法、信号及边界条件。
DMenuComboBox 为死代码(#if 0),排除测试。

multica: V-6403
Log: 添加 widgets 组件单元测试
@wyu71
wyu71 force-pushed the agent/codebase/15f4781f96aa branch from 1e5e616 to ec5fa40 Compare October 26, 2026 06:11
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

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

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交为 deepin-draw 项目的 7 个 widgets 类(CMenu、CSideWidthWidget、CSvgLabel、 DrawThemeManager、EditLabel、ProgressLayout、SeperatorLine)添加了完整的 Google Test 单元测试, 测试覆盖了构造函数、关键方法、信号和析构函数。代码语法正确,逻辑清晰,无安全漏洞, 性能良好。存在少量代码质量问题(多处不必要的 #define protected public 宏、未使用的头文件包含、 原始 new/delete 析构测试、冗余的 if/else 断言、单例状态污染风险等),建议按 OCR 建议优化。

🔍 详细分析

1. 语法逻辑 ✅

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

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

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


2. 代码质量 ✅

评价: 代码结构清晰,注释完整,存在少量可优化项 ✅ 通过

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

建议: ['移除 test_editlabel.cpp、test_progresslayout.cpp、test_seperatorline.cpp 中不必要的 #define protected public / #define private public 宏', '移除未使用的头文件包含:<gmock/gmock-matchers.h>(test_csidewidthwidget.cpp)、(test_progresslayout.cpp)', '将析构函数测试中的 new/delete 改为栈分配:{ EditLabel label; } 即可触发析构', 'test_seperatorline.cpp 的 PixmapIsSetAfterUpdate 测试应使用 EXPECT_FALSE(pix.isNull()) 或记录日志而非两分支都 SUCCEED()', 'test_drawthememanager.cpp 建议使用 test fixture(SetUp/TearDown)保存和恢复 m_currentTheme 状态', '强化 SizeHintIsValid 和 NegativeValues 测试断言,确保验证组件特定行为']


3. 代码性能 ✅

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

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

建议: ['无需性能优化']


4. 代码安全 🔒

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

🔐 发现 0 个安全漏洞

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

建议: ['无需安全加固']


💡 改进建议代码示例

// 1. 移除不必要的宏(test_editlabel.cpp / test_progresslayout.cpp / test_seperatorline.cpp)
// 直接包含头文件,无需 #define protected public:
#include "widgets/editlabel.h"

// 2. 析构函数测试改用栈分配(test_editlabel.cpp)
TEST(EditLabelTest, DestructorDoesNotCrash)
{
    {
        EditLabel label;  // 栈分配,作用域结束自动调用析构函数
    }
    SUCCEED();
}

// 3. 修复无意义的 if/else 断言(test_seperatorline.cpp)
TEST(SeperatorLineUpdateTheme, PixmapIsSetAfterUpdate)
{
    SeperatorLine line;
    line.updateTheme();
    QPixmap pix = line.pixmap();
    // 如果资源可用则验证非空,否则记录但不失败
    if (pix.isNull()) {
        GTEST_SKIP() << "SVG resource unavailable in test environment";
    }
    EXPECT_FALSE(pix.isNull());
}

// 4. 单例测试使用 fixture 管理状态(test_drawthememanager.cpp)
class DrawThemeManagerFixture : public ::testing::Test {
protected:
    void SetUp() override {
        m_originalTheme = DrawThemeManager::instance()->m_currentTheme;
    }
    void TearDown() override {
        DrawThemeManager::instance()->m_currentTheme = m_originalTheme;
    }
    QString m_originalTheme;
};

TEST_F(DrawThemeManagerFixture, DefaultThemeIsLight)
{
    EXPECT_EQ(DrawThemeManager::instance()->m_currentTheme, QString("light"));
}

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

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: lzwind, wyu71

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

@wyu71
wyu71 merged commit 614cb49 into linuxdeepin:master Oct 26, 2026
14 checks passed
@wyu71
wyu71 deleted the agent/codebase/15f4781f96aa branch October 26, 2026 06:39
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