test: add PageScene unit tests - #227
Conversation
Reviewer's GuideAdds 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
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅ |
|
I have read the CLA Document and I hereby sign the CLA. |
7bb5eb8 to
6c8cf45
Compare
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个方法的测试覆盖率,验证图元 查找、分组树获取及图层移动等功能的正确性。
6c8cf45 to
1cfbf02
Compare
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 优秀 ✅ 通过 潜在问题: 建议: 语法正确,逻辑清晰。测试用例覆盖了空场景、单项场景、多项场景、分组场景等多种边界条件,ASSERT_NE/EXPECT_EQ/EXPECT_NE/EXPECT_TRUE/EXPECT_FALSE 等断言使用恰当。指针使用前均做了空指针检查(ASSERT_NE),资源管理规范(releaseBzItemsTreeInfo 释放树信息)。 2. 代码质量 ✅评价: 良好 ✅ 通过 潜在问题:
建议: 建议使用 Google Test 的 TEST_F 夹具机制提取公共初始化代码(createNewViewByShortcutKey、获取view/scene),减少重复;将重复的创建图元和分组操作提取为辅助函数(如 createRectAndGroup)。 3. 代码性能 ✅评价: 优秀 ✅ 通过 潜在问题: 建议: 性能良好,资源使用合理。每个测试仅创建必要的对象,无不必要的计算或循环。 4. 代码安全 🔒评价: 优秀 ✅ 通过
安全漏洞详情: 建议: 存在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 代码审查工具自动生成 |
|
[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 |
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: