Skip to content

test: add unit tests for PageScene move/sort Z methods - #229

Merged
wyu71 merged 1 commit into
linuxdeepin:masterfrom
wyu71:agent/agent/faff3ebfdd7e
Sep 14, 2026
Merged

wyu71 merged 1 commit into
linuxdeepin:masterfrom
wyu71:agent/agent/faff3ebfdd7e

Conversation

@wyu71

@wyu71 wyu71 commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

概述

为 PageScene 类的 4 个方法补充 Google Test 单元测试。

源文件:src/drawshape/cdrawscene.cpp
类:PageScene

测试方法

方法 测试用例数 覆盖分支
moveBzItemsLayer 5 空列表早返回、EDownLayer、EUpLayer、EToGroup、pushToStack 记录 undo/redo
moveItemsZDown 2 单步下移、step=-1 移至底层
moveItemsZUp 2 单步上移、step=-1 移至顶层
sortZBaseOneBzItem 2 基于 baseItem 重排 Z 值、全部在组内保持 Z 序

编译与运行

  • 构建环境:Qt6 / DTK6,CMake -DDEEPINDRAW_TEST=ON
  • 编译通过,11 个测试用例全部通过(exit code 0)
[==========] 11 tests from 4 test suites ran. (18821 ms total)
[  PASSED  ] 11 tests.

约束

  • 仅修改 tests/test_pagescene.cpp,不涉及生产源码
  • 沿用项目现有 tests/ 目录和 Google Test 测试方式

Summary by Sourcery

Tests:

  • Add Google Test coverage for PageScene Z-order movement, grouping, sorting, boundary, and undo/redo behavior.

@sourcery-ai

sourcery-ai Bot commented Sep 11, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds 11 Google Test cases in tests/test_pagescene.cpp covering PageScene layer dispatch, single-step and boundary Z movement, base-item Z sorting, empty-input handling, and the pushToStack path; production code is unchanged.

File-Level Changes

Change Details Files
Add focused Google Test coverage for layer movement dispatch and early-return behavior.
  • Exercise empty-input handling and EDownLayer, EUpLayer, and EToGroup dispatch paths.
  • Verify single-step Z movement changes and undo-stack-enabled invocation behavior.
tests/test_pagescene.cpp
Cover boundary semantics for moving items to the bottom or top Z layer.
  • Test step=1 downward and upward movement.
  • Test step=-1 movement to the bottom and top relative to neighboring items.
tests/test_pagescene.cpp
Validate Z-order regrouping around a base item.
  • Verify selected items are reordered around the base item while intervening items move below them.
  • Verify sorting an already ordered group preserves each item's Z value.
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 found 1 issue

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

## Individual Comments

### Comment 1
<location path="tests/test_pagescene.cpp" line_range="575-577" />
<code_context>
+    QList<CGraphicsItem *> items;
+    items.append(middleItem);
+
+    scene->moveBzItemsLayer(items, EDownLayer, 1, nullptr, true);
+
+    EXPECT_NE(middleItem->zValue(), originalZ);
+}
+
</code_context>
<issue_to_address>
**issue (testing):** The test named `PushToStack_RecordsUndoRedo` only checks that the item's Z value changed; it never performs undo/redo or inspects the undo/redo command state, so a regression that removes `recordItemsInfoToCmd`, records the wrong snapshot, or omits `finishRecord` still passes.

**Triggers:** When the production method changes its undo/redo recording behavior while continuing to move the item.

**Suggested fix:** Execute undo and redo after the move and assert that the item's Z value returns to the original value and then returns to the moved value.
</issue_to_address>

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

Comment thread tests/test_pagescene.cpp
Comment on lines +575 to +577
scene->moveBzItemsLayer(items, EDownLayer, 1, nullptr, true);

EXPECT_NE(middleItem->zValue(), originalZ);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue (testing): The test named PushToStack_RecordsUndoRedo only checks that the item's Z value changed; it never performs undo/redo or inspects the undo/redo command state, so a regression that removes recordItemsInfoToCmd, records the wrong snapshot, or omits finishRecord still passes.

Triggers: When the production method changes its undo/redo recording behavior while continuing to move the item.

Suggested fix: Execute undo and redo after the move and assert that the item's Z value returns to the original value and then returns to the moved value.

…moveItemsZUp, sortZBaseOneBzItem

Add 11 Google Test cases for PageScene class in cdrawscene.cpp,
covering moveBzItemsLayer, moveItemsZDown, moveItemsZUp, and
sortZBaseOneBzItem methods with various layer operations.

为cdrawscene.cpp中PageScene类的moveBzItemsLayer、moveItemsZDown、
moveItemsZUp和sortZBaseOneBzItem方法补充11个Google Test
单元测试用例,覆盖空列表早返回、图层上移/下移/移至分组、
undo/redo记录及基于基准项重排Z值等场景。

Log: 补充PageScene类图层操作方法单元测试
Influence: 提升PageScene类4个图层操作方法的测试覆盖率,验证
图元图层移动、分组排序及撤销重做等功能的正确性。
@wyu71
wyu71 force-pushed the agent/agent/faff3ebfdd7e branch from 8589461 to 11da2c1 Compare September 14, 2026 01:18
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

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

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 总体评分 97 分,大于 70 分通过阈值,代码质量符合要求。本次提交为 PageScene 类的 4 个方法补充了 11 个 Google Test 单元测试,覆盖空列表早返回、各分支分发、Z 值移动、排序及 undo/redo 记录等场景,测试逻辑清晰,编译通过且全部测试 PASSED。

🔍 详细分析

1. 语法逻辑 ✅

评价: 优秀 ✅ 通过

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

建议: 语法正确,逻辑清晰,无需修改


2. 代码质量 ✅

评价: 良好 ✅ 通过

潜在问题:

  1. tests/test_pagescene.cpp:441 - 9/11 个测试用例包含相同的 setup 代码(创建视图+创建3个矩形图元),应使用 TEST_F 测试夹具提取公共 SetUp 逻辑以减少代码重复

建议: 建议使用 Google Test 的 TEST_F 测试夹具(TestFixture)提取公共 setup 代码,将 createNewViewByShortcutKey、createItemByMouse 等初始化逻辑放入 SetUp() 方法中,减少代码重复并提高可维护性


3. 代码性能 ✅

评价: 优秀 ✅ 通过

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

建议: 性能良好,资源使用合理,无需修改


4. 代码安全 🔒

评价: 优秀 ✅ 通过

🔐 发现 0 个安全漏洞

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

建议: 纯测试代码,无安全风险,无需修改


💡 改进建议代码示例

// 建议使用测试夹具重构重复的 setup 代码
class PageSceneZOrderTest : 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);

        // 创建 3 个矩形图元
        drawApp->setCurrentTool(rectangle);
        createItemByMouse(view, false, QPoint(100, 100), QPoint(200, 200), false);
        drawApp->setCurrentTool(rectangle);
        createItemByMouse(view, false, QPoint(300, 300), QPoint(400, 400), false);
        drawApp->setCurrentTool(rectangle);
        createItemByMouse(view, false, QPoint(500, 500), QPoint(600, 600), false);

        ASSERT_GE(scene->getBzItems().count(), 3);
    }
};

// 使用测试夹具后,每个测试只需关注核心逻辑
TEST_F(PageSceneZOrderTest, MoveBzItemsLayer_EDownLayer_DispatchesToMoveItemsZDown) {
    auto bzItems = scene->getBzItems();
    CGraphicsItem *topItem = bzItems[0];
    qreal originalZ = topItem->zValue();

    QList<CGraphicsItem *> items;
    items.append(topItem);

    scene->moveBzItemsLayer(items, EDownLayer, 1, nullptr, false);

    EXPECT_LT(topItem->zValue(), originalZ);
}

本报告由 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 78adfea into linuxdeepin:master Sep 14, 2026
14 checks passed
@wyu71
wyu71 deleted the agent/agent/faff3ebfdd7e branch September 14, 2026 02:45
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