Skip to content

test: add unit tests for CSelectTool - #232

Merged
wyu71 merged 1 commit into
linuxdeepin:masterfrom
wyu71:agent/agent/9fd249ecbf1d
Sep 17, 2026
Merged

wyu71 merged 1 commit into
linuxdeepin:masterfrom
wyu71:agent/agent/9fd249ecbf1d

Conversation

@wyu71

@wyu71 wyu71 commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

test: add unit tests for CSelectTool

CSelectTool 类的五个方法添加 Google Test 单元测试,共 24 个测试用例,覆盖 5 个测试套件。

测试覆盖

方法 测试套件 用例数 覆盖分支
decideUpdate CSelectToolDecideUpdate 7 无工作状态返回、空点击(鼠标/触摸长按/触摸短按/模拟事件)、图元点击(普通拖拽/Alt复制)
toolStart CSelectToolToolStart 4 空白点击清除选中、图元点击选中、Shift修饰键切换选中、高亮路径清除
toolUpdate CSelectToolToolUpdate 3 矩形选择更新、画布拖拽滚动条调整、默认操作无崩溃
toolFinish CSelectToolToolFinish 4 矩形框选、拖拽移动完成、复制移动完成、默认操作提前返回
sendToolEventToItem CSelectToolSendToolEventToItem 6 移动事件分发、复制移动分发、缩放事件分发、旋转事件分发、默认操作无崩溃

编译与运行结果

[==========] 24 tests from 5 test suites ran. (20259 ms total)
[  PASSED  ] 24 tests.

所有测试在 QT_QPA_PLATFORM=offscreen 模式下通过。

Summary by Sourcery

Add comprehensive unit coverage for CSelectTool behavior and integrate it into the test build.

Build:

  • Add a configurable CSelectTool test target to the test build.

Tests:

  • Add Google Test coverage for CSelectTool interaction decisions, selection lifecycle, scene movement, item transformations, and event dispatch across 24 cases in five test suites.

@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 @wyu71, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 1 day and 10 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Sep 17, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds an opt-in-by-default CMake test switch and 24 Google Test cases across five suites to validate CSelectTool’s selection, movement, transformation, event dispatch, and no-op branches in an offscreen Qt environment.

File-Level Changes

Change Details Files
Add a conditionally enabled Google Test target for CSelectTool coverage.
  • Introduce the DEEPINDRAW_TEST_CSELECTTOOL_ITEM option, enabled by default.
  • Expose the TEST_CSELECTTOOL_ITEM compile definition when enabled.
tests/CMakeLists.txt
Add five Google Test suites covering CSelectTool’s event-decision, lifecycle, update, finish, and item-dispatch behavior.
  • Construct offscreen application scenes, tools, events, selection state, and graphics items through shared test helpers.
  • Exercise decideUpdate branches for idle, blank clicks, touch timing, simulated events, item dragging, and Alt-copy movement.
  • Verify toolStart selection clearing/toggling and highlight cleanup.
  • Exercise toolUpdate rectangle selection, canvas scrolling, and no-op handling.
  • Exercise toolFinish rectangle selection, move/copy cleanup, and early-return behavior.
  • Exercise move, copy, resize, rotate, and no-op dispatch paths in sendToolEventToItem.
tests/testItems/test_cselecttool.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

…ate, toolFinish, sendToolEventToItem

Add 24 Google Test cases for CSelectTool class in cselecttool.cpp,
covering decideUpdate, toolStart, toolUpdate, toolFinish, and
sendToolEventToItem methods with various tool states and events.

为cselecttool.cpp中CSelectTool类的decideUpdate、toolStart、
toolUpdate、toolFinish和sendToolEventToItem方法补充24个Google Test
单元测试用例,覆盖无工作状态返回、空点击清除选中、图元点击选中、
矩形框选、拖拽/复制移动完成及事件分发等场景。

Log: 补充CSelectTool类5个方法单元测试
Influence: 提升CSelectTool类测试覆盖率,验证选择工具的
状态判断、选中操作、拖拽移动及事件分发等功能的正确性。
@wyu71
wyu71 force-pushed the agent/agent/9fd249ecbf1d branch from 5ab1114 to 26822c9 Compare September 17, 2026 01:10
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

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

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 总体评分 96 分,大于 70 分通过阈值。本次提交为 CSelectTool 类新增单元测试,代码结构清晰,测试覆盖全面,无安全漏洞,符合项目现有测试规范。

🔍 详细分析

1. 语法逻辑 ✅

评价: 良好 ✅ 通过

潜在问题:

  1. tests/testItems/test_cselecttool.cpp:81 - ASSERT_NE(scene, nullptr) 失败时 tool 对象内存泄漏(GTest ASSERT 宏从函数返回,跳过 delete)

建议: 建议在测试用例中使用 RAII 模式(如 std::unique_ptr)管理动态创建的对象,或在 ASSERT 语句之前不创建需要手动释放的对象,以确保在任何断言失败路径下都不会发生内存泄漏


2. 代码质量 ✅

评价: 优秀 ✅ 通过

潜在问题:

  1. tests/testItems/test_cselecttool.cpp:10 - 使用 #define protected public / #define private public 访问私有成员,属于 C++ UB(与项目现有测试一致)

建议: 该模式与项目中现有测试文件(如 test_idrawtool.cpp)保持一致,属于项目约定。建议长期考虑使用 friend 类或测试接口替代宏定义方式访问私有成员


3. 代码性能 ✅

评价: 优秀 ✅ 通过

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

建议: 单元测试中每个测试用例独立创建和销毁对象是合理的做法,确保测试隔离性,无需优化


4. 代码安全 🔒

评价: 优秀 ✅ 通过

🔐 发现 0 个安全漏洞

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

建议: 测试代码不涉及用户输入处理、网络访问、文件系统操作等安全敏感场景,无需额外安全加固


💡 改进建议代码示例

// 建议使用 RAII 管理 tool 对象,避免 ASSERT 失败时内存泄漏
TEST(CSelectToolDecideUpdate, NotWorking_ReturnsENothingDo)
{
    auto tool = std::make_unique<CSelectTool>();
    tool->setDrawBoard(getMainWindow()->drawBoard());
    
    PageScene *scene = getTestScene();
    ASSERT_NE(scene, nullptr);

    CDrawToolEvent event(QPointF(100, 100), QPointF(100, 100), QPointF(100, 100), scene);
    int result = tool->decideUpdate(&event, nullptr);
    EXPECT_EQ(result, CSelectTool::ENothingDo);
    // tool 自动释放,无需手动 delete
}

本报告由 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 5e7b426 into linuxdeepin:master Sep 17, 2026
14 checks passed
@wyu71
wyu71 deleted the agent/agent/9fd249ecbf1d branch September 17, 2026 02:53
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