test: add unit tests for PageScene move/sort Z methods - #229
Conversation
Reviewer's GuideAdds 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
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
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>| scene->moveBzItemsLayer(items, EDownLayer, 1, nullptr, true); | ||
|
|
||
| EXPECT_NE(middleItem->zValue(), originalZ); |
There was a problem hiding this comment.
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个图层操作方法的测试覆盖率,验证 图元图层移动、分组排序及撤销重做等功能的正确性。
8589461 to
11da2c1
Compare
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 优秀 ✅ 通过 潜在问题: 建议: 语法正确,逻辑清晰,无需修改 2. 代码质量 ✅评价: 良好 ✅ 通过 潜在问题:
建议: 建议使用 Google Test 的 TEST_F 测试夹具(TestFixture)提取公共 setup 代码,将 createNewViewByShortcutKey、createItemByMouse 等初始化逻辑放入 SetUp() 方法中,减少代码重复并提高可维护性 3. 代码性能 ✅评价: 优秀 ✅ 通过 潜在问题: 建议: 性能良好,资源使用合理,无需修改 4. 代码安全 🔒评价: 优秀 ✅ 通过
安全漏洞详情: 建议: 纯测试代码,无安全风险,无需修改 💡 改进建议代码示例// 建议使用测试夹具重构重复的 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 代码审查工具自动生成 |
|
[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. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
概述
为
PageScene类的 4 个方法补充 Google Test 单元测试。源文件:
src/drawshape/cdrawscene.cpp类:
PageScene测试方法
moveBzItemsLayermoveItemsZDownmoveItemsZUpsortZBaseOneBzItem编译与运行
-DDEEPINDRAW_TEST=ON约束
tests/test_pagescene.cpp,不涉及生产源码tests/目录和 Google Test 测试方式Summary by Sourcery
Tests: