Skip to content

test(editor): extend tests and remove empty stubs - #502

Merged
deepin-bot[bot] merged 2 commits into
linuxdeepin:masterfrom
pengfeixx:test/ut-controls-editor-ext
Aug 3, 2026
Merged

test(editor): extend tests and remove empty stubs#502
deepin-bot[bot] merged 2 commits into
linuxdeepin:masterfrom
pengfeixx:test/ut-controls-editor-ext

Conversation

@pengfeixx

@pengfeixx pengfeixx commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Add test cases for WarningNotices, EditWrapper, FlashTween, LeftAreaTextEdit and DetectCode. Remove empty commented-out tests.

Log: 扩充controls和editor模块测试,清理空测试
Influence: 提升EditWrapper等类的覆盖率,移除无效测试

Summary by Sourcery

Extend unit test coverage for editor and controls components while cleaning up obsolete test stubs.

Tests:

  • Add focused tests for EditWrapper behaviors, including custom events, invalid-character flows, and file-saving paths.
  • Introduce new tests for ParseFileEvent lifecycle, FlashTween easing/animation internals, and LeftAreaTextEdit::getEdit.
  • Expand WarningNotices tests to cover constructor wiring, button state management, and signal/slot interactions.

Chores:

  • Remove unused and commented-out test cases in DetectCode and InsertBlockByTextCommand suites.
  • Update WarningNotices test SPDX copyright year to 2026.

@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.

Sorry @pengfeixx, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@sourcery-ai

sourcery-ai Bot commented Aug 3, 2026

Copy link
Copy Markdown

Reviewer's Guide

This PR extends unit test coverage for several editor and controls classes (EditWrapper, ParseFileEvent, FlashTween, WarningNotices, LeftAreaTextEdit), updates license headers, and removes obsolete commented‑out tests for DetectCode and InsertBlockByTextCommand.

File-Level Changes

Change Details Files
Add comprehensive EditWrapper and ParseFileEvent tests covering custom events, invalid-character workflows, file-saving, and accessor behavior.
  • Introduce a mirror ParseFileEvent test helper class and add tests for its construction, cloning, and destruction paths.
  • Exercise EditWrapper::customEvent for both non-ParseFileEvent and ParseFileEvent inputs, including async read completion flag behavior.
  • Cover EditWrapper state and accessors such as quit flag, last-modified time, invalid-character flags and paths, cursor restore position, and plain-text content retrieval.
  • Test invalid-character-related workflows: highlighter update early-return, edit-anyway flow, read allocation error handling, invalid-character preview exit, and forced save of invalid-character files with stubbed history recording.
tests/src/editor/ut_editwrapper.cpp
Expand WarningNotices tests to validate constructor behavior, button configuration methods, and connected lambdas reacting to UI helper signals and close events.
  • Update SPDX copyright years in WarningNotices test sources.
  • Add tests for the WarningNotices constructor, edit-anyway button setup, button clearing, and edit-anyway click signal emission.
  • Add tests that explicitly trigger constructor-connected lambdas via closeButtonClicked, DGuiApplicationHelper::sizeModeChanged, and fontChanged signals.
tests/src/controls/ut_warningnotices.cpp
tests/src/controls/ut_warningnotices.h
Increase FlashTween coverage by testing easing function behavior, one-frame runs for X/Y tween slots, and destructor cleanup of timers.
  • Add tests for FlashTween::sinusoidalEaseOut across start, mid, and end times.
  • Invoke private slots __runX and __runY (via relaxed access control) after startX/startY to assert state updates.
  • Add destructor test to ensure timers are created and freed correctly.
tests/src/editor/ut_flashtween.cpp
Remove obsolete or empty commented-out tests for DetectCode and InsertBlockByTextCommand, keeping only meaningful test cases.
  • Delete commented-out DetectCode::ChartDet_DetectingTextCoding test stubs for out-of-memory, null-object, and success paths.
  • Delete commented-out InsertBlockByTextCommand::treat test stub that constructed large content and relied on stubs.
  • Retain existing functional tests in these suites without modification.
tests/src/encodes/ut_detectcode.cpp
tests/src/editor/ut_insertblockbytextcommond.cpp
Add a simple LeftAreaTextEdit accessor test to verify association with its TextEdit instance.
  • Add a test that constructs LeftAreaTextEdit with a TextEdit, calls getEdit, and asserts it returns the same non-null TextEdit instance.
tests/src/editor/ut_leftareaoftextedit.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

Add test cases for WarningNotices, EditWrapper, FlashTween,
LeftAreaTextEdit and DetectCode. Remove empty commented-out tests.

Log: 扩充controls和editor模块测试,清理空测试
Influence: 提升EditWrapper等类的覆盖率,移除无效测试
Log: 更新已修改文件的SPDX版权头年份范围
Influence: 无
@pengfeixx
pengfeixx force-pushed the test/ut-controls-editor-ext branch from 4bfcbfd to 567857d Compare August 3, 2026 02:20
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:95分

■ 【总体评价】

代码清理了无效的注释测试用例并新增了大量单元测试以提升覆盖率,整体质量良好
逻辑正确且无安全漏洞,仅在测试文件路径硬编码和私有类前置声明上存在轻微瑕疵

■ 【详细分析】

  • 1.语法逻辑(基本正确)✓

测试代码使用了标准的 GTest 框架宏(如 TEST_F, EXPECT_EQ, ASSERT_TRUE),语法正确。在 ut_editwrapper.cpp 中重新声明了 ParseFileEvent 类以访问私有成员,这种做法在测试中常见。内存管理方面,大部分对象使用了 deleteLater()delete 进行释放,避免了内存泄漏。
潜在问题:ParseFileEvent 在测试文件中手动声明,如果源文件中的该类发生结构变更,测试代码可能不会编译报错但会导致内存布局不匹配,引发未定义行为。
建议:添加注释提醒维护者在源类变更时同步更新测试中的镜像声明;或考虑使用友元类机制替代手动镜像声明。

  • 2.代码质量(良好)✓

代码清理了大量被注释掉的废弃测试用例(如 ut_insertblockbytextcommond.cpp 中的 treatut_detectcode.cpp 中的多个用例),提高了代码整洁度。新增的测试用例覆盖了 WarningNoticesEditWrapper 的多个核心方法,注释清晰,命名规范。
潜在问题:在 ut_editwrapper.cppforceSaveInvalidCharFile 测试中,硬编码了文件路径 /tmp/ut_forceSaveInvalidCharFile.txt
建议:使用 QTemporaryFile 或在测试构建目录下创建临时文件,避免硬编码 /tmp 路径带来的潜在冲突。

  • 3.代码性能(无性能问题)✓

测试代码主要针对单元功能验证,不涉及复杂的算法或高频轮询,性能表现正常。customEvent 等测试用例直接构造事件并触发,没有引入不必要的延迟或资源消耗。
建议:保持现有的轻量级测试设计原则。

  • 4.代码安全(存在0个安全漏洞)✓

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
本次提交为单元测试代码,未引入任何外部输入处理或敏感操作,不存在命令注入、路径遍历等安全风险。硬编码的临时文件路径仅在测试环境中运行,不构成生产环境安全漏洞。

  • 建议:无需针对安全进行修复,保持测试环境的隔离性即可。

■ 【改进建议代码示例】

// tests/src/editor/ut_editwrapper.cpp
// 建议使用 QTemporaryFile 替代硬编码的 /tmp 路径

#include <QTemporaryFile>

// ...

TEST(UT_Editwrapper_forceSaveInvalidCharFile, save_success)
{
    Stub s;
    s.set(ADDR(TextEdit, writeEncodeHistoryRecord), editwrapper_force::writeEncodeHistoryRecord_stub);

    Window *pWindow = new Window();
    pWindow->addBlankTab(QString());
    EditWrapper *wra = pWindow->currentWrapper();
    wra->m_pTextEdit->setPlainText("force save content");
    
    // 使用 QTemporaryFile 生成安全的临时文件路径
    QTemporaryFile tempFile;
    tempFile.setAutoRemove(true); // 自动清理
    if (!tempFile.open()) {
        FAIL() << "Failed to create temporary file";
    }
    QString tempPath = tempFile.fileName();
    tempFile.close(); // 关闭文件以便后续写入测试

    wra->m_sInvalidCharOriginalPath = tempPath;

    bool ok = wra->forceSaveInvalidCharFile();
    EXPECT_TRUE(ok);
    EXPECT_FALSE(wra->m_bInvalidCharPreview);

    // QFile::remove(tempPath); // 不再需要手动删除,QTemporaryFile 会处理

    pWindow->deleteLater();
}

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

@pengfeixx

Copy link
Copy Markdown
Contributor Author

/merge

@deepin-bot
deepin-bot Bot merged commit ae2f5a2 into linuxdeepin:master Aug 3, 2026
20 checks passed
@pengfeixx
pengfeixx deleted the test/ut-controls-editor-ext branch August 3, 2026 02:30
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