test: add unit tests for CSelectTool - #232
Conversation
Reviewer's GuideAdds an opt-in-by-default CMake test switch and 24 Google Test cases across five suites to validate CSelectTool’s selection, movement, transformation, event dispatch, and no-op branches in an offscreen Qt environment. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
…ate, toolFinish, sendToolEventToItem Add 24 Google Test cases for CSelectTool class in cselecttool.cpp, covering decideUpdate, toolStart, toolUpdate, toolFinish, and sendToolEventToItem methods with various tool states and events. 为cselecttool.cpp中CSelectTool类的decideUpdate、toolStart、 toolUpdate、toolFinish和sendToolEventToItem方法补充24个Google Test 单元测试用例,覆盖无工作状态返回、空点击清除选中、图元点击选中、 矩形框选、拖拽/复制移动完成及事件分发等场景。 Log: 补充CSelectTool类5个方法单元测试 Influence: 提升CSelectTool类测试覆盖率,验证选择工具的 状态判断、选中操作、拖拽移动及事件分发等功能的正确性。
5ab1114 to
26822c9
Compare
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 良好 ✅ 通过 潜在问题:
建议: 建议在测试用例中使用 RAII 模式(如 std::unique_ptr)管理动态创建的对象,或在 ASSERT 语句之前不创建需要手动释放的对象,以确保在任何断言失败路径下都不会发生内存泄漏 2. 代码质量 ✅评价: 优秀 ✅ 通过 潜在问题:
建议: 该模式与项目中现有测试文件(如 test_idrawtool.cpp)保持一致,属于项目约定。建议长期考虑使用 friend 类或测试接口替代宏定义方式访问私有成员 3. 代码性能 ✅评价: 优秀 ✅ 通过 潜在问题: 建议: 单元测试中每个测试用例独立创建和销毁对象是合理的做法,确保测试隔离性,无需优化 4. 代码安全 🔒评价: 优秀 ✅ 通过
安全漏洞详情: 建议: 测试代码不涉及用户输入处理、网络访问、文件系统操作等安全敏感场景,无需额外安全加固 💡 改进建议代码示例// 建议使用 RAII 管理 tool 对象,避免 ASSERT 失败时内存泄漏
TEST(CSelectToolDecideUpdate, NotWorking_ReturnsENothingDo)
{
auto tool = std::make_unique<CSelectTool>();
tool->setDrawBoard(getMainWindow()->drawBoard());
PageScene *scene = getTestScene();
ASSERT_NE(scene, nullptr);
CDrawToolEvent event(QPointF(100, 100), QPointF(100, 100), QPointF(100, 100), scene);
int result = tool->decideUpdate(&event, nullptr);
EXPECT_EQ(result, CSelectTool::ENothingDo);
// tool 自动释放,无需手动 delete
}本报告由 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 |
test: add unit tests for CSelectTool
为
CSelectTool类的五个方法添加 Google Test 单元测试,共 24 个测试用例,覆盖 5 个测试套件。测试覆盖
decideUpdatetoolStarttoolUpdatetoolFinishsendToolEventToItem编译与运行结果
所有测试在
QT_QPA_PLATFORM=offscreen模式下通过。Summary by Sourcery
Add comprehensive unit coverage for CSelectTool behavior and integrate it into the test build.
Build:
Tests: