test: add unit tests for toolCreatItemUpdate in 5 draw tool classes - #233
Conversation
Reviewer's GuideThe PR adds 45 Google Test cases covering toolCreatItemUpdate across five drawing tools, using real Qt scenes/items and modifier-specific geometry assertions, and exposes each suite through an independently toggleable CMake option. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
d41c361 to
7bf889a
Compare
Add 45 Google Test cases for 5 drawing tool classes, covering toolCreatItemUpdate method with various tool states and modifier keys. 为crecttool.cpp、cellipsetool.cpp、ctriangletool.cpp、cpolygontool.cpp和 cpolygonalstartool.cpp中5个绘制工具类的toolCreatItemUpdate方法补充45个 Google Test单元测试用例,覆盖空指针安全、错误类型安全、无修饰键自由绘制、 Shift正方形模式4个子分支、Alt居中模式及Shift+Alt居中正方形等场景。 Log: 补充5个绘制工具类toolCreatItemUpdate方法单元测试 Influence: 提升CRectTool、CEllipseTool、CTriangleTool、CPolygonTool、 CPolygonalStarTool类测试覆盖率,验证绘制工具在空指针、错误类型、 自由绘制、Shift正方形、Alt居中及Shift+Alt居中正方形等场景的正确性。
7bf889a to
4f483f9
Compare
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 优秀 ✅ 通过 潜在问题: 建议: 语法正确,逻辑清晰。建议统一 makeRecordInfo 函数参数类型为 CGraphicsItem* 以保持一致性;移除未使用的头文件引用。 2. 代码质量 ✅评价: 优秀 ✅ 通过 潜在问题:
建议: 建议将重复的 getTestScene() 和 makeRecordInfo() 辅助函数提取到共享头文件(如 test_drawtool_helpers.h)中以减少代码重复;为其他4个测试文件补充与 test_crecttool.cpp 同等详细的注释。 3. 代码性能 ✅评价: 优秀 ✅ 通过 潜在问题: 建议: 测试代码性能良好,资源使用合理。每个测试用例中创建的对象均有对应的 delete 清理,无资源泄漏风险。 4. 代码安全 🔒评价: 优秀 ✅ 通过
安全漏洞详情: 建议: 存在0个安全漏洞。测试代码不涉及用户输入处理、网络操作或文件系统操作。#define protected public 和 #define private public 是单元测试中常用的访问私有成员技术,仅影响测试编译单元,不构成安全风险。 💡 改进建议代码示例// 建议提取共享辅助函数到 tests/testItems/test_drawtool_helpers.h
#pragma once
#include "idrawtool.h"
#include "drawshape/cdrawscene.h"
#include "cgraphicsview.h"
#include "publicApi.h"
// 共享的 getTestScene 辅助函数
static PageScene *getTestScene()
{
createNewViewByShortcutKey();
PageView *view = getCurView();
if (!view)
return nullptr;
return view->drawScene();
}
// 共享的 makeRecordInfo 辅助函数(统一参数类型)
static IDrawTool::ITERecordInfo makeRecordInfo(PageScene *scene,
CGraphicsItem *item,
const QPointF &startPos = QPointF(100, 100))
{
IDrawTool::ITERecordInfo info;
info.eventLife = IDrawTool::ENormal;
info._startPos = startPos;
info._prePos = startPos;
info._scene = scene;
info._isvaild = true;
info.businessItem = item;
return info;
}本报告由 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 |
Summary
为 5 个绘制工具类的
toolCreatItemUpdate方法补充 Google Test 单元测试。覆盖类
CRectTooltest_crecttool.cppCEllipseTooltest_cellipsetool.cppCTriangleTooltest_ctriangletool.cppCPolygonTooltest_cpolygontool.cppCPolygonalStarTooltest_cpolygonalstartool.cpp测试场景
每个类覆盖以下场景(共 45 个用例):
测试结果
Log: 补充toolCreatItemUpdate单元测试
Influence: 无
Summary by Sourcery
Expand unit-test coverage for item updates across five drawing tools and make each test suite independently configurable in the test build.
Build:
Tests: