Skip to content

test: add unit tests for toolCreatItemUpdate in 5 draw tool classes - #233

Merged
wyu71 merged 1 commit into
linuxdeepin:masterfrom
wyu71:agent/agent/02a6e962c7ee
Sep 18, 2026
Merged

wyu71 merged 1 commit into
linuxdeepin:masterfrom
wyu71:agent/agent/02a6e962c7ee

Conversation

@wyu71

@wyu71 wyu71 commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Summary

为 5 个绘制工具类的 toolCreatItemUpdate 方法补充 Google Test 单元测试。

覆盖类

测试文件 用例数
CRectTool test_crecttool.cpp 9
CEllipseTool test_cellipsetool.cpp 9
CTriangleTool test_ctriangletool.cpp 9
CPolygonTool test_cpolygontool.cpp 9
CPolygonalStarTool test_cpolygonalstartool.cpp 9

测试场景

每个类覆盖以下场景(共 45 个用例):

  • 空指针安全(NullPInfo_NoCrash)
  • 错误类型安全(WrongBusinessItemType_NoCrash)
  • 无修饰键自由绘制(NoModifiers_FreeFormRect)
  • Shift 正方形模式 4 个子分支:
    • AbsLengthGeHPositive(|w|>=|h|, h>=0)
    • AbsLengthGeHNegative(|w|>=|h|, h<0)
    • AbsLengthLtWPositive(|w|<|h|, w>=0)
    • AbsLengthLtWNegative(|w|<|h|, w<0)
  • Alt 居中模式(AltOnly_CenteredRect)
  • Shift+Alt 居中正方形(ShiftAlt_CenteredSquare)

测试结果

[==========] Running 45 tests from 5 test suites.
[  PASSED  ] 45 tests.

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:

  • Add configurable CMake options and compile definitions for enabling unit tests for five drawing tool item-update implementations.

Tests:

  • Add Google Test coverage for rectangle, ellipse, triangle, polygon, and polygonal-star tool item updates, including invalid-input safety, free-form sizing, Shift-constrained squares, Alt-centered shapes, and Shift+Alt centered squares.

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

@sourcery-ai

sourcery-ai Bot commented Sep 18, 2026

Copy link
Copy Markdown

Reviewer's Guide

The 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

Change Details Files
Added Google Test coverage for rectangle, ellipse, triangle, polygon, and polygonal-star tool item-update behavior.
  • Added nine tests per tool for null and wrong-type safety, free-form sizing, four Shift square branches, Alt-centered sizing, and Shift+Alt centered-square sizing.
  • Constructed real draw scenes, tool instances, events, and graphics items; asserted resulting geometry with tolerances and cleaned up test objects.
tests/testItems/test_crecttool.cpp
tests/testItems/test_cellipsetool.cpp
tests/testItems/test_ctriangletool.cpp
tests/testItems/test_cpolygontool.cpp
tests/testItems/test_cpolygonalstartool.cpp
Made each new tool test suite independently configurable in the test build.
  • Added five CMake options enabled by default.
  • Defined per-suite preprocessor flags to conditionally compile the corresponding tests.
tests/CMakeLists.txt

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

@wyu71
wyu71 force-pushed the agent/agent/02a6e962c7ee branch 2 times, most recently from d41c361 to 7bf889a Compare September 18, 2026 01:01
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居中正方形等场景的正确性。
@wyu71
wyu71 force-pushed the agent/agent/02a6e962c7ee branch from 7bf889a to 4f483f9 Compare September 18, 2026 01:10
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

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

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 总体评分 98 分,大于 70 分通过阈值。本次提交为 5 个绘制工具类补充单元测试,代码结构清晰、测试覆盖全面,未发现安全漏洞。

🔍 详细分析

1. 语法逻辑 ✅

评价: 优秀 ✅ 通过

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

建议: 语法正确,逻辑清晰。建议统一 makeRecordInfo 函数参数类型为 CGraphicsItem* 以保持一致性;移除未使用的头文件引用。


2. 代码质量 ✅

评价: 优秀 ✅ 通过

潜在问题:

  1. tests/testItems/test_cellipsetool.cpp:75 - getTestScene() 和 makeRecordInfo() 辅助函数在5个测试文件中完全重复,建议提取到共享头文件
  2. tests/testItems/test_crecttool.cpp:1135 - makeRecordInfo 参数类型为 CGraphicsRectItem* 而非 CGraphicsItem*,与其他文件不一致
  3. tests/testItems/test_cellipsetool.cpp:70 - 包含 和 头文件但未使用

建议: 建议将重复的 getTestScene() 和 makeRecordInfo() 辅助函数提取到共享头文件(如 test_drawtool_helpers.h)中以减少代码重复;为其他4个测试文件补充与 test_crecttool.cpp 同等详细的注释。


3. 代码性能 ✅

评价: 优秀 ✅ 通过

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

建议: 测试代码性能良好,资源使用合理。每个测试用例中创建的对象均有对应的 delete 清理,无资源泄漏风险。


4. 代码安全 🔒

评价: 优秀 ✅ 通过

🔐 发现 0 个安全漏洞

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

建议: 存在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 代码审查工具自动生成

@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 b07d043 into linuxdeepin:master Sep 18, 2026
14 checks passed
@wyu71
wyu71 deleted the agent/agent/02a6e962c7ee branch September 18, 2026 01:48
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