Skip to content

test: add PageScene unit tests for creatGroup, cancelGroup, releaseBzItemsTreeInfo, event, mouseEvent - #230

Merged
wyu71 merged 1 commit into
linuxdeepin:masterfrom
wyu71:main
Sep 15, 2026
Merged

wyu71 merged 1 commit into
linuxdeepin:masterfrom
wyu71:main

Conversation

@wyu71

@wyu71 wyu71 commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Summary

Add 24 Google Test unit test cases for 5 methods in PageScene class (src/drawshape/cdrawscene.cpp):

Test Coverage

creatGroup (4 tests)

  • Empty items and empty selection returns nullptr
  • Single item normal group returns nullptr
  • Items already in group returns nullptr
  • Valid two-item normal group creation returns group

cancelGroup (4 tests)

  • Nullptr with no groups does not crash
  • Nullptr with selected group destroys group
  • Non-null cancelable group destroys group
  • Non-null non-cancelable group no change

releaseBzItemsTreeInfo (CGroupBzItemsTree) (4 tests)

  • Empty tree does not crash
  • With childGroups recurse and release
  • With bzItems not in scene deletes bzItems
  • With pGroup not in scene deletes later

releaseBzItemsTreeInfo (CGroupBzItemsTreeInfo) (2 tests)

  • Empty treeInfo does not crash
  • With childGroups recurse and release

event (5 tests)

  • Non-touch/non-gesture event returns base result
  • TouchBegin with tool returns true
  • TouchEnd with tool returns true
  • Gesture event with selection tool no crash
  • Gesture event with non-selection tool falls back to base

mouseEvent (5 tests)

  • Mouse press delegates to base
  • Mouse move delegates to base
  • Mouse release delegates to base
  • Mouse double click delegates to base
  • Unknown event type default break

Build & Test Results

  • Build: cmake -DDEEPINDRAW_TEST=ON — success (Qt 6.8.0)
  • All 24 tests pass (0 failures)

