Skip to content

test: add PageScene unit tests - #227

Merged
wyu71 merged 1 commit into
masterfrom
agent/agent/fee1836613c8
Sep 10, 2026
Merged

wyu71 merged 1 commit into
masterfrom
agent/agent/fee1836613c8

Conversation

@wyu71

@wyu71 wyu71 commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Add 16 Google Test cases for PageScene class in cdrawscene.cpp, covering firstItem, getGroupTree, getGroupTreeInfo, and isCurrentZMovable methods with various scene states.

为cdrawscene.cpp中PageScene类的firstItem、getGroupTree、 getGroupTreeInfo和isCurrentZMovable方法补充16个Google Test 单元测试用例,覆盖空场景、分组、图层操作等多种场景。

Log: 补充PageScene类单元测试
Influence: 提升PageScene类4个方法的测试覆盖率,验证图元
查找、分组树获取及图层移动等功能的正确性。

Summary by Sourcery

Tests:

  • Add unit coverage for PageScene item lookup, group-tree generation, group-tree information, and z-order movability across empty, grouped, and multi-item scene states.

@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 8 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Sep 10, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds 16 Google Test cases in tests/test_pagescene.cpp that exercise PageScene::firstItem, getGroupTree, getGroupTreeInfo, and isCurrentZMovable across empty, item-containing, grouped, and layered scene states using application-level view and drawing helpers.

File-Level Changes

Change Details Files
Add Google Test coverage for PageScene item lookup behavior.
  • Exercise empty scenes and scenes containing drawable items.
  • Cover penetrability and Bezier-item filtering branches.
  • Verify a non-null item is returned for hit-tested shapes.
tests/test_pagescene.cpp
Add tests for group-tree construction and serialization-oriented group information.
  • Validate empty, ungrouped, and grouped scene trees.
  • Exercise root and valid-group inputs.
  • Cover EDuplicate and ESaveToDDf modes and release returned tree data.
tests/test_pagescene.cpp
Add tests for current-layer movement eligibility.
  • Verify no-selection and single-item scenes cannot move layers.
  • Verify a middle-Z item can move both up and down.
tests/test_pagescene.cpp
Build integration-style PageScene fixtures through the application UI and expose internals for direct assertions.
  • Create views and shapes using existing test helpers and simulated grouping shortcuts.
  • Access protected/private scene members by temporarily redefining access specifiers.
  • Assert scene, group, item, and tree state with Google Test.
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

@github-actions

github-actions Bot commented Sep 10, 2026

Copy link
Copy Markdown

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@wyu71

wyu71 commented Sep 10, 2026

Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA.

deepin-bot Bot added a commit to linuxdeepin/cla that referenced this pull request Sep 10, 2026
@wyu71
wyu71 force-pushed the agent/agent/fee1836613c8 branch from 7bb5eb8 to 6c8cf45 Compare September 10, 2026 01:31
Add 16 Google Test cases for PageScene class in cdrawscene.cpp,
covering firstItem, getGroupTree, getGroupTreeInfo, and
isCurrentZMovable methods with various scene states.

为cdrawscene.cpp中PageScene类的firstItem、getGroupTree、
getGroupTreeInfo和isCurrentZMovable方法补充16个Google Test
单元测试用例,覆盖空场景、分组、图层操作等多种场景。

Log: 补充PageScene类单元测试
Influence: 提升PageScene类4个方法的测试覆盖率,验证图元
查找、分组树获取及图层移动等功能的正确性。
@wyu71
wyu71 force-pushed the agent/agent/fee1836613c8 branch from 6c8cf45 to 1cfbf02 Compare September 10, 2026 01:57
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

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

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 总体评分 97 分,大于 70 分通过阈值,代码质量符合要求。本次提交为 PageScene 类新增 16 个单元测试,覆盖 firstItem、getGroupTree、getGroupTreeInfo 和 isCurrentZMovable 方法,测试逻辑清晰,无安全漏洞,仅存在测试代码重复的轻微质量问题。

🔍 详细分析

1. 语法逻辑 ✅

评价: 优秀 ✅ 通过

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

建议: 语法正确,逻辑清晰。测试用例覆盖了空场景、单项场景、多项场景、分组场景等多种边界条件,ASSERT_NE/EXPECT_EQ/EXPECT_NE/EXPECT_TRUE/EXPECT_FALSE 等断言使用恰当。指针使用前均做了空指针检查(ASSERT_NE),资源管理规范(releaseBzItemsTreeInfo 释放树信息)。


2. 代码质量 ✅

评价: 良好 ✅ 通过

潜在问题:

  1. tests/test_pagescene.cpp:1 - 16个测试用例中重复的初始化代码(createNewViewByShortcutKey、获取view/scene、ASSERT_NE检查),应使用TEST_F测试夹具提取
  2. tests/test_pagescene.cpp:170 - 多个测试中创建矩形图元并分组的代码重复(创建2个矩形+Ctrl+G分组),可提取为辅助函数

建议: 建议使用 Google Test 的 TEST_F 夹具机制提取公共初始化代码(createNewViewByShortcutKey、获取view/scene),减少重复;将重复的创建图元和分组操作提取为辅助函数(如 createRectAndGroup)。


3. 代码性能 ✅

评价: 优秀 ✅ 通过

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

建议: 性能良好,资源使用合理。每个测试仅创建必要的对象,无不必要的计算或循环。


4. 代码安全 🔒

评价: 优秀 ✅ 通过

🔐 发现 0 个安全漏洞

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

建议: 存在0个安全漏洞,安全合规。测试代码无用户输入处理、无注入风险、无硬编码凭证。#define protected/public 为 C++ 测试常用模式,非安全漏洞。


💡 改进建议代码示例

// 推荐使用 TEST_F 测试夹具减少重复代码
class PageSceneTest : 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);
    }

    // 辅助函数:创建矩形图元并分组
    void createRectsAndGroup(int count) {
        for (int i = 0; i < count; ++i) {
            drawApp->setCurrentTool(rectangle);
            createItemByMouse(view, false,
                QPoint(100 + i * 200, 100 + i * 200),
                QPoint(200 + i * 200, 200 + i * 200), false);
        }
        view->slotOnSelectAll();
        DTestEventList e;
        e.addKeyPress(Qt::Key_G, Qt::ControlModifier, 100);
        e.addKeyRelease(Qt::Key_G, Qt::ControlModifier, 100);
        e.simulate(view->viewport());
    }
};

TEST_F(PageSceneTest, EmptyScene_ReturnsNullptr) {
    QGraphicsItem *result = scene->firstItem(QPointF(100, 100),
        QList<QGraphicsItem *>(), false, false, false, false, false, 0);
    EXPECT_EQ(result, nullptr);
}

本报告由 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 9d8ce76 into master Sep 10, 2026
33 of 36 checks passed
@wyu71
wyu71 deleted the agent/agent/fee1836613c8 branch September 10, 2026 02:06
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