Notes

  • Only test file tests/test_pagescene.cpp modified; no production source code changes
  • Follows existing test patterns (#define protected public / #define private public before includes)

Summary by Sourcery

Tests:

  • Add comprehensive Google Test coverage for PageScene grouping, group cancellation, tree-info cleanup, event handling, and mouse event dispatch behavior.

@sourcery-ai

sourcery-ai Bot commented Sep 14, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds 24 Google Test cases in tests/test_pagescene.cpp covering PageScene group lifecycle, tree cleanup, event dispatch, and mouse handling. The PR changes no production code and reports a successful Qt 6.8 build with all tests passing.

File-Level Changes

Change Details Files
Adds unit coverage for group creation and cancellation behavior, including valid, invalid, selected, and non-cancelable group states.
  • Exercises empty, single-item, already-grouped, and valid multi-item creation paths.
  • Verifies null, selected, cancelable, and non-cancelable cancellation paths.
tests/test_pagescene.cpp
Adds cleanup tests for both group-item tree metadata overloads, including recursion and deletion of objects detached from a scene.
  • Covers empty trees and nested child-group traversal.
  • Covers cleanup of detached Bézier items and groups.
tests/test_pagescene.cpp
Adds event-dispatch coverage for touch, gesture, mouse, and unknown event types.
  • Checks base fallback behavior and tool-dependent touch/gesture handling.
  • Exercises all supported mouse event types plus the default branch.
tests/test_pagescene.cpp
Extends test dependencies to construct Qt touch and graphics-scene mouse events.
  • Includes the required Qt event headers while retaining access to protected/private PageScene APIs through existing test conventions.
tests/test_pagescene.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 reviewed your changes and they look great!


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

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

AI 代码审查报告

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

审查结果: 通过


总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交为测试代码新增,为PageScene类的5个方法添加了24个单元测试用例。代码结构清晰,逻辑正确,无安全漏洞。存在少量代码重复和部分测试断言不充分的问题,但整体质量良好。
项目名称 linuxdeepin/deepin-draw
PR地址 #230
提交者 wyu71
分析模式 全量分析

漏洞对比统计

统计项 数量
当前漏洞总数 0
新增漏洞 0
减少漏洞 0
持平漏洞 0

详细分析

1. 语法逻辑(25/25分)✓

语法正确,逻辑清晰

  • 评分:25/25
  • 状态:通过 ✓

问题列表:

分析说明:

  • 24个Google Test单元测试用例语法正确,TEST()宏使用规范
  • ASSERT_NE、EXPECT_EQ、EXPECT_NE、EXPECT_TRUE、EXPECT_FALSE等断言宏使用正确
  • 测试逻辑清晰:每个测试遵循"设置场景 → 执行操作 → 验证结果"模式
  • 边界条件处理完善:空列表、空指针、单个图元、已分组的图元等边界场景均有覆盖
  • 内存管理正确:new创建的对象由场景管理或由releaseBzItemsTreeInfo释放
  • PR描述确认构建成功,所有24个测试通过

2. 代码质量(20/25分)✓

代码结构清晰,注释完整

  • 评分:20/25
  • 状态:通过 ✓

问题列表:

  1. tests/test_pagescene.cpp:792-1201 - 代码重复:16+个测试用例重复使用相同的5行设置模式(createNewViewByShortcutKey + getCurView + drawScene + ASSERT_NE),建议提取到测试固件的SetUp()方法或辅助函数中 [中等]

  2. tests/test_pagescene.cpp:1015-1021 - 测试断言不充分:PageSceneReleaseBzItemsTreeInfo_WithBzItemsNotInScene_DeletesBzItems测试名称声称验证删除操作,但未实际验证item是否被删除。info.bzItems.clear()掩盖了releaseBzItemsTreeInfo未清空列表的问题 [中等] [OCR发现]

  3. tests/test_pagescene.cpp:1027-1034 - 测试断言不充分:PageSceneReleaseBzItemsTreeInfo_WithPGroupNotInScene_DeletesLater测试名称声称验证延迟删除,但未实际验证group是否被删除。info.pGroup=nullptr掩盖了releaseBzItemsTreeInfo未置空的问题 [中等] [OCR发现]

  4. tests/test_pagescene.cpp:837-841 - 冗余调用:drawApp->setCurrentTool(rectangle)在多次测试中被重复调用,工具已在第一次调用后设置,第二次调用是冗余的 [低] [OCR发现]

  5. tests/test_pagescene.cpp:1146-1148 - 测试断言不足:5个mouseEvent测试仅断言SUCCEED()而未验证任何可观察行为或返回值,回归价值较低 [低] [OCR发现]

改进建议:

  1. 建议将重复的测试设置代码提取到测试固件的SetUp()方法中
  2. 建议在DeletesBzItems测试中用EXPECT_TRUE(info.bzItems.isEmpty())替换info.bzItems.clear()
  3. 建议在DeletesLater测试中用EXPECT_EQ(info.pGroup, nullptr)替换info.pGroup = nullptr
  4. 建议在mouseEvent测试中增加对可观察副作用的验证,如场景选择状态、图元数量等

3. 代码性能(20/20分)✓

性能良好,资源使用合理

  • 评分:20/20
  • 状态:通过 ✓

问题列表:

分析说明:

  • 测试代码无性能瓶颈
  • 无不必要的计算操作
  • QCoreApplication::processEvents()用于处理延迟删除,使用得当
  • 无资源泄漏

4. 代码安全(30/30分)✓

存在0个安全漏洞

  • 评分:30/30
  • 状态:通过 ✓
  • 安全漏洞总数:0

安全漏洞详情:
无安全漏洞

分析说明:

  • 测试代码无用户输入处理,无网络操作,无安全敏感操作
  • 无硬编码密钥、无SQL注入、无命令执行风险
  • 内存管理正确:new创建的对象由场景管理或由releaseBzItemsTreeInfo释放
  • 无缓冲区溢出、无格式化字符串漏洞
  • 无路径遍历、无注入风险

改进建议代码示例

建议1:提取公共设置代码到测试固件

// 建议在测试固件中提取公共设置代码
class PageSceneTestBase : public ::testing::Test {
protected:
    PageView *view = nullptr;
    PageScene *scene = nullptr;

    void SetUp() override {
        createNewViewByShortcutKey();
        view = getCurView();
        ASSERT_NE(view, nullptr);
        scene = view->drawScene();
        ASSERT_NE(scene, nullptr);
    }
};

// 然后测试用例可以简化为:
TEST_F(PageSceneTestBase, SomeTest) {
    // 直接使用 view 和 scene,无需重复设置
}

建议2:增强删除验证测试

TEST(PageSceneReleaseBzItemsTreeInfo, WithBzItemsNotInScene_DeletesBzItems)
{
    PageScene::CGroupBzItemsTree info;
    CGraphicsRectItem *item = new CGraphicsRectItem();
    ASSERT_NE(item, nullptr);
    EXPECT_EQ(item->scene(), nullptr);
    info.bzItems.append(item);
    PageScene::releaseBzItemsTreeInfo(info);
    // 验证函数已接管所有权并清空列表
    EXPECT_TRUE(info.bzItems.isEmpty());
    SUCCEED();
}

TEST(PageSceneReleaseBzItemsTreeInfo, WithPGroupNotInScene_DeletesLater)
{
    PageScene::CGroupBzItemsTree info;
    CGraphicsItemGroup *group = new CGraphicsItemGroup();
    ASSERT_NE(group, nullptr);
    EXPECT_EQ(group->scene(), nullptr);
    info.pGroup = group;
    PageScene::releaseBzItemsTreeInfo(info);
    QCoreApplication::processEvents();
    // 验证函数已接管所有权并置空
    EXPECT_EQ(info.pGroup, nullptr);
    SUCCEED();
}

审查结论

本次提交为 deepin-draw 项目的测试代码新增,为 PageScene 类的 creatGroupcancelGroupreleaseBzItemsTreeInfoeventmouseEvent 5个方法添加了24个Google Test单元测试用例。代码与commit目的一致,仅修改测试文件,无生产代码变更。

代码语法正确,逻辑清晰,无安全漏洞。主要改进点在于减少代码重复和增强部分测试的断言验证。整体代码质量良好,建议合并。


本报告由 AI 代码审查工具自动生成
审查时间:2026-09-14 18:30:00

…ItemsTreeInfo, event, mouseEvent

Add 24 Google Test cases for PageScene class in cdrawscene.cpp,
covering creatGroup, cancelGroup, releaseBzItemsTreeInfo, event,
and mouseEvent methods with various scene states.

为cdrawscene.cpp中PageScene类的creatGroup、cancelGroup、
releaseBzItemsTreeInfo、event和mouseEvent方法补充24个Google Test
单元测试用例,覆盖空列表组合、组合取消、树信息释放、
触摸/手势事件及鼠标事件分发等场景。

Log: 补充PageScene类组合及事件方法单元测试
Influence: 提升PageScene类5个方法的测试覆盖率,验证
图元组合/取消组合、分组树信息释放及事件分发等功能的正确性。
@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 a470989 into linuxdeepin:master Sep 15, 2026
13 checks passed
@wyu71
wyu71 deleted the main branch September 15, 2026 02:26
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